Most, if not all, of you have seen the multi-protocol patch that used to
be posted at klomp.covalent.net:8080/.  That web site will be back up as
soon as we can do it.  Covalent has recently moved(needed more space), and
that web site was a casualty until things settle down.  Should be
sometime tomorrow.  In the mean-time, I have begun to split the patch into
managable pieces.  This post is the first part of that work.

What this post basically does, is it breaks part of the conn_rec out and
into an HTTP specific structure.  I am not saying that this is everything
that can be pulled out of the conn_rec, but it is a good first step.

Comments?

Ryan

Index: include/httpd.h
===================================================================
RCS file: /home/cvs/httpd-2.0/include/httpd.h,v
retrieving revision 1.146
diff -u -d -b -w -u -r1.146 httpd.h
--- include/httpd.h     2001/04/16 20:33:16     1.146
+++ include/httpd.h     2001/04/17 03:53:21
@@ -860,14 +860,10 @@
     unsigned aborted:1;
     /** Are we using HTTP Keep-Alive?  -1 fatal error, 0 undecided, 1 yes */
     signed int keepalive:2;
-    /** Did we use HTTP Keep-Alive? */
-    unsigned keptalive:1;
     /** have we done double-reverse DNS? -1 yes/failure, 0 not yet,
      *  1 yes/success */
     signed int double_reverse:2;

-    /** How many times have we used it? */
-    int keepalives;
     /** server IP address */
     char *local_ip;
     /** used for ap_get_server_name when UseCanonicalName is set to DNS
Index: modules/http/config.m4
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/http/config.m4,v
retrieving revision 1.4
diff -u -d -b -w -u -r1.4 config.m4
--- modules/http/config.m4      2001/03/04 06:27:27     1.4
+++ modules/http/config.m4      2001/04/17 03:53:22
@@ -7,5 +7,8 @@
 APACHE_MODULE(http, HTTP protocol handling, $http_objects, , yes)
 APACHE_MODULE(mime, mapping of file-extension to MIME, , , yes)

+if test "$enable_http" = "yes"; then
+  AC_DEFINE(AP_HTTP_ENABLED, 1, [HTTP is enabled on this server])
+fi

 APACHE_MODPATH_FINISH
Index: modules/http/http_core.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/http/http_core.c,v
retrieving revision 1.270
diff -u -d -b -w -u -r1.270 http_core.c
--- modules/http/http_core.c    2001/04/11 23:37:16     1.270
+++ modules/http/http_core.c    2001/04/17 03:53:22
@@ -295,6 +295,35 @@
     return OK;
 }

+static int http_create_request(request_rec *r)
+{
+    http_conn_rec *conn = ap_get_module_config(r->connection->conn_config, 
+&http_module);
+
+    conn = apr_palloc(r->pool, sizeof(*conn));
+    ap_set_module_config(r->connection->conn_config, &http_module, conn);
+
+    if (!r->main && !(r->prev || r->next)) {
+        conn->keptalive = r->connection->keepalive == 1;
+        r->connection->keepalive    = 0;
+
+        apr_setsocketopt(r->connection->client_socket, APR_SO_TIMEOUT,
+                         (int)(conn->keptalive
+                         ? r->server->keep_alive_timeout * APR_USEC_PER_SEC
+                         : r->server->timeout * APR_USEC_PER_SEC));
+
+        if (conn->keptalive) {
+            apr_setsocketopt(r->connection->client_socket,
+                             APR_SO_TIMEOUT,
+                             (int)(r->server->timeout * APR_USEC_PER_SEC));
+        }
+
+        conn->keptalive = 0;
+
+        return OK;
+    }
+    return OK;
+}
+
 static void register_hooks(apr_pool_t *p)
 {
     ap_hook_pre_connection(ap_pre_http_connection,NULL,NULL,
@@ -303,6 +332,7 @@
                               APR_HOOK_REALLY_LAST);
     ap_hook_http_method(http_method,NULL,NULL,APR_HOOK_REALLY_LAST);
     ap_hook_default_port(http_port,NULL,NULL,APR_HOOK_REALLY_LAST);
+    ap_hook_create_request(http_create_request, NULL, NULL, APR_HOOK_MIDDLE);

     ap_register_input_filter("HTTP_IN", ap_http_filter, AP_FTYPE_CONNECTION);
     ap_register_input_filter("DECHUNK", ap_dechunk_filter, AP_FTYPE_TRANSCODE);
Index: modules/http/http_protocol.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/http/http_protocol.c,v
retrieving revision 1.313
diff -u -d -b -w -u -r1.313 http_protocol.c
--- modules/http/http_protocol.c        2001/04/16 21:16:53     1.313
+++ modules/http/http_protocol.c        2001/04/17 03:53:23
@@ -105,6 +105,7 @@
     int ka_sent = 0;
     int wimpy = ap_find_token(r->pool,
                            apr_table_get(r->headers_out, "Connection"), "close");
+    http_conn_rec *hconn = ap_get_module_config(r->connection->conn_config, 
+&http_module);
     const char *conn = apr_table_get(r->headers_in, "Connection");

     /* The following convoluted conditional determines whether or not
@@ -146,7 +147,7 @@
         && r->server->keep_alive
        && (r->server->keep_alive_timeout > 0)
        && ((r->server->keep_alive_max == 0)
-           || (r->server->keep_alive_max > r->connection->keepalives))
+           || (r->server->keep_alive_max > hconn->keepalives))
        && !ap_status_drops_connection(r->status)
        && !wimpy
        && !ap_find_token(r->pool, conn, "close")
@@ -154,10 +155,10 @@
            || apr_table_get(r->headers_in, "Via"))
        && ((ka_sent = ap_find_token(r->pool, conn, "keep-alive"))
            || (r->proto_num >= HTTP_VERSION(1,1)))) {
-        int left = r->server->keep_alive_max - r->connection->keepalives;
+        int left = r->server->keep_alive_max - hconn->keepalives;

         r->connection->keepalive = 1;
-        r->connection->keepalives++;
+        hconn->keepalives++;

         /* If they sent a Keep-Alive token, send one back */
         if (ka_sent) {
Index: modules/http/mod_core.h
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/http/mod_core.h,v
retrieving revision 1.6
diff -u -d -b -w -u -r1.6 mod_core.h
--- modules/http/mod_core.h     2001/02/28 15:24:07     1.6
+++ modules/http/mod_core.h     2001/04/17 03:53:23
@@ -70,6 +70,15 @@
  * @package mod_core private header file
  */

+typedef struct http_conn_rec http_conn_rec;
+
+struct http_conn_rec {
+    /** Did we use HTTP Keep-Alive? */
+    unsigned keptalive:1;
+    /** How many times have we used it? */
+    int keepalives;
+};
+
 /*
  * These (input) filters are internal to the mod_core operation.
  */
@@ -91,6 +100,8 @@

 AP_DECLARE(int) ap_send_http_trace(request_rec *r);
 int ap_send_http_options(request_rec *r);
+
+AP_DECLARE_DATA module http_module;

 #ifdef __cplusplus
 }
