]> granicus.if.org Git - apache/commitdiff
Pull lingering close out of the pool cleanup phase. This was causing too
authorRyan Bloom <rbb@apache.org>
Thu, 15 Nov 2001 20:49:54 +0000 (20:49 +0000)
committerRyan Bloom <rbb@apache.org>
Thu, 15 Nov 2001 20:49:54 +0000 (20:49 +0000)
many bugs.  Instead, it is called where it used to be called.  I have
abstracted some of the logic out of the lingering close so that it gets
the socket from the connection using the core's conn_config vector.  This
is in anticipation of a change to use a hook for the lingering close,
which I hope to do soon.

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

13 files changed:
include/http_connection.h
server/connection.c
server/core.c
server/mpm/beos/beos.c
server/mpm/experimental/perchild/perchild.c
server/mpm/mpmt_os2/mpmt_os2_child.c
server/mpm/netware/mpm_netware.c
server/mpm/perchild/perchild.c
server/mpm/prefork/prefork.c
server/mpm/spmt_os2/spmt_os2.c
server/mpm/threaded/threaded.c
server/mpm/winnt/mpm_winnt.c
server/mpm/worker/worker.c

index eb48cfcdd0215d420cd7e1d16d31752864cbf025..57b043890cd1700222f07785fdf81ed6a19e69ca 100644 (file)
@@ -92,7 +92,7 @@ AP_CORE_DECLARE(void) ap_flush_conn(conn_rec *c);
  * </pre>
  * @param c The connection we are closing
  */
-apr_status_t ap_lingering_close(void *dummy);
+AP_DECLARE(void) ap_lingering_close(conn_rec *c);
 #endif
 
   /* Hooks */
index b0d59aaed0d9ad76bbc83807d80089af7267a91b..1bc6c2bb1bb6875e089f929e007b153e57e1b9fd 100644 (file)
@@ -68,6 +68,7 @@
 #include "ap_mpm.h"
 #include "mpm_default.h"
 #include "http_config.h"
+#include "http_core.h"
 #include "http_vhost.h"
 #include "scoreboard.h"
 #include "http_log.h"
@@ -153,20 +154,24 @@ AP_CORE_DECLARE(void) ap_flush_conn(conn_rec *c)
  * all the response data has been sent to the client.
  */
 #define SECONDS_TO_LINGER  2
