You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Blair Zajac <bl...@orcaware.com> on 2011/02/05 00:32:51 UTC
[PATCH] apr_file_flush_locked and short writes
Looking at apr_file_flush_locked(), it looks like it doesn't handle short writes for buffered apr_file_t's, upon a short write the unwritten data will be lost.
Here's a patch for this:
Index: file_io/unix/readwrite.c
===================================================================
--- file_io/unix/readwrite.c (revision 1067340)
+++ file_io/unix/readwrite.c (working copy)
@@ -409,7 +409,11 @@
rv = errno;
} else {
thefile->filePtr += written;
- thefile->bufpos = 0;
+ if (written != thefile->bufpos)
+ memmove(thefile->buffer,
+ thefile->buffer + written,
+ thefile->bufpos - written);
+ thefile->bufpos -= written;
}
}
Beyond this, there's no a mechanism to report that all the buffered data didn't get into the file. Perhaps apr_file_flush() should loop until the entire buffer is written or it gets a non-EINTR error?
Blair
Re: [PATCH] apr_file_flush_locked and short writes
Posted by Blair Zajac <bl...@orcaware.com>.
On 2/21/11 1:30 PM, Stefan Fritsch wrote:
> On Monday 21 February 2011, Bert Huijben wrote:
>>> Beyond this, there's no a mechanism to report that all the
>>> buffered data didn't get into the file. Perhaps
>>> apr_file_flush() should loop until the entire
>>> buffer is written or it gets a non-EINTR error?
>
> Commited the looping solution as r1073142, r1073145, r1073146
Thanks!
Regards,
Blair
Re: [PATCH] apr_file_flush_locked and short writes
Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Monday 21 February 2011, Bert Huijben wrote:
> > Beyond this, there's no a mechanism to report that all the
> > buffered data didn't get into the file. Perhaps
> > apr_file_flush() should loop until the entire
> > buffer is written or it gets a non-EINTR error?
Commited the looping solution as r1073142, r1073145, r1073146
RE: [PATCH] apr_file_flush_locked and short writes
Posted by Bert Huijben <be...@qqmail.nl>.
> -----Original Message-----
> From: Blair Zajac [mailto:blair@orcaware.com]
> Sent: zaterdag 5 februari 2011 0:33
> To: dev@apr.apache.org
> Subject: [PATCH] apr_file_flush_locked and short writes
>
> Looking at apr_file_flush_locked(), it looks like it doesn't handle short
writes
> for buffered apr_file_t's, upon a short write the unwritten data will be
lost.
>
> Here's a patch for this:
>
> Index: file_io/unix/readwrite.c
> ==========================================================
> =========
> --- file_io/unix/readwrite.c (revision 1067340)
> +++ file_io/unix/readwrite.c (working copy)
> @@ -409,7 +409,11 @@
> rv = errno;
> } else {
> thefile->filePtr += written;
> - thefile->bufpos = 0;
> + if (written != thefile->bufpos)
> + memmove(thefile->buffer,
> + thefile->buffer + written,
> + thefile->bufpos - written);
> + thefile->bufpos -= written;
> }
> }
>
>
> Beyond this, there's no a mechanism to report that all the buffered data
> didn't get into the file. Perhaps apr_file_flush() should loop until the
entire
> buffer is written or it gets a non-EINTR error?
Pinging this two weeks old issue as I think it should be fixed for the next
release.
Bert