Index: modules/loggers/mod_log_config.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/loggers/mod_log_config.c,v
retrieving revision 1.52
diff -u -d -b -w -u -r1.52 mod_log_config.c
--- modules/loggers/mod_log_config.c    2001/03/09 20:30:32     1.52
+++ modules/loggers/mod_log_config.c    2001/04/17 03:53:23
@@ -191,6 +191,7 @@
 #include "http_core.h"          /* For REMOTE_NAME */
 #include "http_log.h"
 #include "http_protocol.h"
+#include "mod_core.h"

 #if APR_HAVE_UNISTD_H
 #include <unistd.h>
@@ -527,13 +528,19 @@
 }
 static const char *log_connection_status(request_rec *r, char *a)
 {
+#ifdef AP_HTTP_ENABLED
+    http_conn_rec *hconn = ap_get_module_config(r->connection->conn_config,
+                                                &http_module);
+#endif
     if (r->connection->aborted)
         return "X";

+#ifdef AP_HTTP_ENABLED
     if ((r->connection->keepalive) &&
-        ((r->server->keep_alive_max - r->connection->keepalives) > 0)) {
+        ((r->server->keep_alive_max - hconn->keepalives) > 0)) {
         return "+";
     }
+#endif

     return "-";
 }
Index: server/protocol.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/protocol.c,v
retrieving revision 1.12
diff -u -d -b -w -u -r1.12 protocol.c
--- server/protocol.c   2001/04/11 23:37:16     1.12
+++ server/protocol.c   2001/04/17 03:53:26
@@ -556,9 +556,6 @@
     r->connection      = conn;
     r->server          = conn->base_server;

-    conn->keptalive    = conn->keepalive == 1;
-    conn->keepalive    = 0;
-
     r->user            = NULL;
     r->ap_auth_type    = NULL;

@@ -584,11 +581,6 @@
     r->output_filters  = conn->output_filters;
     r->input_filters   = conn->input_filters;

-    apr_setsocketopt(conn->client_socket, APR_SO_TIMEOUT,
-                     (int)(conn->keptalive
-                     ? r->server->keep_alive_timeout * APR_USEC_PER_SEC
-                     : r->server->timeout * APR_USEC_PER_SEC));
-
     ap_add_output_filter("BYTERANGE", NULL, r, r->connection);
     ap_add_output_filter("CONTENT_LENGTH", NULL, r, r->connection);
     ap_add_output_filter("HTTP_HEADER", NULL, r, r->connection);
@@ -604,10 +596,6 @@
         }
         return NULL;
     }
-    if (r->connection->keptalive) {
-        apr_setsocketopt(r->connection->client_socket, APR_SO_TIMEOUT,
-                         (int)(r->server->timeout * APR_USEC_PER_SEC));
-    }
     if (!r->assbackwards) {
         get_mime_headers(r);
         if (r->status != HTTP_REQUEST_TIME_OUT) {
@@ -645,8 +633,6 @@

     /* we may have switched to another server */
     r->per_dir_config = r->server->lookup_defaults;
-
-    conn->keptalive = 0;        /* We now have a request to play with */

     if ((!r->hostname && (r->proto_num >= HTTP_VERSION(1,1))) ||
         ((r->proto_num == HTTP_VERSION(1,1)) &&


Reply via email to