summaryrefslogtreecommitdiff
path: root/lib/async_req
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-12-27 16:39:08 +0000
committerJeremy Allison <jra@samba.org>2014-12-30 00:25:08 +0100
commit475cfb8dee6cdb5a89e8f15b32ad3886f949005f (patch)
tree2e843c98a4cc8964b5e4933bf40a37ce835a2668 /lib/async_req
parent8855c0332a5ad2996873727074af6974f1238d5f (diff)
downloadsamba-475cfb8dee6cdb5a89e8f15b32ad3886f949005f.tar.gz
lib: Use iov_advance in writev_handler
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/async_req')
-rw-r--r--lib/async_req/async_sock.c34
-rw-r--r--lib/async_req/wscript_build2
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 <talloc.h>
#include <tevent.h>
#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; i<state->count; 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'
)