You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Greg Ames <gr...@raleigh.ibm.com> on 2000/07/19 23:24:19 UTC

[PATCH] ap_send_fd - less packets when using sendfile

Currently, when ap_send_fd uses sendfile, helper function static_send_file flushes the
BUFF before invoking iol_sendfile.  This causes the http headers to be sent separately
from the first blob of data in the file, increasing the number of packets that are sent.  

This patch sends any headers queued in the BUFF as sendfile headers, and resets the BUFF
to empty so its contents won't be re-sent by end of request processing.

Tested on Linux. 

Greg

Index: main/http_protocol.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/main/http_protocol.c,v
retrieving revision 1.96
diff -u -d -b -r1.96 http_protocol.c
--- http_protocol.c     2000/07/13 16:26:42     1.96
+++ http_protocol.c     2000/07/19 20:14:10
@@ -2249,22 +2249,41 @@
 {
     ap_int32_t flags = 0;
     ap_status_t rv;
+    struct iovec iov;
+    ap_hdtr_t hdtr;
+    ap_hdtr_t *phdtr = &hdtr;
 
     ap_bsetopt(r->connection->client, BO_TIMEOUT,
                r->connection->keptalive
                ? &r->server->keep_alive_timeout
                : &r->server->timeout);
 
-    ap_bflush(r->connection->client);
+    /*
+     * We want to send any data held in the client buffer on the
+     * call to iol_sendfile. So hijack it then set outcnt to 0
+     * to prevent the data from being sent to the client again
+     * when the buffer is flushed to the client at the end of the
+     * request.
+     */
+    iov.iov_base = r->connection->client->outbase;
+    iov.iov_len =  r->connection->client->outcnt;
+    r->connection->client->outcnt = 0;
 
+    /* initialize the ap_hdtr_t struct */
+    phdtr->headers = &iov;
+    phdtr->numheaders = 1;
+    phdtr->trailers = NULL;
+    phdtr->numtrailers = 0;
+
     if (!r->connection->keepalive) {
         /* Prepare the socket to be reused */
+        /* XXX fix me - byteranges? */
         flags |= APR_SENDFILE_DISCONNECT_SOCKET;
     }
 
     rv = iol_sendfile(r->connection->client->iol, 
                       fd,      /* The file to send */
-                      NULL,    /* Header and trailer iovecs */
+                      phdtr,   /* Header and trailer iovecs */
                       &offset, /* Offset in file to begin sending from */
                       &length,
                       flags);