From 475cfb8dee6cdb5a89e8f15b32ad3886f949005f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 27 Dec 2014 16:39:08 +0000 Subject: [PATCH] lib: Use iov_advance in writev_handler Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- lib/async_req/async_sock.c | 34 +++++++++------------------------- lib/async_req/wscript_build | 2 +- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/lib/async_req/async_sock.c b/lib/async_req/async_sock.c index 74b2cb7baa8..b986e45b0aa 100644 --- a/lib/async_req/async_sock.c +++ b/lib/async_req/async_sock.c @@ -27,6 +27,7 @@ #include #include #include "lib/async_req/async_sock.h" +#include "lib/iov_buf.h" /* Note: lib/util/ is currently GPL */ #include "lib/util/tevent_unix.h" @@ -470,10 +471,8 @@ static void writev_handler(struct tevent_context *ev, struct tevent_fd *fde, private_data, struct tevent_req); struct writev_state *state = tevent_req_data(req, struct writev_state); - size_t to_write, written; - int i; - - to_write = 0; + size_t written; + bool ok; if ((state->flags & TEVENT_FD_READ) && (flags & TEVENT_FD_READ)) { int ret, value; @@ -507,10 +506,6 @@ static void writev_handler(struct tevent_context *ev, struct tevent_fd *fde, } } - for (i=0; icount; i++) { - to_write += state->iov[i].iov_len; - } - written = writev(state->fd, state->iov, state->count); if ((written == -1) && (errno == EINTR)) { /* retry */ @@ -526,26 +521,15 @@ static void writev_handler(struct tevent_context *ev, struct tevent_fd *fde, } state->total_size += written; - if (written == to_write) { - tevent_req_done(req); + ok = iov_advance(&state->iov, &state->count, written); + if (!ok) { + tevent_req_error(req, EIO); return; } - /* - * We've written less than we were asked to, drop stuff from - * state->iov. - */ - - while (written > 0) { - if (written < state->iov[0].iov_len) { - state->iov[0].iov_base = - (char *)state->iov[0].iov_base + written; - state->iov[0].iov_len -= written; - break; - } - written -= state->iov[0].iov_len; - state->iov += 1; - state->count -= 1; + if (state->count == 0) { + tevent_req_done(req); + return; } } diff --git a/lib/async_req/wscript_build b/lib/async_req/wscript_build index 7802935f682..e8af569b4f9 100644 --- a/lib/async_req/wscript_build +++ b/lib/async_req/wscript_build @@ -3,7 +3,7 @@ bld.SAMBA_SUBSYSTEM('LIBASYNC_REQ', source='async_sock.c', - public_deps='talloc tevent', + public_deps='talloc tevent iov_buf', deps='tevent-util socket-blocking' ) -- 2.34.1