Add "queue" to writev_send
authorVolker Lendecke <vl@samba.org>
Sun, 1 Mar 2009 18:43:07 +0000 (19:43 +0100)
committerVolker Lendecke <vl@samba.org>
Sun, 8 Mar 2009 10:20:59 +0000 (11:20 +0100)
Unless higher levels queue themselves somehow, writev will *always* be queued.
So the queueing should be done at the right level.

lib/async_req/async_sock.c
lib/async_req/async_sock.h
source3/lib/wb_reqtrans.c
source3/rpc_server/srv_pipe_hnd.c

index 424da952ebabb6fabf5f879269a14039c4866bbe..f803b9cc36bf683cfd749c74c2f82e77ac15a779 100644 (file)
@@ -379,11 +379,13 @@ struct writev_state {
        size_t total_size;
 };
 
+static void writev_trigger(struct tevent_req *req, void *private_data);
 static void writev_handler(struct tevent_context *ev, struct tevent_fd *fde,
                           uint16_t flags, void *private_data);
 
 struct tevent_req *writev_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
-                              int fd, struct iovec *iov, int count)
+                              struct tevent_queue *queue, int fd,
+                              struct iovec *iov, int count)
 {
        struct tevent_req *result;
        struct writev_state *state;
@@ -403,18 +405,42 @@ struct tevent_req *writev_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
                goto fail;
        }
 
+       /*
+        * This if () should go away once our callers are converted to always
+        * pass in a queue.
+        */
+
+       if (queue != NULL) {
+               if (!tevent_queue_add(queue, ev, result, writev_trigger,
+                                     NULL)) {
+                       goto fail;
+               }
+               return result;
+       }
+
        fde = tevent_add_fd(ev, state, fd, TEVENT_FD_WRITE, writev_handler,
                            result);
        if (fde == NULL) {
                goto fail;
        }
        return result;
-
  fail:
        TALLOC_FREE(result);
        return NULL;
 }
 
+static void writev_trigger(struct tevent_req *req, void *private_data)
+{
+       struct writev_state *state = tevent_req_data(req, struct writev_state);
+       struct tevent_fd *fde;
+
+       fde = tevent_add_fd(state->ev, state, state->fd, TEVENT_FD_WRITE,
+                           writev_handler, req);
+       if (fde == NULL) {
+               tevent_req_error(req, ENOMEM);
+       }
+}
+
 static void writev_handler(struct tevent_context *ev, struct tevent_fd *fde,
                           uint16_t flags, void *private_data)
 {
index e001709d2783b4f5696875e208bab330bc55fb9f..c5d9400eb60e3ea6d3bcabfe894615b4747b1e0a 100644 (file)
@@ -43,7 +43,8 @@ struct tevent_req *async_connect_send(TALLOC_CTX *mem_ctx,
 int async_connect_recv(struct tevent_req *req, int *perrno);
 
 struct tevent_req *writev_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
-                              int fd, struct iovec *iov, int count);
+                              struct tevent_queue *queue, int fd,
+                              struct iovec *iov, int count);
 ssize_t writev_recv(struct tevent_req *req, int *perrno);
 
 struct tevent_req *read_packet_send(TALLOC_CTX *mem_ctx,
index 222b64667ce33cd20c6c394276d08837e08ade2c..26dfb783ab00b27ed9140a3261262d1917e2528a 100644 (file)
@@ -208,7 +208,7 @@ struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx,
                count = 2;
        }
 
-       subreq = writev_send(state, ev, fd, state->iov, count);
+       subreq = writev_send(state, ev, NULL, fd, state->iov, count);
        if (subreq == NULL) {
                goto fail;
        }
@@ -360,7 +360,7 @@ struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx,
                count = 2;
        }
 
-       subreq = writev_send(state, ev, fd, state->iov, count);
+       subreq = writev_send(state, ev, NULL, fd, state->iov, count);
        if (subreq == NULL) {
                goto fail;
        }
index a5d059c06a18f96f7e987837274777e6c4ce461e..fb7aca5c0fa2febbf9f3578d72962ce41f2dd3d3 100644 (file)
@@ -1243,7 +1243,8 @@ static void np_write_trigger(struct async_req *req)
                req->private_data, struct np_write_state);
        struct tevent_req *subreq;
 
-       subreq = writev_send(state, state->ev, state->p->fd, &state->iov, 1);
+       subreq = writev_send(state, state->ev, NULL, state->p->fd,
+                            &state->iov, 1);
        if (async_req_nomem(subreq, req)) {
                return;
        }