From: Bill Stoddard Date: Tue, 29 Jan 2002 19:02:04 +0000 (+0000) Subject: This patch restores most of Ryan's patch (11/12/2001) to remove the X-Git-Tag: 2.0.31~36 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4168820850f74e0b1cbe58be6acddfb1a86d7746;p=apache This patch restores most of Ryan's patch (11/12/2001) to remove the client_socket from the conn_rec. Diffs from Ryan's patch include: - rename the create_connection hook to install_transport_filters - move the point of invocation of the hook till after the call to after ap_update_vhost_given_ip to enable the hook to use vhost config info in its decision making. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93087 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/http_connection.h b/include/http_connection.h index 5cbcb86cd9..02cb5555b5 100644 --- a/include/http_connection.h +++ b/include/http_connection.h @@ -78,13 +78,14 @@ extern "C" { */ AP_CORE_DECLARE(conn_rec *)ap_new_connection(apr_pool_t *ptrans, server_rec *server, apr_socket_t *csd, long id, void *sbh); + /** * This is the protocol module driver. This calls all of the * pre-connection and connection hooks for all protocol modules. * @param c The connection on which the request is read * @deffunc void ap_process_connection(conn_rec *) */ -AP_CORE_DECLARE(void) ap_process_connection(conn_rec *); +AP_CORE_DECLARE(void) ap_process_connection(conn_rec *, apr_socket_t *csd); AP_CORE_DECLARE(void) ap_flush_conn(conn_rec *c); @@ -107,6 +108,19 @@ AP_DECLARE(void) ap_lingering_close(conn_rec *c); #endif /* Hooks */ +/** + * This hook is used to install the bottom most input and output + * filters (e.g., CORE_IN and CORE_OUT) used to interface to the + * network. This filter is a RUN_FIRST hook that runs right before + * the pre_connection filter. This filter hook can use vhost + * configuration to influence its operation. + * @param c The socket to the client + * @param csd Pointer to the client apr_socket_t struct. + * @return OK or DECLINED + * @deffunc int ap_run_install_transport_filters(conn_rec *c, apr_socket_t *csd) + */ +AP_DECLARE_HOOK(int, install_transport_filters, (conn_rec *c, apr_socket_t *csd)) + /** * This hook gives protocol modules an opportunity to set everything up * before calling the protocol handler. All pre-connection hooks are diff --git a/include/httpd.h b/include/httpd.h index ed0c332e27..800ea082ec 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -936,10 +936,6 @@ struct conn_rec { void *vhost_lookup_data; /* Information about the connection itself */ - - /** Connection to the client */ - apr_socket_t *client_socket; - /** local address */ apr_sockaddr_t *local_addr; /** remote address */ @@ -1093,6 +1089,17 @@ typedef struct core_output_filter_ctx { typedef struct core_filter_ctx { apr_bucket_brigade *b; } core_ctx_t; + +typedef struct core_net_rec { + /** Connection to the client */ + apr_socket_t *client_socket; + + /** connection record */ + conn_rec *c; + + core_output_filter_ctx_t *out_ctx; + core_ctx_t *in_ctx; +} core_net_rec; /** * Examine a field value (such as a media-/content-type) string and return diff --git a/modules/http/http_core.c b/modules/http/http_core.c index 64a58d39b0..c8659ae6ae 100644 --- a/modules/http/http_core.c +++ b/modules/http/http_core.c @@ -266,12 +266,7 @@ static const char *http_method(const request_rec *r) static apr_port_t http_port(const request_rec *r) { return DEFAULT_HTTP_PORT; } -static int ap_pre_http_connection(conn_rec *c) -{ - ap_add_input_filter_handle(ap_core_input_filter_handle, NULL, NULL, c); - ap_add_output_filter_handle(ap_core_output_filter_handle, NULL, NULL, c); - return OK; -} + static int ap_process_http_connection(conn_rec *c) { request_rec *r; @@ -321,8 +316,6 @@ static void ap_http_insert_filter(request_rec *r) static void register_hooks(apr_pool_t *p) { - ap_hook_pre_connection(ap_pre_http_connection,NULL,NULL, - APR_HOOK_REALLY_LAST); ap_hook_process_connection(ap_process_http_connection,NULL,NULL, APR_HOOK_REALLY_LAST); ap_hook_map_to_storage(ap_send_http_trace,NULL,NULL,APR_HOOK_MIDDLE); diff --git a/server/connection.c b/server/connection.c index d812bd4d1c..52ce3e97ab 100644 --- a/server/connection.c +++ b/server/connection.c @@ -77,10 +77,13 @@ APR_HOOK_STRUCT( APR_HOOK_LINK(pre_connection) APR_HOOK_LINK(process_connection) + APR_HOOK_LINK(install_transport_filters) ) AP_IMPLEMENT_HOOK_RUN_ALL(int,pre_connection,(conn_rec *c),(c),OK,DECLINED) AP_IMPLEMENT_HOOK_RUN_FIRST(int,process_connection,(conn_rec *c),(c),DECLINED) +AP_IMPLEMENT_HOOK_RUN_FIRST(int, install_transport_filters, + (conn_rec *c, apr_socket_t *csd),(c, csd), DECLINED) /* * More machine-dependent networking gooo... on some systems, @@ -157,7 +160,7 @@ AP_DECLARE(void) ap_lingering_close(conn_rec *c) apr_status_t rc; apr_int32_t timeout; apr_int32_t total_linger_time = 0; - apr_socket_t *csd = c->client_socket; + apr_socket_t *csd = ap_get_module_config(c->conn_config, &core_module); if (!csd) { return; @@ -216,10 +219,12 @@ AP_DECLARE(void) ap_lingering_close(conn_rec *c) return; } -AP_CORE_DECLARE(void) ap_process_connection(conn_rec *c) +AP_CORE_DECLARE(void) ap_process_connection(conn_rec *c, apr_socket_t *csd) { ap_update_vhost_given_ip(c); + ap_run_install_transport_filters(c, csd); + ap_run_pre_connection(c); if (!c->aborted) { @@ -235,15 +240,6 @@ AP_CORE_DECLARE(conn_rec *)ap_new_connection(apr_pool_t *ptrans, server_rec *ser c->sbh = sbh; (void) ap_update_child_status(c->sbh, SERVER_BUSY_READ, (request_rec *) NULL); -#ifdef AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK - /* BillS says perhaps this should be moved to the MPMs. Some OSes - * allow listening socket attributes to be inherited by the - * accept sockets which means this call only needs to be made - * once on the listener - */ - ap_sock_disable_nagle(csd); -#endif - /* Got a connection structure, so initialize what fields we can * (the rest are zeroed out by pcalloc). */ @@ -268,9 +264,7 @@ AP_CORE_DECLARE(conn_rec *)ap_new_connection(apr_pool_t *ptrans, server_rec *ser } apr_sockaddr_ip_get(&c->remote_ip, c->remote_addr); c->base_server = server; - c->client_socket = csd; c->id = id; - return c; } diff --git a/server/core.c b/server/core.c index 1cdfbfe4c4..0fbf99a3fe 100644 --- a/server/core.c +++ b/server/core.c @@ -2405,7 +2405,7 @@ static apr_status_t writev_it_all(apr_socket_t *s, */ #if APR_HAS_SENDFILE -static apr_status_t sendfile_it_all(conn_rec *c, +static apr_status_t sendfile_it_all(core_net_rec *c, apr_file_t *fd, apr_hdtr_t *hdtr, apr_off_t file_offset, @@ -2490,7 +2490,7 @@ static apr_status_t sendfile_it_all(conn_rec *c, * to the network. emulate_sendfile will return only when all the bytes have been * sent (i.e., it handles partial writes) or on a network error condition. */ -static apr_status_t emulate_sendfile(conn_rec *c, apr_file_t *fd, +static apr_status_t emulate_sendfile(core_net_rec *c, apr_file_t *fd, apr_hdtr_t *hdtr, apr_off_t offset, apr_size_t length, apr_size_t *nbytes) { @@ -2997,7 +2997,7 @@ static int net_time_filter(ap_filter_t *f, apr_bucket_brigade *b, apr_off_t readbytes) { int keptalive = f->c->keepalive == 1; - apr_socket_t *csd = f->c->client_socket; + apr_socket_t *csd = ap_get_module_config(f->c->conn_config, &core_module); int *first_line = f->ctx; if (!f->ctx) { @@ -3029,7 +3029,8 @@ static int core_input_filter(ap_filter_t *f, apr_bucket_brigade *b, { apr_bucket *e; apr_status_t rv; - core_ctx_t *ctx = f->ctx; + core_net_rec *net = f->ctx; + core_ctx_t *ctx = net->in_ctx; const char *str; apr_size_t len; @@ -3049,12 +3050,13 @@ static int core_input_filter(ap_filter_t *f, apr_bucket_brigade *b, if (!ctx) { - f->ctx = ctx = apr_pcalloc(f->c->pool, sizeof(*ctx)); + ctx = apr_pcalloc(f->c->pool, sizeof(*ctx)); ctx->b = apr_brigade_create(f->c->pool); /* seed the brigade with the client socket. */ - e = apr_bucket_socket_create(f->c->client_socket); + e = apr_bucket_socket_create(net->client_socket); APR_BRIGADE_INSERT_TAIL(ctx->b, e); + net->in_ctx = ctx; } else if (APR_BRIGADE_EMPTY(ctx->b)) { /* hit EOF on socket already */ @@ -3203,10 +3205,12 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b) { apr_status_t rv; conn_rec *c = f->c; - core_output_filter_ctx_t *ctx = f->ctx; + core_net_rec *net = f->ctx; + core_output_filter_ctx_t *ctx = net->out_ctx; if (ctx == NULL) { - f->ctx = ctx = apr_pcalloc(c->pool, sizeof(*ctx)); + ctx = apr_pcalloc(net->c->pool, sizeof(*ctx)); + net->out_ctx = ctx; } /* If we have a saved brigade, concatenate the new brigade to it */ @@ -3408,7 +3412,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(c->pool); + ctx->b = apr_brigade_create(net->c->pool); } APR_BRIGADE_FOREACH(bucket, b) { @@ -3462,7 +3466,7 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b) /* Prepare the socket to be reused */ flags |= APR_SENDFILE_DISCONNECT_SOCKET; } - rv = sendfile_it_all(c, /* the network information */ + rv = sendfile_it_all(net, /* the network information */ fd, /* the file to send */ &hdtr, /* header and trailer iovecs */ foffset, /* offset in the file to begin @@ -3481,7 +3485,7 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b) #endif { apr_size_t unused_bytes_sent; - rv = emulate_sendfile(c, fd, &hdtr, foffset, flen, + rv = emulate_sendfile(net, fd, &hdtr, foffset, flen, &unused_bytes_sent); } fd = NULL; @@ -3489,7 +3493,7 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b) else { apr_size_t unused_bytes_sent; - rv = writev_it_all(c->client_socket, + rv = writev_it_all(net->client_socket, vec, nvec, nbytes, &unused_bytes_sent); } @@ -3611,8 +3615,33 @@ static int core_create_proxy_req(request_rec *r, request_rec *pr) return core_create_req(pr); } +static int core_install_transport_filters(conn_rec *c, apr_socket_t *csd) +{ + core_net_rec *net = apr_palloc(c->pool, sizeof(*net)); + +#ifdef AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK + /* BillS says perhaps this should be moved to the MPMs. Some OSes + * allow listening socket attributes to be inherited by the + * accept sockets which means this call only needs to be made + * once on the listener + */ + ap_sock_disable_nagle(csd); +#endif + net->c = c; + net->in_ctx = NULL; + net->out_ctx = NULL; + net->client_socket = csd; + + 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); + return OK; +} + static void register_hooks(apr_pool_t *p) { + ap_hook_install_transport_filters(core_install_transport_filters, NULL, + NULL, APR_HOOK_REALLY_LAST); ap_hook_post_config(core_post_config,NULL,NULL,APR_HOOK_REALLY_FIRST); ap_hook_translate_name(ap_core_translate,NULL,NULL,APR_HOOK_REALLY_LAST); ap_hook_map_to_storage(core_map_to_storage,NULL,NULL,APR_HOOK_REALLY_LAST); diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c index b618e364af..1f6d015418 100644 --- a/server/mpm/beos/beos.c +++ b/server/mpm/beos/beos.c @@ -349,7 +349,7 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num) current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id, sbh); if (current_conn) { - ap_process_connection(current_conn); + ap_process_connection(current_conn, sock); ap_lingering_close(current_conn); } } diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c index ddc947f004..fe69695acc 100644 --- a/server/mpm/experimental/perchild/perchild.c +++ b/server/mpm/experimental/perchild/perchild.c @@ -569,7 +569,7 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id) ap_create_sb_handle(&sbh, p, conn_id / thread_limit, thread_num); current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id, sbh); if (current_conn) { - ap_process_connection(current_conn); + ap_process_connection(current_conn, sock); 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 b1824f0075..20887377f6 100644 --- a/server/mpm/mpmt_os2/mpmt_os2_child.c +++ b/server/mpm/mpmt_os2/mpmt_os2_child.c @@ -433,7 +433,7 @@ static void worker_main(void *vpArg) current_conn = ap_new_connection(pconn, ap_server_conf, worker_args->conn_sd, conn_id, sbh); if (current_conn) { - ap_process_connection(current_conn); + ap_process_connection(current_conn, worker_args->conn_sd); ap_lingering_close(current_conn); } diff --git a/server/mpm/netware/mpm_netware.c b/server/mpm/netware/mpm_netware.c index 80febdb0d3..77f32cfbe6 100644 --- a/server/mpm/netware/mpm_netware.c +++ b/server/mpm/netware/mpm_netware.c @@ -526,7 +526,7 @@ got_listener: current_conn = ap_new_connection(ptrans, ap_server_conf, csd, my_worker_num, sbh); if (current_conn) { - ap_process_connection(current_conn); + ap_process_connection(current_conn, csd); ap_lingering_close(current_conn); } request_count++; diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c index ddc947f004..fe69695acc 100644 --- a/server/mpm/perchild/perchild.c +++ b/server/mpm/perchild/perchild.c @@ -569,7 +569,7 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id) ap_create_sb_handle(&sbh, p, conn_id / thread_limit, thread_num); current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id, sbh); if (current_conn) { - ap_process_connection(current_conn); + ap_process_connection(current_conn, sock); ap_lingering_close(current_conn); } } diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index b3488a1dee..040afa86a8 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -927,7 +927,7 @@ static void worker_main(int thread_num) thread_num, sbh); if (c) { - ap_process_connection(c); + ap_process_connection(c, context->sock); apr_getsocketopt(context->sock, APR_SO_DISCONNECTED, &disconnected); if (!disconnected) { context->accept_socket = INVALID_SOCKET; diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index fdf9cafa49..52259b56d8 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -559,7 +559,7 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num, current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id, sbh); if (current_conn) { - ap_process_connection(current_conn); + ap_process_connection(current_conn, sock); ap_lingering_close(current_conn); } }