The branch, master has been updated
       via  a777b4d50136dc52b69756fdfd6d7024270fe040 (commit)
       via  408cde8fcaac96b82d1cb4d638d790122900cff0 (commit)
       via  4d22554e98134755cea609aa6d888c8e67fc123b (commit)
      from  42b8d6b3084e235beb8e4ed4215b5973e769ada3 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a777b4d50136dc52b69756fdfd6d7024270fe040
Author: Volker Lendecke <[email protected]>
Date:   Thu Feb 26 12:34:39 2009 +0100

    Convert open_socket_out to tevent_req

commit 408cde8fcaac96b82d1cb4d638d790122900cff0
Author: Volker Lendecke <[email protected]>
Date:   Thu Feb 26 12:34:14 2009 +0100

    Add tevent_req helpers to includes.h

commit 4d22554e98134755cea609aa6d888c8e67fc123b
Author: Volker Lendecke <[email protected]>
Date:   Thu Feb 26 10:48:41 2009 +0100

    Add tevent_ntstatus

-----------------------------------------------------------------------

Summary of changes:
 lib/util/tevent_ntstatus.c |   51 +++++++++++++++++++++++++++
 lib/util/tevent_ntstatus.h |   32 +++++++++++++++++
 source3/Makefile.in        |    2 +-
 source3/include/includes.h |    2 +
 source3/include/proto.h    |   12 +++---
 source3/lib/util_sock.c    |   82 ++++++++++++++++++++++----------------------
 6 files changed, 133 insertions(+), 48 deletions(-)
 create mode 100644 lib/util/tevent_ntstatus.c
 create mode 100644 lib/util/tevent_ntstatus.h


Changeset truncated at 500 lines:

diff --git a/lib/util/tevent_ntstatus.c b/lib/util/tevent_ntstatus.c
new file mode 100644
index 0000000..1a34e9c
--- /dev/null
+++ b/lib/util/tevent_ntstatus.c
@@ -0,0 +1,51 @@
+/*
+   Unix SMB/CIFS implementation.
+   Wrap unix errno around tevent_req
+   Copyright (C) Volker Lendecke 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "tevent_ntstatus.h"
+#include "../replace/replace.h"
+
+bool tevent_req_nterror(struct tevent_req *req,        NTSTATUS status)
+{
+       return tevent_req_error(req, NT_STATUS_V(status));
+}
+
+bool tevent_req_is_nterror(struct tevent_req *req, NTSTATUS *status)
+{
+       enum tevent_req_state state;
+       uint64_t err;
+
+       if (!tevent_req_is_error(req, &state, &err)) {
+               return false;
+       }
+       switch (state) {
+       case TEVENT_REQ_TIMED_OUT:
+               *status = NT_STATUS_IO_TIMEOUT;
+               break;
+       case TEVENT_REQ_NO_MEMORY:
+               *status = NT_STATUS_NO_MEMORY;
+               break;
+       case TEVENT_REQ_USER_ERROR:
+               *status = NT_STATUS(err);
+               break;
+       default:
+               *status = NT_STATUS_INTERNAL_ERROR;
+               break;
+       }
+       return true;
+}
diff --git a/lib/util/tevent_ntstatus.h b/lib/util/tevent_ntstatus.h
new file mode 100644
index 0000000..84c275f
--- /dev/null
+++ b/lib/util/tevent_ntstatus.h
@@ -0,0 +1,32 @@
+/*
+   Unix SMB/CIFS implementation.
+   Wrap unix errno around tevent_req
+   Copyright (C) Volker Lendecke 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _TEVENT_NTSTATUS_H
+#define _TEVENT_NTSTATUS_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "config.h"
+#include "../libcli/util/ntstatus.h"
+#include "../tevent/tevent.h"
+
+bool tevent_req_nterror(struct tevent_req *req, NTSTATUS status);
+bool tevent_req_is_nterror(struct tevent_req *req, NTSTATUS *pstatus);
+
+#endif
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 8f1d1a5..d957d70 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -340,7 +340,7 @@ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o 
../lib/util/time.o \
                   ../lib/util/params.o ../lib/util/talloc_stack.o \
                   ../lib/util/genrand.o ../lib/util/util_net.o \
                   ../lib/util/become_daemon.o ../lib/util/system.o \
-                  ../lib/util/tevent_unix.o
+                  ../lib/util/tevent_unix.o ../lib/util/tevent_ntstatus.o
 
 CRYPTO_OBJ = ../lib/crypto/crc32.o ../lib/crypto/md5.o \
                         ../lib/crypto/hmacmd5.o ../lib/crypto/arcfour.o \
diff --git a/source3/include/includes.h b/source3/include/includes.h
index 80d7bfc..523a11e 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -577,6 +577,8 @@ struct smb_iconv_convenience *lp_iconv_convenience(void 
*lp_ctx);
 #include "../talloc/talloc.h"
 
 #include "event.h"
+#include "../lib/util/tevent_unix.h"
+#include "../lib/util/tevent_ntstatus.h"
 
 #include "../lib/util/data_blob.h"
 #include "../lib/util/time.h"
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 559d62f..3fb57e4 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1423,12 +1423,12 @@ int open_socket_in(int type,
                bool rebind);
 NTSTATUS open_socket_out(const struct sockaddr_storage *pss, uint16_t port,
                         int timeout, int *pfd);
-struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
-                                      struct event_context *ev,
-                                      const struct sockaddr_storage *pss,
-                                      uint16_t port,
-                                      int timeout);
-NTSTATUS open_socket_out_recv(struct async_req *req, int *pfd);
+struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
+                                       struct event_context *ev,
+                                       const struct sockaddr_storage *pss,
+                                       uint16_t port,
+                                       int timeout);
+NTSTATUS open_socket_out_recv(struct tevent_req *req, int *pfd);
 struct async_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx,
                                             struct event_context *ev,
                                             struct timeval wait_time,
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 83e8a9d..b33088d 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -967,20 +967,20 @@ static int open_socket_out_state_destructor(struct 
open_socket_out_state *s)
  Create an outgoing socket. timeout is in milliseconds.
 **************************************************************************/
 
-struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
-                                      struct event_context *ev,
-                                      const struct sockaddr_storage *pss,
-                                      uint16_t port,
-                                      int timeout)
+struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
+                                       struct event_context *ev,
+                                       const struct sockaddr_storage *pss,
+                                       uint16_t port,
+                                       int timeout)
 {
        char addr[INET6_ADDRSTRLEN];
-       struct async_req *result;
-       struct tevent_req *subreq;
+       struct tevent_req *result, *subreq;
        struct open_socket_out_state *state;
        NTSTATUS status;
 
-       if (!async_req_setup(mem_ctx, &result, &state,
-                            struct open_socket_out_state)) {
+       result = tevent_req_create(mem_ctx, &state,
+                                  struct open_socket_out_state);
+       if (result == NULL) {
                return NULL;
        }
        state->ev = ev;
@@ -996,7 +996,8 @@ struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
        }
        talloc_set_destructor(state, open_socket_out_state_destructor);
 
-       if (!async_req_set_timeout(result, ev, timeval_set(0, timeout*1000))) {
+       if (!tevent_req_set_endtime(
+                   result, ev, timeval_current_ofs(0, timeout*1000))) {
                goto fail;
        }
 
@@ -1030,18 +1031,15 @@ struct async_req *open_socket_out_send(TALLOC_CTX 
*mem_ctx,
            || !tevent_req_set_endtime(
                    subreq, state->ev,
                    timeval_current_ofs(0, state->wait_nsec))) {
-               status = NT_STATUS_NO_MEMORY;
-               goto post_status;
+               goto fail;
        }
        subreq->async.fn = open_socket_out_connected;
        subreq->async.private_data = result;
        return result;
 
  post_status:
-       if (!async_post_ntstatus(result, ev, status)) {
-               goto fail;
-       }
-       return result;
+       tevent_req_nterror(result, status);
+       return tevent_req_post(result, ev);
  fail:
        TALLOC_FREE(result);
        return NULL;
@@ -1049,17 +1047,18 @@ struct async_req *open_socket_out_send(TALLOC_CTX 
*mem_ctx,
 
 static void open_socket_out_connected(struct tevent_req *subreq)
 {
-       struct async_req *req = talloc_get_type_abort(
-               subreq->async.private_data, struct async_req);
+       struct tevent_req *req = talloc_get_type_abort(
+               subreq->async.private_data, struct tevent_req);
        struct open_socket_out_state *state = talloc_get_type_abort(
-               req->private_data, struct open_socket_out_state);
+               req->private_state, struct open_socket_out_state);
        int ret;
        int sys_errno;
 
        ret = async_connect_recv(subreq, &sys_errno);
        TALLOC_FREE(subreq);
        if (ret == 0) {
-               async_req_done(req);
+               DEBUG(0, ("calling tevent_req_done from 
open_socket_out_connected\n"));
+               tevent_req_done(req);
                return;
        }
 
@@ -1082,13 +1081,13 @@ static void open_socket_out_connected(struct tevent_req 
*subreq)
                subreq = async_connect_send(state, state->ev, state->fd,
                                            (struct sockaddr *)&state->ss,
                                            state->salen);
-               if (async_req_nomem(subreq, req)) {
+               if (tevent_req_nomem(subreq, req)) {
                        return;
                }
                if (!tevent_req_set_endtime(
                            subreq, state->ev,
                            timeval_current_ofs(0, state->wait_nsec))) {
-                       async_req_error(req, ENOMEM);
+                       tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
                        return;
                }
                subreq->async.fn = open_socket_out_connected;
@@ -1098,23 +1097,23 @@ static void open_socket_out_connected(struct tevent_req 
*subreq)
 
 #ifdef EISCONN
        if (sys_errno == EISCONN) {
-               async_req_done(req);
+               tevent_req_done(req);
                return;
        }
 #endif
 
        /* real error */
-       async_req_error(req, sys_errno);
+       tevent_req_nterror(req, map_nt_error_from_unix(sys_errno));
 }
 
-NTSTATUS open_socket_out_recv(struct async_req *req, int *pfd)
+NTSTATUS open_socket_out_recv(struct tevent_req *req, int *pfd)
 {
        struct open_socket_out_state *state = talloc_get_type_abort(
-               req->private_data, struct open_socket_out_state);
-       int err;
+               req->private_state, struct open_socket_out_state);
+       NTSTATUS status;
 
-       if (async_req_is_errno(req, &err)) {
-               return map_nt_error_from_unix(err);
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
        }
        *pfd = state->fd;
        state->fd = -1;
@@ -1126,7 +1125,7 @@ NTSTATUS open_socket_out(const struct sockaddr_storage 
*pss, uint16_t port,
 {
        TALLOC_CTX *frame = talloc_stackframe();
        struct event_context *ev;
-       struct async_req *req;
+       struct tevent_req *req;
        NTSTATUS status = NT_STATUS_NO_MEMORY;
 
        ev = event_context_init(frame);
@@ -1138,10 +1137,10 @@ NTSTATUS open_socket_out(const struct sockaddr_storage 
*pss, uint16_t port,
        if (req == NULL) {
                goto fail;
        }
-       while (req->state < ASYNC_REQ_DONE) {
-               event_loop_once(ev);
+       if (!tevent_req_poll(req, ev)) {
+               status = NT_STATUS_INTERNAL_ERROR;
+               goto fail;
        }
-
        status = open_socket_out_recv(req, pfd);
  fail:
        TALLOC_FREE(frame);
@@ -1157,7 +1156,7 @@ struct open_socket_out_defer_state {
 };
 
 static void open_socket_out_defer_waited(struct async_req *subreq);
-static void open_socket_out_defer_connected(struct async_req *subreq);
+static void open_socket_out_defer_connected(struct tevent_req *subreq);
 
 struct async_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx,
                                             struct event_context *ev,
@@ -1204,6 +1203,7 @@ static void open_socket_out_defer_waited(struct async_req 
*subreq)
                subreq->async.priv, struct async_req);
        struct open_socket_out_defer_state *state = talloc_get_type_abort(
                req->private_data, struct open_socket_out_defer_state);
+       struct tevent_req *subreq2;
        bool ret;
 
        ret = async_wait_recv(subreq);
@@ -1213,19 +1213,19 @@ static void open_socket_out_defer_waited(struct 
async_req *subreq)
                return;
        }
 
-       subreq = open_socket_out_send(state, state->ev, &state->ss,
-                                     state->port, state->timeout);
-       if (async_req_nomem(subreq, req)) {
+       subreq2 = open_socket_out_send(state, state->ev, &state->ss,
+                                      state->port, state->timeout);
+       if (async_req_nomem(subreq2, req)) {
                return;
        }
-       subreq->async.fn = open_socket_out_defer_connected;
-       subreq->async.priv = req;
+       subreq2->async.fn = open_socket_out_defer_connected;
+       subreq2->async.private_data = req;
 }
 
-static void open_socket_out_defer_connected(struct async_req *subreq)
+static void open_socket_out_defer_connected(struct tevent_req *subreq)
 {
        struct async_req *req = talloc_get_type_abort(
-               subreq->async.priv, struct async_req);
+               subreq->async.private_data, struct async_req);
        struct open_socket_out_defer_state *state = talloc_get_type_abort(
                req->private_data, struct open_socket_out_defer_state);
        NTSTATUS status;


-- 
Samba Shared Repository

Reply via email to