* </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 */
#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"
* 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
*/
/* 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
* 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;
}
}
- apr_socket_close(net->client_socket);
- return APR_SUCCESS;
+ apr_socket_close(csd);
+ return;
}
AP_CORE_DECLARE(void) ap_process_connection(conn_rec *c)
(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.
* 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) {
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;
}
more = NULL;
} /* end while () */
- if (ctx->subpool && ctx->subpool_has_stuff) {
- apr_pool_clear(ctx->subpool);
- ctx->subpool_has_stuff = 0;
- }
-
return APR_SUCCESS;
}
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);
if (current_conn) {
ap_process_connection(current_conn);
+ ap_lingering_close(current_conn);
}
}
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);
}
}
if (current_conn) {
ap_process_connection(current_conn);
+ ap_lingering_close(current_conn);
}
apr_pool_destroy(pconn);
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);
}
}
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);
}
}
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
if (current_conn) {
ap_process_connection(current_conn);
+ ap_lingering_close(current_conn);
}
}
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);
}
}
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 {
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);
}
}