]> granicus.if.org Git - apache/commitdiff
This patch restores most of Ryan's patch (11/12/2001) to remove the
authorBill Stoddard <stoddard@apache.org>
Tue, 29 Jan 2002 19:02:04 +0000 (19:02 +0000)
committerBill Stoddard <stoddard@apache.org>
Tue, 29 Jan 2002 19:02:04 +0000 (19:02 +0000)
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

12 files changed:
include/http_connection.h
include/httpd.h
modules/http/http_core.c
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/winnt/mpm_winnt.c
server/mpm/worker/worker.c

index 5cbcb86cd950833a223be44246734668147c6081..02cb5555b5a5c9e03b5e26438c08a6c7b256c8e8 100644 (file)
@@ -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
index ed0c332e27d31f20911dc695562280eda15c905d..800ea082ec0ea2e481427277dce00e0b2f14be52 100644 (file)
@@ -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
index 64a58d39b08943b79d5da8146fdfac6daeca9b7a..c8659ae6aed9fb621c63e06d2623a27d4d9d6c3b 100644 (file)
@@ -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);
index d812bd4d1c6df967d174c39e35df42bac4fb21d8..52ce3e97ab307432dad3b0f7712e4ea774cab57a 100644 (file)
 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;
 }
index 1cdfbfe4c4714c277e5123aa1656ae4f85e09d99..0fbf99a3fe36edcbb91e41610b0b9b674d46b62f 100644 (file)
@@ -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);
index b618e364af49151e1c128d2382d244bc37a73995..1f6d0154180e6707af6c9da0a819d861516aac6b 100644 (file)
@@ -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);
     }
 }
index ddc947f004df7edd141fe5fa359571e45a0611fd..fe69695acc202c568b774c4bbac157395ece47d5 100644 (file)
@@ -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);
     }
 }
index b1824f00753a0c6070b87523b2dc0bb37accc022..20887377f6d146f36f261b8d24eb792393c4a9d6 100644 (file)
@@ -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);
         }
 
index 80febdb0d325cce8b03794e6c0072185f6b347b1..77f32cfbe6f77a0e9ec82efb01614d705dadf15c 100644 (file)
@@ -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++;
index ddc947f004df7edd141fe5fa359571e45a0611fd..fe69695acc202c568b774c4bbac157395ece47d5 100644 (file)
@@ -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);
     }
 }
index b3488a1dee7609600c0776249f808550126addc7..040afa86a8313a3b093af36917f002e32311df53 100644 (file)
@@ -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;
index fdf9cafa495aa5e1b4a345368e065af28f315605..52259b56d8b25bfad6ccd35c094d942b7067465c 100644 (file)
@@ -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);
     }
 }