-apr_status_t ap_lingering_close(void *dummy)
+AP_DECLARE(void) ap_lingering_close(conn_rec *c)
 {
     char dummybuf[512];
     apr_size_t nbytes = sizeof(dummybuf);
     apr_status_t rc;
     apr_int32_t timeout;
     apr_int32_t total_linger_time = 0;
-    core_net_rec *net = dummy;
+    apr_socket_t *csd = ap_get_module_config(c->conn_config, &core_module);
 
-    ap_update_child_status(AP_CHILD_THREAD_FROM_ID(net->c->id), SERVER_CLOSING, NULL);
+    if (!csd) {
+        return;
+    }
+
+    ap_update_child_status(AP_CHILD_THREAD_FROM_ID(c->id), SERVER_CLOSING, NULL);
 
 #ifdef NO_LINGCLOSE
-    ap_flush_conn(net->c);     /* just close it */
-    apr_socket_close(net->client_socket);
+    ap_flush_conn(c);  /* just close it */
+    apr_socket_close(csd);
     return;
 #endif
 
@@ -176,20 +181,20 @@ apr_status_t ap_lingering_close(void *dummy)
      */
 
     /* Send any leftover data to the client, but never try to again */
-    ap_flush_conn(net->c);
+    ap_flush_conn(c);
 
-    if (net->c->aborted) {
-        apr_socket_close(net->client_socket);
-        return APR_SUCCESS;
+    if (c->aborted) {
+        apr_socket_close(csd);
+        return;
     }
 
     /* Shut down the socket for write, which will send a FIN
      * to the peer.
      */
-    if (apr_shutdown(net->client_socket, APR_SHUTDOWN_WRITE) != APR_SUCCESS || 
-        net->c->aborted) {
-        apr_socket_close(net->client_socket);
-        return APR_SUCCESS;
+    if (apr_shutdown(csd, APR_SHUTDOWN_WRITE) != APR_SUCCESS || 
+        c->aborted) {
+        apr_socket_close(csd);
+        return;
     }
 
     /* Read all data from the peer until we reach "end-of-file" (FIN
@@ -198,11 +203,11 @@ apr_status_t ap_lingering_close(void *dummy)
      * which seems to work well), close the connection.
      */
     timeout = SECONDS_TO_LINGER * APR_USEC_PER_SEC;
-    apr_setsocketopt(net->client_socket, APR_SO_TIMEOUT, timeout);
-    apr_setsocketopt(net->client_socket, APR_INCOMPLETE_READ, 1);
+    apr_setsocketopt(csd, APR_SO_TIMEOUT, timeout);
+    apr_setsocketopt(csd, APR_INCOMPLETE_READ, 1);
     for (;;) {
         nbytes = sizeof(dummybuf);
-        rc = apr_recv(net->client_socket, dummybuf, &nbytes);
+        rc = apr_recv(csd, dummybuf, &nbytes);
         if (rc != APR_SUCCESS || nbytes == 0) break;
 
         total_linger_time += SECONDS_TO_LINGER;
@@ -211,8 +216,8 @@ apr_status_t ap_lingering_close(void *dummy)
         }
     }
 
-    apr_socket_close(net->client_socket);
-    return APR_SUCCESS;
+    apr_socket_close(csd);
+    return;
 }
 
 AP_CORE_DECLARE(void) ap_process_connection(conn_rec *c)
index bf3eee79959f1da1196a38b2ced57d8d4363912b..3a9378f81b9c92680956d71cd9796829d4b3e293 100644 (file)
@@ -3095,10 +3095,6 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b)
             (nbytes + flen < AP_MIN_BYTES_TO_WRITE) && !APR_BUCKET_IS_FLUSH(last_e))
             || (nbytes + flen < AP_MIN_BYTES_TO_WRITE && APR_BUCKET_IS_EOS(last_e) && c->keepalive)) {
 
-            if (ctx->subpool == NULL) {
-                apr_pool_create(&ctx->subpool, f->c->pool);
-            }
-
             /* NEVER save an EOS in here.  If we are saving a brigade with 
              * an EOS bucket, then we are doing keepalive connections, and 
              * we want to process to second request fully.
@@ -3110,7 +3106,7 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b)
                  * after the request_pool is cleared.
                  */ 
                 if (ctx->b == NULL) {
-                    ctx->b = apr_brigade_create(ctx->subpool);
+                    ctx->b = apr_brigade_create(c->pool);
                 }
 
                 APR_BRIGADE_FOREACH(bucket, b) {
@@ -3135,13 +3131,11 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b)
                         return rv;
                     }
                     apr_brigade_write(ctx->b, NULL, NULL, str, n);
-                    ctx->subpool_has_stuff = 1;
                 }
                 apr_brigade_destroy(b);
             }
             else {
-                ap_save_brigade(f, &ctx->b, &b, ctx->subpool);
-                ctx->subpool_has_stuff = 1;
+                ap_save_brigade(f, &ctx->b, &b, c->pool);
             }
             return APR_SUCCESS;
         }
@@ -3216,11 +3210,6 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b)
         more = NULL;
     }  /* end while () */
 
-    if (ctx->subpool && ctx->subpool_has_stuff) {
-        apr_pool_clear(ctx->subpool);
-        ctx->subpool_has_stuff = 0;
-    }
-
     return APR_SUCCESS;
 }
 
@@ -3322,8 +3311,6 @@ static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *server,
  
     net->c->id = conn_id;
  
-    apr_pool_cleanup_register(ptrans, net, ap_lingering_close, apr_pool_cleanup_null);
     ap_set_module_config(net->c->conn_config, &core_module, csd);
     ap_add_input_filter("CORE_IN", net, NULL, net->c);
     ap_add_output_filter("CORE", net, NULL, net->c);
