From: Stefan Metzmacher Date: Fri, 22 May 2009 10:28:17 +0000 (+0200) Subject: tsocket: allow empty vectors at the end for tstream_writev()/readv() X-Git-Tag: tdb-1.1.5~424 X-Git-Url: http://git.samba.org/samba.git/?p=ira%2Fwip.git;a=commitdiff_plain;h=edd9bd9b167cb04290b06eb9b209c21ad5a884a0;hp=e9010fa366746ec1ae948dbcf3493d446e23b14c;ds=sidebyside tsocket: allow empty vectors at the end for tstream_writev()/readv() metze --- diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c index 8f5f009d4c1..a4cbda8b837 100644 --- a/lib/tsocket/tsocket_bsd.c +++ b/lib/tsocket/tsocket_bsd.c @@ -1538,6 +1538,19 @@ static void tstream_bsd_readv_handler(void *private_data) state->count -= 1; } + /* + * 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 (state->count > 0) { /* we have more to read */ return; @@ -1685,6 +1698,19 @@ static void tstream_bsd_writev_handler(void *private_data) state->count -= 1; } + /* + * 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 (state->count > 0) { /* we have more to read */ return;