gregames 02/05/17 14:19:45
Modified: network_io/unix sendrecv.c
Log:
FreeBSD sendfile: return an error if the kernel returns 0 & no bytes sent.
This probably means the file became smaller after it was stat()ed.
Revision Changes Path
1.84 +21 -10 apr/network_io/unix/sendrecv.c
Index: sendrecv.c
===================================================================
RCS file: /home/cvs/apr/network_io/unix/sendrecv.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- sendrecv.c 17 May 2002 18:01:14 -0000 1.83
+++ sendrecv.c 17 May 2002 21:19:45 -0000 1.84
@@ -490,18 +490,29 @@
&nbytes, /* number of bytes written */
flags); /* undefined, set to 0 */
- if (rv == -1 && errno == EAGAIN) {
- if (sock->timeout) {
- sock->netmask |= APR_INCOMPLETE_WRITE;
+ if (rv == -1) {
+ if (errno == EAGAIN) {
+ if (sock->timeout) {
+ sock->netmask |= APR_INCOMPLETE_WRITE;
+ }
+ /* FreeBSD's sendfile can return -1/EAGAIN even if it
+ * sent bytes. Sanitize the result so we get normal
EAGAIN
+ * semantics w.r.t. bytes sent.
+ */
+ if (nbytes) {
+ /* normal exit for a big file & non-blocking io */
+ (*len) = nbytes;
+ return APR_SUCCESS;
+ }
}
- /* FreeBSD's sendfile can return -1/EAGAIN even if it
- * sent bytes. Sanitize the result so we get normal EAGAIN
- * semantics w.r.t. bytes sent.
- */
- if (nbytes) {
- /* normal exit for a big file & non-blocking io */
+ }
+ else { /* rv == 0 (or the kernel is broken) */
+ if (nbytes == 0) {
+ /* Most likely the file got smaller after the stat.
+ * Return an error so the caller can do the Right Thing.
+ */
(*len) = nbytes;
- return APR_SUCCESS;
+ return APR_EOF;
}
}
}