Use async writev for wb_resp_write
authorVolker Lendecke <vl@samba.org>
Sun, 22 Feb 2009 20:55:03 +0000 (21:55 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 24 Feb 2009 19:40:47 +0000 (20:40 +0100)
source3/lib/wb_reqtrans.c

index 1c2d09318db11099d0da29d1f02c4511bed11ea4..1be72390927b5a3650d9a71e9e6d8e7479ff6e53 100644 (file)
@@ -451,91 +451,61 @@ wbcErr wb_resp_read_recv(struct async_req *req, TALLOC_CTX *mem_ctx,
 }
 
 struct resp_write_state {
-       struct winbindd_response *wb_resp;
-       struct tevent_context *ev;
-       int fd;
+       struct iovec iov[2];
 };
 
-static void wb_resp_write_main(struct async_req *subreq);
-static void wb_resp_write_extra(struct async_req *subreq);
+static void wb_resp_write_done(struct tevent_req *subreq);
 
 struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx,
                                    struct tevent_context *ev, int fd,
                                    struct winbindd_response *wb_resp)
 {
-       struct async_req *result, *subreq;
+       struct async_req *result;
+       struct tevent_req *subreq;
        struct resp_write_state *state;
+       int count = 1;
 
        if (!async_req_setup(mem_ctx, &result, &state,
                             struct resp_write_state)) {
                return NULL;
        }
-       state->fd = fd;
-       state->ev = ev;
-       state->wb_resp = wb_resp;
 
-       subreq = sendall_send(state, state->ev, state->fd, state->wb_resp,
-                             sizeof(struct winbindd_response), 0);
-       if (subreq == NULL) {
-               goto nomem;
+       state->iov[0].iov_base = wb_resp;
+       state->iov[0].iov_len = sizeof(struct winbindd_response);
+
+       if (wb_resp->length > sizeof(struct winbindd_response)) {
+               state->iov[1].iov_base = wb_resp->extra_data.data;
+               state->iov[1].iov_len =
+                       wb_resp->length - sizeof(struct winbindd_response);
+               count = 2;
        }
 
-       subreq->async.fn = wb_resp_write_main;
-       subreq->async.priv = result;
+       subreq = writev_send(state, ev, fd, state->iov, count);
+       if (subreq == NULL) {
+               goto fail;
+       }
+       subreq->async.fn = wb_resp_write_done;
+       subreq->async.private_data = result;
        return result;
 
nomem:
fail:
        TALLOC_FREE(result);
        return NULL;
 }
 
-static void wb_resp_write_main(struct async_req *subreq)
+static void wb_resp_write_done(struct tevent_req *subreq)
 {
        struct async_req *req = talloc_get_type_abort(
-               subreq->async.priv, struct async_req);
-       struct resp_write_state *state = talloc_get_type_abort(
-               req->private_data, struct resp_write_state);
+               subreq->async.private_data, struct async_req);
        int err;
        ssize_t ret;
 
-       ret = sendall_recv(subreq, &err);
+       ret = writev_recv(subreq, &err);
        TALLOC_FREE(subreq);
        if (ret < 0) {
                async_req_error(req, map_wbc_err_from_errno(err));
                return;
        }
-
-       if (state->wb_resp->length == sizeof(struct winbindd_response)) {
-               async_req_done(req);
-               return;
-       }
-
-       subreq = sendall_send(
-               state, state->ev, state->fd,
-               state->wb_resp->extra_data.data,
-               state->wb_resp->length - sizeof(struct winbindd_response), 0);
-       if (async_req_nomem(subreq, req)) {
-               return;
-       }
-
-       subreq->async.fn = wb_resp_write_extra;
-       subreq->async.priv = req;
-}
-
-static void wb_resp_write_extra(struct async_req *subreq)
-{
-       struct async_req *req = talloc_get_type_abort(
-               subreq->async.priv, struct async_req);
-       int err;
-       ssize_t ret;
-
-       ret = sendall_recv(subreq, &err);
-       TALLOC_FREE(subreq);
-       if (err < 0) {
-               async_req_error(req, map_wbc_err_from_errno(err));
-               return;
-       }
-
        async_req_done(req);
 }