Convert rpc_cli_transport->write to tevent_req
authorVolker Lendecke <vl@samba.org>
Mon, 23 Mar 2009 22:20:03 +0000 (23:20 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 24 Mar 2009 12:23:41 +0000 (13:23 +0100)
source3/include/client.h
source3/rpc_client/cli_pipe.c
source3/rpc_client/rpc_transport_np.c
source3/rpc_client/rpc_transport_smbd.c
source3/rpc_client/rpc_transport_sock.c

index 6510a14b153a1d4ca3ba4bdfda678c375be60acf..f0c8ecc9dd4e647d048a4d29d1d1f5a052629498 100644 (file)
@@ -83,14 +83,14 @@ struct rpc_cli_transport {
        /**
         * Trigger an async write to the server. May return a short write.
         */
-       struct async_req *(*write_send)(TALLOC_CTX *mem_ctx,
-                                       struct event_context *ev,
-                                       const uint8_t *data, size_t size,
-                                       void *priv);
+       struct tevent_req *(*write_send)(TALLOC_CTX *mem_ctx,
+                                        struct event_context *ev,
+                                        const uint8_t *data, size_t size,
+                                        void *priv);
        /**
         * Get the result from the read_send operation.
         */
-       NTSTATUS (*write_recv)(struct async_req *req, ssize_t *psent);
+       NTSTATUS (*write_recv)(struct tevent_req *req, ssize_t *psent);
 
        /**
         * This is an optimization for the SMB transport. It models the
index d4abe3c4fd1424fc0956dd50c0f1dcad9bdcca30..dbd6930718787596e5fefc39b4dd1f784a728cd6 100644 (file)
@@ -287,15 +287,14 @@ struct rpc_write_state {
        size_t num_written;
 };
 
-static void rpc_write_done(struct async_req *subreq);
+static void rpc_write_done(struct tevent_req *subreq);
 
 static struct tevent_req *rpc_write_send(TALLOC_CTX *mem_ctx,
                                         struct event_context *ev,
                                         struct rpc_cli_transport *transport,
                                         const uint8_t *data, size_t size)
 {
-       struct tevent_req *req;
-       struct async_req *subreq;
+       struct tevent_req *req, *subreq;
        struct rpc_write_state *state;
 
        req = tevent_req_create(mem_ctx, &state, struct rpc_write_state);
@@ -314,18 +313,17 @@ static struct tevent_req *rpc_write_send(TALLOC_CTX *mem_ctx,
        if (subreq == NULL) {
                goto fail;
        }
-       subreq->async.fn = rpc_write_done;
-       subreq->async.priv = req;
+       tevent_req_set_callback(subreq, rpc_write_done, req);
        return req;
  fail:
        TALLOC_FREE(req);
        return NULL;
 }
 
-static void rpc_write_done(struct async_req *subreq)
+static void rpc_write_done(struct tevent_req *subreq)
 {
-       struct tevent_req *req = talloc_get_type_abort(
-               subreq->async.priv, struct tevent_req);
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
        struct rpc_write_state *state = tevent_req_data(
                req, struct rpc_write_state);
        NTSTATUS status;
@@ -352,8 +350,7 @@ static void rpc_write_done(struct async_req *subreq)
        if (tevent_req_nomem(subreq, req)) {
                return;
        }
-       subreq->async.fn = rpc_write_done;
-       subreq->async.priv = req;
+       tevent_req_set_callback(subreq, rpc_write_done, req);
 }
 
 static NTSTATUS rpc_write_recv(struct tevent_req *req)
index 7da44213291162890f69b14c1ec42be1322712f1..620910060a81b99e17e33cb7ec7dac06c4191bce 100644 (file)
@@ -51,18 +51,19 @@ struct rpc_np_write_state {
 
 static void rpc_np_write_done(struct async_req *subreq);
 
-static struct async_req *rpc_np_write_send(TALLOC_CTX *mem_ctx,
-                                          struct event_context *ev,
-                                          const uint8_t *data, size_t size,
-                                          void *priv)
+static struct tevent_req *rpc_np_write_send(TALLOC_CTX *mem_ctx,
+                                           struct event_context *ev,
+                                           const uint8_t *data, size_t size,
+                                           void *priv)
 {
        struct rpc_transport_np_state *np_transport = talloc_get_type_abort(
                priv, struct rpc_transport_np_state);
-       struct async_req *result, *subreq;
+       struct tevent_req *req;
+       struct async_req *subreq;
        struct rpc_np_write_state *state;
 
-       if (!async_req_setup(mem_ctx, &result, &state,
-                            struct rpc_np_write_state)) {
+       req = tevent_req_create(mem_ctx, &state, struct rpc_np_write_state);
+       if (req == NULL) {
                return NULL;
        }
        state->size = size;
@@ -75,37 +76,37 @@ static struct async_req *rpc_np_write_send(TALLOC_CTX *mem_ctx,
                goto fail;
        }
        subreq->async.fn = rpc_np_write_done;
-       subreq->async.priv = result;
-       return result;
+       subreq->async.priv = req;
+       return req;
  fail:
-       TALLOC_FREE(result);
+       TALLOC_FREE(req);
        return NULL;
 }
 
 static void rpc_np_write_done(struct async_req *subreq)
 {
-       struct async_req *req = talloc_get_type_abort(
-               subreq->async.priv, struct async_req);
-       struct rpc_np_write_state *state = talloc_get_type_abort(
-               req->private_data, struct rpc_np_write_state);
+       struct tevent_req *req = talloc_get_type_abort(
+               subreq->async.priv, struct tevent_req);
+       struct rpc_np_write_state *state = tevent_req_data(
+               req, struct rpc_np_write_state);
        NTSTATUS status;
 
        status = cli_write_andx_recv(subreq, &state->written);
        TALLOC_FREE(subreq);
        if (!NT_STATUS_IS_OK(status)) {
-               async_req_nterror(req, status);
+               tevent_req_nterror(req, status);
                return;
        }
-       async_req_done(req);
+       tevent_req_done(req);
 }
 
-static NTSTATUS rpc_np_write_recv(struct async_req *req, ssize_t *pwritten)
+static NTSTATUS rpc_np_write_recv(struct tevent_req *req, ssize_t *pwritten)
 {
-       struct rpc_np_write_state *state = talloc_get_type_abort(
-               req->private_data, struct rpc_np_write_state);
+       struct rpc_np_write_state *state = tevent_req_data(
+               req, struct rpc_np_write_state);
        NTSTATUS status;
 
-       if (async_req_is_nterror(req, &status)) {
+       if (tevent_req_is_nterror(req, &status)) {
                return status;
        }
        *pwritten = state->written;
index 85fe3d86cef3317389a03e934cce2ccb70832e22..bde8d04208f2a590b5467218dcba2851f7c52f6a 100644 (file)
@@ -432,20 +432,20 @@ struct rpc_smbd_write_state {
        ssize_t written;
 };
 
-static void rpc_smbd_write_done(struct async_req *subreq);
+static void rpc_smbd_write_done(struct tevent_req *subreq);
 
-static struct async_req *rpc_smbd_write_send(TALLOC_CTX *mem_ctx,
-                                            struct event_context *ev,
-                                            const uint8_t *data, size_t size,
-                                            void *priv)
+static struct tevent_req *rpc_smbd_write_send(TALLOC_CTX *mem_ctx,
+                                             struct event_context *ev,
+                                             const uint8_t *data, size_t size,
+                                             void *priv)
 {
        struct rpc_transport_smbd_state *transp = talloc_get_type_abort(
                priv, struct rpc_transport_smbd_state);
-       struct async_req *result, *subreq;
+       struct tevent_req *req, *subreq;
        struct rpc_smbd_write_state *state;
 
-       if (!async_req_setup(mem_ctx, &result, &state,
-                            struct rpc_smbd_write_state)) {
+       req = tevent_req_create(mem_ctx, &state, struct rpc_smbd_write_state);
+       if (req == NULL) {
                return NULL;
        }
        state->sub_transp = transp->sub_transp;
@@ -460,40 +460,38 @@ static struct async_req *rpc_smbd_write_send(TALLOC_CTX *mem_ctx,
                         rpc_cli_smbd_stdout_reader, transp->conn) == NULL) {
                goto fail;
        }
-
-       subreq->async.fn = rpc_smbd_write_done;
-       subreq->async.priv = result;
-       return result;
+       tevent_req_set_callback(subreq, rpc_smbd_write_done, req);
+       return req;
 
  fail:
-       TALLOC_FREE(result);
+       TALLOC_FREE(req);
        return NULL;
 }
 
-static void rpc_smbd_write_done(struct async_req *subreq)
+static void rpc_smbd_write_done(struct tevent_req *subreq)
 {
-       struct async_req *req = talloc_get_type_abort(
-               subreq->async.priv, struct async_req);
-       struct rpc_smbd_write_state *state = talloc_get_type_abort(
-               req->private_data, struct rpc_smbd_write_state);
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct rpc_smbd_write_state *state = tevent_req_data(
+               req, struct rpc_smbd_write_state);
        NTSTATUS status;
 
        status = state->sub_transp->write_recv(subreq, &state->written);
        TALLOC_FREE(subreq);
        if (!NT_STATUS_IS_OK(status)) {
-               async_req_nterror(req, status);
+               tevent_req_nterror(req, status);
                return;
        }
-       async_req_done(req);
+       tevent_req_done(req);
 }
 
-static NTSTATUS rpc_smbd_write_recv(struct async_req *req, ssize_t *pwritten)
+static NTSTATUS rpc_smbd_write_recv(struct tevent_req *req, ssize_t *pwritten)
 {
-       struct rpc_smbd_write_state *state = talloc_get_type_abort(
-               req->private_data, struct rpc_smbd_write_state);
+       struct rpc_smbd_write_state *state = tevent_req_data(
+               req, struct rpc_smbd_write_state);
        NTSTATUS status;
 
-       if (async_req_is_nterror(req, &status)) {
+       if (tevent_req_is_nterror(req, &status)) {
                return status;
        }
        *pwritten = state->written;
index c9fcbcc07e915508f692cee10931621268af924d..570d792c9c3fa417c85a008847105ff8170d49bb 100644 (file)
@@ -102,55 +102,54 @@ struct rpc_sock_write_state {
 
 static void rpc_sock_write_done(struct tevent_req *subreq);
 
-static struct async_req *rpc_sock_write_send(TALLOC_CTX *mem_ctx,
-                                            struct event_context *ev,
-                                            const uint8_t *data, size_t size,
-                                            void *priv)
+static struct tevent_req *rpc_sock_write_send(TALLOC_CTX *mem_ctx,
+                                             struct event_context *ev,
+                                             const uint8_t *data, size_t size,
+                                             void *priv)
 {
        struct rpc_transport_sock_state *sock_transp = talloc_get_type_abort(
                priv, struct rpc_transport_sock_state);
-       struct async_req *result;
-       struct tevent_req *subreq;
+       struct tevent_req *req, *subreq;
        struct rpc_sock_write_state *state;
 
-       if (!async_req_setup(mem_ctx, &result, &state,
-                            struct rpc_sock_write_state)) {
+       req = tevent_req_create(mem_ctx, &state, struct rpc_sock_write_state);
+       if (req == NULL) {
                return NULL;
        }
        subreq = async_send_send(state, ev, sock_transp->fd, data, size, 0);
        if (subreq == NULL) {
                goto fail;
        }
-       tevent_req_set_callback(subreq, rpc_sock_write_done, result);
-       return result;
+       tevent_req_set_callback(subreq, rpc_sock_write_done, req);
+       return req;
  fail:
-       TALLOC_FREE(result);
+       TALLOC_FREE(req);
        return NULL;
 }
 
 static void rpc_sock_write_done(struct tevent_req *subreq)
 {
-       struct async_req *req =
-               tevent_req_callback_data(subreq, struct async_req);
-       struct rpc_sock_write_state *state = talloc_get_type_abort(
-               req->private_data, struct rpc_sock_write_state);
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct rpc_sock_write_state *state = tevent_req_data(
+               req, struct rpc_sock_write_state);
        int err;
 
        state->sent = async_send_recv(subreq, &err);
        if (state->sent == -1) {
-               async_req_nterror(req, map_nt_error_from_unix(err));
+               tevent_req_nterror(req, map_nt_error_from_unix(err));
                return;
        }
-       async_req_done(req);
+       tevent_req_done(req);
 }
 
-static NTSTATUS rpc_sock_write_recv(struct async_req *req, ssize_t *psent)
+static NTSTATUS rpc_sock_write_recv(struct tevent_req *req, ssize_t *psent)
 {
-       struct rpc_sock_write_state *state = talloc_get_type_abort(
-               req->private_data, struct rpc_sock_write_state);
+       struct rpc_sock_write_state *state = tevent_req_data(
+               req, struct rpc_sock_write_state);
        NTSTATUS status;
 
-       if (async_req_is_nterror(req, &status)) {
+       if (tevent_req_is_nterror(req, &status)) {
                return status;
        }
        *psent = state->sent;