Hey everyone,

There is a problem on systems with largefile support (such as windows 2000)
when downloading a file that is larger than AP_MAX_SENDFILE (16777216)
with keepalives turned off.

When largefile support is enabled, we split up files larger
AP_MAX_SENDFILE into several file buckets.  Just before we call sendfile, 
we set the APR_SENDFILE_DISCONNECT_SOCKET flag, even if there are more 
file buckets sitting in the brigade.  The result is truncated file of 
size 16777216, since the socket has been closed after the first call to
sendfile.

This patch disables setting this flag unless we are the last file bucket
in the brigade.  I've also attached a patch that fixes a comment in 
httpd.h

Thanks,

-Ryan
Index: core.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/core.c,v
retrieving revision 1.149
diff -u -r1.149 core.c
--- core.c      19 Feb 2002 04:45:53 -0000      1.149
+++ core.c      21 Feb 2002 01:05:37 -0000
@@ -3633,7 +3633,7 @@
                 hdtr.trailers = vec_trailers;
             }
 #if APR_HAS_SENDFILE
-            if (!c->keepalive) {
+            if (!c->keepalive && APR_BUCKET_IS_EOS(last_e)) {
                 /* Prepare the socket to be reused */
                 flags |= APR_SENDFILE_DISCONNECT_SOCKET;
             }
Index: httpd.h
===================================================================
RCS file: /home/cvspublic/httpd-2.0/include/httpd.h,v
retrieving revision 1.177
diff -u -r1.177 httpd.h
--- httpd.h     11 Feb 2002 23:20:15 -0000      1.177
+++ httpd.h     21 Feb 2002 01:05:26 -0000
@@ -324,9 +324,9 @@
  * APR_HAS_LARGE_FILES introduces the problem of spliting sendfile into 
  * mutiple buckets, no greater than MAX(apr_size_t), and more granular 
  * than that in case the brigade code/filters attempt to read it directly.
- * ### 4mb is an invention, no idea if it is reasonable.
+ * ### 16mb is an invention, no idea if it is reasonable.
  */
-#define AP_MAX_SENDFILE 16777216
+#define AP_MAX_SENDFILE 16777216  /* 2^24 */
 
 /**
  * Special Apache error codes. These are basically used

Reply via email to