]> granicus.if.org Git - apache/commitdiff
WinNT: Implement acceptex socket reuse. Make sure that the ap_sendfile flags
authorBill Stoddard <stoddard@apache.org>
Thu, 6 Jul 2000 15:13:30 +0000 (15:13 +0000)
committerBill Stoddard <stoddard@apache.org>
Thu, 6 Jul 2000 15:13:30 +0000 (15:13 +0000)
argument is properly initialized for all platforms.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85775 13f79535-47bb-0310-9956-ffa450edef68

modules/cache/mod_file_cache.c
modules/http/http_protocol.c
server/mpm/winnt/mpm_winnt.c

index 4bd0385dd89835b76c66c45cd85f7f3115028927..634b3bcde93690d71b1a185d67a7f2f4eb40edb4 100644 (file)
@@ -421,6 +421,14 @@ static int sendfile_handler(request_rec *r, a_file *file, int rangestatus)
     struct iovec iov;
     ap_hdtr_t hdtr;
     ap_hdtr_t *phdtr = &hdtr;
+    ap_int32_t flags = 0;
+
+    if (!r->connection->keepalive) {
+        /* Prepare the socket to be reused. Ignored on systems
+         * that do not support reusing the accept socket
+         */
+        flags |= APR_SENDFILE_DISCONNECT_SOCKET;
+    }
 
     /* 
      * We want to send any data held in the client buffer on the
@@ -446,7 +454,7 @@ static int sendfile_handler(request_rec *r, a_file *file, int rangestatus)
                      phdtr,
                      &offset,
                      &length,
-                     0);
+                     flags);
     }
     else {
         while (ap_each_byterange(r, &offset, &length)) {
@@ -455,7 +463,7 @@ static int sendfile_handler(request_rec *r, a_file *file, int rangestatus)
                          phdtr,
                          &offset,
                          &length,
-                         0);
+                         flags);
             phdtr = NULL;
         }
     }
index ea4bcdf9e1a2db5590121fd04b32bf7fa994330f..1563afb225688b26980761b8b4dcaea00621057f 100644 (file)
@@ -2250,6 +2250,7 @@ API_EXPORT(long) ap_send_fd(ap_file_t *fd, request_rec *r)
 {
     ap_size_t len = r->finfo.size;
 #if APR_HAS_SENDFILE
+    ap_int32_t flags = 0;
     if (!r->chunked) {
        ap_status_t rv;
         ap_bsetopt(r->connection->client, BO_TIMEOUT,
@@ -2257,12 +2258,20 @@ API_EXPORT(long) ap_send_fd(ap_file_t *fd, request_rec *r)
                    ? &r->server->keep_alive_timeout
                    : &r->server->timeout);
         ap_bflush(r->connection->client);
+
+        if (!r->connection->keepalive) {
+            /* Prepare the socket to be reused. Ignored on systems
+             * that do not support reusing the accept socket
+             */
+            flags |= APR_SENDFILE_DISCONNECT_SOCKET;
+        }
+
         rv = iol_sendfile(r->connection->client->iol, 
                           fd,     /* The file to send */
                           NULL,   /* header and trailer iovecs */
                           0,      /* Offset in file to begin sending from */
                           &len,
-                          0);
+                          flags);
         if (rv != APR_SUCCESS) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
                           "ap_send_fd: iol_sendfile failed.");
index a587e4001001e28e519f9c5ee7f50ce8558cfa81..3fe15f3bbe4e90edbbdec03d2058bdb4964fb5de 100644 (file)
@@ -944,7 +944,6 @@ static ap_inline ap_status_t reset_acceptex_context(PCOMP_CONTEXT context)
                          "reset_acceptex_context: AcceptEx failed for "
                          "listening socket: %d and accept socket: %d", 
                          nsd, context->accept_socket);
-            context->accept_socket = INVALID_SOCKET;
             return lasterror;
         }
     }
@@ -1071,6 +1070,7 @@ static void worker_main(int child_num)
     while (1) {
         conn_rec *current_conn;
         ap_iol *iol;
+        ap_int32_t disconnected;
 
         /* Grab a connection off the network */
         if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
@@ -1099,8 +1099,20 @@ static void worker_main(int child_num)
                                          child_num);
 
         ap_process_connection(current_conn);
-        ap_lingering_close(current_conn);
-        context->accept_socket = INVALID_SOCKET;
+
+
+        ap_getsocketopt(context->sock, APR_SO_DISCONNECTED, &disconnected);
+        if (disconnected) {
+            /* Kill the clean-up registered by the iol. We want to leave 
+             * the accept socket open because we are about to try to 
+             * reuse it
+             */
+            ap_bpop_iol(&iol, context->conn_io);
+        }
+        else {
+            context->accept_socket = INVALID_SOCKET;
+            ap_lingering_close(current_conn);
+        }
     }
 
     ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, server_conf,