index 4ac0f6b70f9532893f6a0b9ef973b8f831d69ea5..63b1b04c913365142912d83526c3f60fb61f6216 100644 (file)
@@ -316,6 +316,7 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num)
 
     if (current_conn) {
         ap_process_connection(current_conn);
+        ap_lingering_close(current_conn);
     }
 }
 
index cd3aeb4a7bbb73e8d7af596d69758c095dc88100..909567770a9bbf096f95e3de9c668d35d7279be7 100644 (file)
@@ -505,6 +505,7 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id)
     current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id);
     if (current_conn) {
         ap_process_connection(current_conn);
+        ap_lingering_close(current_conn);
     }
 }
 
index 290a91ea069456681a6068ef88835bff6ca802cc..7e258d2695a58140cfc55c947527ede7704f08c5 100644 (file)
@@ -410,6 +410,7 @@ static void worker_main(void *vpArg)
 
         if (current_conn) {
             ap_process_connection(current_conn);
+            ap_lingering_close(current_conn);
         }
 
         apr_pool_destroy(pconn);
index 181d2909256d8cd0b0d52519d9fa6fbf0cefff82..82c69798597e66267e142f2841ed730b0aa7b772 100644 (file)
@@ -508,6 +508,7 @@ got_listener:
         current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd, my_worker_num);
         if (current_conn) {
             ap_process_connection(current_conn);
+            ap_lingering_close(current_conn);
         }
         
     }
index cd3aeb4a7bbb73e8d7af596d69758c095dc88100..909567770a9bbf096f95e3de9c668d35d7279be7 100644 (file)
@@ -505,6 +505,7 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id)
     current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id);
     if (current_conn) {
         ap_process_connection(current_conn);
+        ap_lingering_close(current_conn);
     }
 }
 
index 83c15d33e79838803693dfe157505ef251d131cd..0d7832404bdbba92288358b57e725039a01e112e 100644 (file)
@@ -682,6 +682,7 @@ static void child_main(int child_num_arg)
        current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd, my_child_num);
         if (current_conn) {
             ap_process_connection(current_conn);
+            ap_lingering_close(current_conn);
         }
         
         /* Check the pod after processing a connection so that we'll go away
index ab530d93c499a33fcc363408f6f43567611cc84f..f4ad1db88174975c2e9e69f4151bd0c7bb26d703 100644 (file)
@@ -682,6 +682,7 @@ static void thread_main(void *thread_num_arg)
 
         if (current_conn) {
             ap_process_connection(current_conn);
+            ap_lingering_close(current_conn);
         }
     }
 
index 8dc3cfd998df53c4b44800274b85d0aa1f35af0d..ad2274d650389b325a88255ca80550e9bff0f59e 100644 (file)
@@ -476,6 +476,7 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num,
     current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id);
     if (current_conn) {
         ap_process_connection(current_conn);
+        ap_lingering_close(current_conn);
     }
 }
 
index f68d7d5c2c506610a3c0cd9c86168d8687189a7e..7f9b75c55916e9e01d1b4fb6ae90e2bd7b343250 100644 (file)
@@ -901,9 +901,7 @@ static void worker_main(int thread_num)
             apr_getsocketopt(context->sock, APR_SO_DISCONNECTED, &disconnected);
             if (!disconnected) {
                 context->accept_socket = INVALID_SOCKET;
-            }
-            else {
-                apr_pool_cleanup_kill(context->ptrans, c, ap_lingering_close);
+                ap_lingering_close(c);
             }
         }
         else {
index 662bcdab00f83b9869ad96aa102d29fd59a55a0d..3d0c590c7d66436a64d1bb51007b8a23bb7691ea 100644 (file)
@@ -499,6 +499,7 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num,
     current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id);
     if (current_conn) {
         ap_process_connection(current_conn);
+        ap_lingering_close(current_conn);
     }
 }