From 2cd51dd16965980a326be18bc3fb1b7d5c602717 Mon Sep 17 00:00:00 2001 From: pquerna Date: Sat, 11 Dec 2004 03:53:06 +0000 Subject: * file_io/unix/readwrite.c: Revert to the original code for apr_file writev() in the !HAVE_WRITEV case, and a large comment explaining why we cannot use a better method without breaking writev()'s semantics. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@111571 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 ---- file_io/unix/readwrite.c | 31 ++++++++++++++++--------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index 20746e530..8c2544c54 100644 --- a/CHANGES +++ b/CHANGES @@ -10,10 +10,6 @@ Changes for APR 1.1.0 *) Add apr_file_writev_full to ensure an entire iovec is writen to a file. [Paul Querna] - *) apr_file_writev will now at least try to write all iovecs on platforms - that do not support writev. - [Paul Querna] - *) Remove the runtime test for Sendfile versions on FreeBSD. PR 25718. [Mike Silbersack , Paul Querna] diff --git a/file_io/unix/readwrite.c b/file_io/unix/readwrite.c index 8f0562b02..97daf3fab 100644 --- a/file_io/unix/readwrite.c +++ b/file_io/unix/readwrite.c @@ -241,21 +241,22 @@ APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iove return APR_SUCCESS; } #else - int i; - int tbytes; - apr_status_t rv = APR_SUCCESS; - - *nbytes = 0; - - for (i = 0; i < nvec; i++) { - tbytes = vec[i].iov_len; - rv = apr_file_write(thefile, vec[i].iov_base, &tbytes); - *nbytes += tbytes; - if (rv != APR_SUCCESS || tbytes < vec[i].iov_len) { - break; - } - } - return rv; + /** + * The problem with trying to output the entire iovec is that we cannot + * maintain the behavoir that a real writev would have. If we iterate + * over the iovec one at a time, we loose the atomic properties of + * writev(). The other option is to combine the entire iovec into one + * buffer that we could then send in one call to write(). This is not + * reasonable since we do not know how much data an iocev could contain. + * + * The only reasonable option, that maintains the semantics of a real + * writev(), is to only write the first iovec. Callers of file_writev() + * must deal with partial writes as they normally would. If you want to + * ensure an entire iovec is written, use apr_file_writev_full(). + */ + + *nbytes = vec[0].iov_len; + return apr_file_write(thefile, vec[0].iov_base, nbytes); #endif } -- cgit v1.2.1