diff --git a/include/http_connection.h b/include/http_connection.h index eb48cfcdd0215d420cd7e1d16d31752864cbf025..57b043890cd1700222f07785fdf81ed6a19e69ca 100644 --- a/include/http_connection.h +++ b/include/http_connection.h @@ -92,7 +92,7 @@ AP_CORE_DECLARE(void) ap_flush_conn(conn_rec *c); * * @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 */ diff --git a/server/connection.c b/server/connection.c index b0d59aaed0d9ad76bbc83807d80089af7267a91b..1bc6c2bb1bb6875e089f929e007b153e57e1b9fd 100644 --- a/server/connection.c +++ b/server/connection.c @@ -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) diff --git a/server/core.c b/server/core.c index bf3eee79959f1da1196a38b2ced57d8d4363912b..3a9378f81b9c92680956d71cd9796829d4b3e293 100644 --- a/server/core.c +++ b/server/core.c @@ -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); diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c index 4ac0f6b70f9532893f6a0b9ef973b8f831d69ea5..63b1b04c913365142912d83526c3f60fb61f6216 100644 --- a/server/mpm/beos/beos.c +++ b/server/mpm/beos/beos.c @@ -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); } } diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c index cd3aeb4a7bbb73e8d7af596d69758c095dc88100..909567770a9bbf096f95e3de9c668d35d7279be7 100644 --- a/server/mpm/experimental/perchild/perchild.c +++ b/server/mpm/experimental/perchild/perchild.c @@ -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); } } diff --git a/server/mpm/mpmt_os2/mpmt_os2_child.c b/server/mpm/mpmt_os2/mpmt_os2_child.c index 290a91ea069456681a6068ef88835bff6ca802cc..7e258d2695a58140cfc55c947527ede7704f08c5 100644 --- a/server/mpm/mpmt_os2/mpmt_os2_child.c +++ b/server/mpm/mpmt_os2/mpmt_os2_child.c @@ -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); diff --git a/server/mpm/netware/mpm_netware.c b/server/mpm/netware/mpm_netware.c index 181d2909256d8cd0b0d52519d9fa6fbf0cefff82..82c69798597e66267e142f2841ed730b0aa7b772 100644 --- a/server/mpm/netware/mpm_netware.c +++ b/server/mpm/netware/mpm_netware.c @@ -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); } } diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c index cd3aeb4a7bbb73e8d7af596d69758c095dc88100..909567770a9bbf096f95e3de9c668d35d7279be7 100644 --- a/server/mpm/perchild/perchild.c +++ b/server/mpm/perchild/perchild.c @@ -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); } } diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 83c15d33e79838803693dfe157505ef251d131cd..0d7832404bdbba92288358b57e725039a01e112e 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -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 diff --git a/server/mpm/spmt_os2/spmt_os2.c b/server/mpm/spmt_os2/spmt_os2.c index ab530d93c499a33fcc363408f6f43567611cc84f..f4ad1db88174975c2e9e69f4151bd0c7bb26d703 100644 --- a/server/mpm/spmt_os2/spmt_os2.c +++ b/server/mpm/spmt_os2/spmt_os2.c @@ -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); } } diff --git a/server/mpm/threaded/threaded.c b/server/mpm/threaded/threaded.c index 8dc3cfd998df53c4b44800274b85d0aa1f35af0d..ad2274d650389b325a88255ca80550e9bff0f59e 100644 --- a/server/mpm/threaded/threaded.c +++ b/server/mpm/threaded/threaded.c @@ -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); } } diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index f68d7d5c2c506610a3c0cd9c86168d8687189a7e..7f9b75c55916e9e01d1b4fb6ae90e2bd7b343250 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -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 { diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 662bcdab00f83b9869ad96aa102d29fd59a55a0d..3d0c590c7d66436a64d1bb51007b8a23bb7691ea 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -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); } }