summaryrefslogtreecommitdiff
path: root/lib/tsocket
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2015-02-16 13:50:25 +0000
committerJeremy Allison <jra@samba.org>2015-02-24 17:52:09 +0100
commitd6f70d334602d374442fa0670c09d80e70641c13 (patch)
treefee9b88f1e080366532c004c2c754e72f2f46ead /lib/tsocket
parent6e94f695c4cb8aabc57b5ef00073c2301fec409a (diff)
downloadsamba-d6f70d334602d374442fa0670c09d80e70641c13.tar.gz
tsocket: Use iov_advance
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/tsocket')
-rw-r--r--lib/tsocket/tsocket_bsd.c67
-rw-r--r--lib/tsocket/wscript_build2
2 files changed, 18 insertions, 51 deletions
diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c
index 35fd0893da9..79235c6e403 100644
--- a/lib/tsocket/tsocket_bsd.c
+++ b/lib/tsocket/tsocket_bsd.c
@@ -26,6 +26,7 @@
#include "system/network.h"
#include "tsocket.h"
#include "tsocket_internal.h"
+#include "lib/util/iov_buf.h"
static int tsocket_bsd_error_from_errno(int ret,
int sys_errno,
@@ -1747,7 +1748,8 @@ static void tstream_bsd_readv_handler(void *private_data)
struct tstream_bsd *bsds = tstream_context_data(stream, struct tstream_bsd);
int ret;
int err;
- bool retry;
+ int _count;
+ bool ok, retry;
ret = readv(bsds->fd, state->vector, state->count);
if (ret == 0) {
@@ -1766,31 +1768,13 @@ static void tstream_bsd_readv_handler(void *private_data)
state->ret += ret;
- while (ret > 0) {
- if (ret < state->vector[0].iov_len) {
- uint8_t *base;
- base = (uint8_t *)state->vector[0].iov_base;
- base += ret;
- state->vector[0].iov_base = (void *)base;
- state->vector[0].iov_len -= ret;
- break;
- }
- ret -= state->vector[0].iov_len;
- state->vector += 1;
- state->count -= 1;
- }
+ _count = state->count; /* tstream has size_t count, readv has int */
+ ok = iov_advance(&state->vector, &_count, ret);
+ state->count = _count;
- /*
- * there're maybe some empty vectors at the end
- * which we need to skip, otherwise we would get
- * ret == 0 from the readv() call and return EPIPE
- */
- while (state->count > 0) {
- if (state->vector[0].iov_len > 0) {
- break;
- }
- state->vector += 1;
- state->count -= 1;
+ if (!ok) {
+ tevent_req_error(req, EINVAL);
+ return;
}
if (state->count > 0) {
@@ -1907,7 +1891,8 @@ static void tstream_bsd_writev_handler(void *private_data)
struct tstream_bsd *bsds = tstream_context_data(stream, struct tstream_bsd);
ssize_t ret;
int err;
- bool retry;
+ int _count;
+ bool ok, retry;
ret = writev(bsds->fd, state->vector, state->count);
if (ret == 0) {
@@ -1926,31 +1911,13 @@ static void tstream_bsd_writev_handler(void *private_data)
state->ret += ret;
- while (ret > 0) {
- if (ret < state->vector[0].iov_len) {
- uint8_t *base;
- base = (uint8_t *)state->vector[0].iov_base;
- base += ret;
- state->vector[0].iov_base = (void *)base;
- state->vector[0].iov_len -= ret;
- break;
- }
- ret -= state->vector[0].iov_len;
- state->vector += 1;
- state->count -= 1;
- }
+ _count = state->count; /* tstream has size_t count, writev has int */
+ ok = iov_advance(&state->vector, &_count, ret);
+ state->count = _count;
- /*
- * there're maybe some empty vectors at the end
- * which we need to skip, otherwise we would get
- * ret == 0 from the writev() call and return EPIPE
- */
- while (state->count > 0) {
- if (state->vector[0].iov_len > 0) {
- break;
- }
- state->vector += 1;
- state->count -= 1;
+ if (!ok) {
+ tevent_req_error(req, EINVAL);
+ return;
}
if (state->count > 0) {
diff --git a/lib/tsocket/wscript_build b/lib/tsocket/wscript_build
index 5fa05f8c501..31ef14ec3d1 100644
--- a/lib/tsocket/wscript_build
+++ b/lib/tsocket/wscript_build
@@ -3,7 +3,7 @@
bld.SAMBA_SUBSYSTEM('LIBTSOCKET',
source='tsocket.c tsocket_helpers.c tsocket_bsd.c',
- public_deps='talloc tevent',
+ public_deps='talloc tevent iov_buf',
public_headers='tsocket.h tsocket_internal.h',
)