Although the subject claims no MMN bump and the patch doesn't have one, I'm not
sure if that's at all realistic. The patch does compile and it does work, so at
least something is good about it :-)

Give it a whirl, tell me what you think and where do we go from here...

Bojan
diff -ur httpd-2.0-vanilla/include/http_core.h httpd-2.0/include/http_core.h
--- httpd-2.0-vanilla/include/http_core.h       Tue Oct 15 08:12:57 2002
+++ httpd-2.0/include/http_core.h       Tue Oct 22 17:18:15 2002
@@ -61,6 +61,7 @@
 
 #include "apr.h"
 #include "apr_hash.h"
+#include "apr_network_io.h"
 #include "util_filter.h"
 
 #if APR_HAVE_STRUCT_RLIMIT
@@ -576,6 +577,15 @@
 
 #endif
 
+/* Structure for passing on the socket and logging of input/output bytes per
+ * connection and eventually per request. The logging stuff is used in both
+ * core.c and mod_logio.c */
+typedef struct core_conn_conf {
+    apr_socket_t *csd;      /* client socket descriptor */
+    apr_off_t    bytes_in;
+    apr_off_t    bytes_out;
+} core_conn_conf;
+
 
 /* ----------------------------------------------------------------------
  *
diff -ur httpd-2.0-vanilla/modules/http/http_core.c httpd-2.0/modules/http/http_core.c
--- httpd-2.0-vanilla/modules/http/http_core.c  Mon Jul 15 20:14:42 2002
+++ httpd-2.0/modules/http/http_core.c  Tue Oct 22 15:37:54 2002
@@ -305,7 +305,10 @@
             break;
         /* Go straight to select() to wait for the next request */
         if (!csd_set) {
-            csd = ap_get_module_config(c->conn_config, &core_module);
+            core_conn_conf *ccc = ap_get_module_config(c->conn_config,
+                                                       &core_module);
+
+            csd = ccc->csd;
             csd_set = 1;
         }
         apr_socket_opt_set(csd, APR_INCOMPLETE_READ, 1);
diff -ur httpd-2.0-vanilla/modules/loggers/mod_logio.c 
httpd-2.0/modules/loggers/mod_logio.c
--- httpd-2.0-vanilla/modules/loggers/mod_logio.c       Sat Sep 28 14:18:35 2002
+++ httpd-2.0/modules/loggers/mod_logio.c       Tue Oct 22 17:17:43 2002
@@ -79,40 +79,33 @@
 #include "ap_config.h"
 #include "mod_log_config.h"
 #include "httpd.h"
+#include "http_core.h"
 #include "http_config.h"
 #include "http_protocol.h"
 
 module AP_MODULE_DECLARE_DATA logio_module;
+extern module core_module;
 
 static const char logio_filter_name[] = "LOG_INPUT_OUTPUT";
 
 /*
- * Logging of input and output config...
- */
-
-typedef struct logio_config_t {
-    apr_off_t bytes_in;
-    apr_off_t bytes_out;
-} logio_config_t;
-
-/*
  * Format items...
  */
 
 static const char *log_bytes_in(request_rec *r, char *a)
 {
-    logio_config_t *cf = ap_get_module_config(r->connection->conn_config,
-                                              &logio_module);
+    core_conn_conf *ccc = ap_get_module_config(r->connection->conn_config,
+                                               &core_module);
 
-    return apr_off_t_toa(r->pool, cf->bytes_in);
+    return apr_off_t_toa(r->pool, ccc->bytes_in);
 }
 
 static const char *log_bytes_out(request_rec *r, char *a)
 {
-    logio_config_t *cf = ap_get_module_config(r->connection->conn_config,
-                                              &logio_module);
+    core_conn_conf *ccc = ap_get_module_config(r->connection->conn_config,
+                                               &core_module);
 
-    return apr_off_t_toa(r->pool, cf->bytes_out);
+    return apr_off_t_toa(r->pool, ccc->bytes_out);
 }
 
 /*
@@ -121,10 +114,10 @@
 
 static int logio_transaction(request_rec *r)
 {
-    logio_config_t *cf = ap_get_module_config(r->connection->conn_config,
-                                              &logio_module);
+    core_conn_conf *ccc = ap_get_module_config(r->connection->conn_config,
+                                               &core_module);
 
-    cf->bytes_in = cf->bytes_out = 0;
+    ccc->bytes_in = ccc->bytes_out = 0;
 
     return OK;
 }
@@ -133,24 +126,6 @@
  * Logging of input and output filters...
  */
 
-static apr_status_t logio_out_filter(ap_filter_t *f,
-                                     apr_bucket_brigade *bb) {
-    apr_off_t length;
-    logio_config_t *cf = ap_get_module_config(f->c->conn_config, &logio_module);
-
-    if (!cf) { /* Create config */
-        cf = apr_pcalloc(f->c->pool, sizeof(*cf));
-        ap_set_module_config(f->c->conn_config, &logio_module, cf);
-    }
-
-    apr_brigade_length (bb, 0, &length);
-
-    if (length > 0)
-        cf->bytes_out += length;
-
-    return ap_pass_brigade(f->next, bb);
-}
-
 static apr_status_t logio_in_filter(ap_filter_t *f,
                                     apr_bucket_brigade *bb,
                                     ap_input_mode_t mode,
@@ -158,23 +133,33 @@
                                     apr_off_t readbytes) {
     apr_off_t length;
     apr_status_t status;
-    logio_config_t *cf = ap_get_module_config(f->c->conn_config, &logio_module);
+    core_conn_conf *ccc = ap_get_module_config(f->c->conn_config, &core_module);
 
     status = ap_get_brigade(f->next, bb, mode, block, readbytes);
 
-    if (!cf) { /* Create config */
-        cf = apr_pcalloc(f->c->pool, sizeof(*cf));
-        ap_set_module_config(f->c->conn_config, &logio_module, cf);
-    }
-
     apr_brigade_length (bb, 0, &length);
 
     if (length > 0)
-        cf->bytes_in += length;
+        ccc->bytes_in += length;
 
     return status;
 }
 
+static apr_status_t logio_out_filter(ap_filter_t *f,
+                                     apr_bucket_brigade *bb) {
+    apr_bucket *b = APR_BRIGADE_LAST(bb);
+
+    /* End of data, make sure we flush */
+    if (APR_BUCKET_IS_EOS(b)) {
+        APR_BRIGADE_INSERT_TAIL(bb,
+                                apr_bucket_flush_create(f->c->bucket_alloc));
+        APR_BUCKET_REMOVE(b);
+        apr_bucket_destroy(b);
+    }
+
+    return ap_pass_brigade(f->next, bb);
+}
+
 /*
  * The hooks...
  */
diff -ur httpd-2.0-vanilla/modules/proxy/proxy_connect.c 
httpd-2.0/modules/proxy/proxy_connect.c
--- httpd-2.0-vanilla/modules/proxy/proxy_connect.c     Thu Jul 11 20:13:04 2002
+++ httpd-2.0/modules/proxy/proxy_connect.c     Tue Oct 22 15:44:27 2002
@@ -129,7 +129,9 @@
     apr_status_t err, rv;
     apr_size_t i, o, nbytes;
     char buffer[HUGE_STRING_LEN];
-    apr_socket_t *client_socket = ap_get_module_config(r->connection->conn_config, 
&core_module);
+    core_conn_conf *ccc = ap_get_module_config(r->connection->conn_config,
+                                               &core_module);
+    apr_socket_t *client_socket = ccc->csd;
     int failed;
     apr_pollfd_t *pollfd;
     apr_int32_t pollcnt;
diff -ur httpd-2.0-vanilla/modules/proxy/proxy_ftp.c 
httpd-2.0/modules/proxy/proxy_ftp.c
--- httpd-2.0-vanilla/modules/proxy/proxy_ftp.c Mon Aug 19 08:13:53 2002
+++ httpd-2.0/modules/proxy/proxy_ftp.c Tue Oct 22 15:42:01 2002
@@ -829,9 +829,13 @@
         backend->port = 0;
         ap_set_module_config(c->conn_config, &proxy_ftp_module, backend);
     }
-    if (backend->connection)
-        origin_sock = ap_get_module_config(backend->connection->conn_config, 
&core_module);
+    if (backend->connection){
+        core_conn_conf *ccc =
+            ap_get_module_config(backend->connection->conn_config,
+                                 &core_module);
 
+        origin_sock = ccc->csd;
+    }
 
     /*
      * I: Who Do I Connect To? -----------------------
diff -ur httpd-2.0-vanilla/modules/proxy/proxy_http.c 
httpd-2.0/modules/proxy/proxy_http.c
--- httpd-2.0-vanilla/modules/proxy/proxy_http.c        Fri Sep 27 02:12:41 2002
+++ httpd-2.0/modules/proxy/proxy_http.c        Tue Oct 22 15:40:01 2002
@@ -295,7 +295,11 @@
      */
     /* see memory note above */
     if (backend->connection) {
-        client_socket = ap_get_module_config(backend->connection->conn_config, 
&core_module);
+        core_conn_conf *ccc =
+            ap_get_module_config(backend->connection->conn_config,
+                                 &core_module);
+
+        client_socket = ccc->csd;
         if ((backend->connection->id == c->id) &&
             (backend->port == p_conn->port) &&
             (backend->hostname) &&
diff -ur httpd-2.0-vanilla/server/connection.c httpd-2.0/server/connection.c
--- httpd-2.0-vanilla/server/connection.c       Mon Jul 15 20:15:02 2002
+++ httpd-2.0/server/connection.c       Tue Oct 22 16:38:51 2002
@@ -137,7 +137,8 @@
     apr_status_t rc;
     apr_int32_t timeout;
     apr_int32_t total_linger_time = 0;
-    apr_socket_t *csd = ap_get_module_config(c->conn_config, &core_module);
+    core_conn_conf *ccc = ap_get_module_config(c->conn_config, &core_module);
+    apr_socket_t *csd = ccc->csd;
 
     if (!csd) {
         return;
diff -ur httpd-2.0-vanilla/server/core.c httpd-2.0/server/core.c
--- httpd-2.0-vanilla/server/core.c     Tue Oct 15 08:12:59 2002
+++ httpd-2.0/server/core.c     Tue Oct 22 16:46:01 2002
@@ -2737,6 +2737,7 @@
                                     apr_off_t   file_offset,
                                     apr_size_t  file_bytes_left,
                                     apr_size_t  total_bytes_left,
+                                    apr_size_t  *bytes_sent,
                                     apr_int32_t flags)
 {
     apr_status_t rv;
@@ -2748,11 +2749,15 @@
                          == APR_SUCCESS)
                     && timeout > 0);  /* socket must be in timeout mode */
 
+    /* Reset the bytes_sent field */
+    *bytes_sent = 0;
+
     do {
         apr_size_t tmplen = file_bytes_left;
 
         rv = apr_sendfile(c->client_socket, fd, hdtr, &file_offset, &tmplen,
                           flags);
+        *bytes_sent += tmplen;
         total_bytes_left -= tmplen;
         if (!total_bytes_left || rv != APR_SUCCESS) {
             return rv;        /* normal case & error exit */
@@ -3395,7 +3400,8 @@
                            apr_off_t readbytes)
 {
     int keptalive = f->c->keepalive == AP_CONN_KEEPALIVE;
-    apr_socket_t *csd = ap_get_module_config(f->c->conn_config, &core_module);
+    core_conn_conf *ccc = ap_get_module_config(f->c->conn_config, &core_module);
+    apr_socket_t *csd = ccc->csd;
     int *first_line = f->ctx;
 
     if (!f->ctx) {
@@ -3908,6 +3914,9 @@
 
         if (fd) {
             apr_hdtr_t hdtr;
+            apr_size_t bytes_sent;
+            core_conn_conf *ccc = ap_get_module_config(c->conn_config,
+                                                       &core_module);
 #if APR_HAS_SENDFILE
             apr_int32_t flags = 0;
 #endif
@@ -3938,25 +3947,37 @@
                                                   sending from              */
                                      flen,     /* length of file            */
                                      nbytes + flen, /* total length including
-                                                       headers                */
+                                                       headers              */
+                                     &bytes_sent,   /* how many bytes were
+                                                       sent                 */
                                      flags);   /* apr_sendfile flags        */
+
+                if (bytes_sent > 0)
+                    ccc->bytes_out += bytes_sent;
             }
             else
 #endif
             {
-                apr_size_t unused_bytes_sent;
                 rv = emulate_sendfile(net, fd, &hdtr, foffset, flen,
-                                      &unused_bytes_sent);
+                                      &bytes_sent);
+
+                if (bytes_sent > 0)
+                    ccc->bytes_out += bytes_sent;
             }
 
             fd = NULL;
         }
         else {
-            apr_size_t unused_bytes_sent;
+            apr_size_t bytes_sent;
+            core_conn_conf *ccc = ap_get_module_config(c->conn_config,
+                                                       &core_module);
 
             rv = writev_it_all(net->client_socket,
                                vec, nvec,
-                               nbytes, &unused_bytes_sent);
+                               nbytes, &bytes_sent);
+
+            if (bytes_sent > 0)
+                ccc->bytes_out += bytes_sent;
         }
 
         apr_brigade_destroy(b);
@@ -4135,6 +4156,7 @@
 static int core_pre_connection(conn_rec *c, void *csd)
 {
     core_net_rec *net = apr_palloc(c->pool, sizeof(*net));
+    core_conn_conf *ccc = apr_pcalloc(c->pool, sizeof(*ccc));
 
 #ifdef AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
     /* BillS says perhaps this should be moved to the MPMs. Some OSes
@@ -4149,7 +4171,9 @@
     net->out_ctx = NULL;
     net->client_socket = csd;
 
-    ap_set_module_config(net->c->conn_config, &core_module, csd);
+    ccc->csd = csd;
+
+    ap_set_module_config(net->c->conn_config, &core_module, ccc);
     ap_add_input_filter_handle(ap_core_input_filter_handle, net, NULL, net->c);
     ap_add_output_filter_handle(ap_core_output_filter_handle, net, NULL, net->c);
     return DONE;
diff -ur httpd-2.0-vanilla/server/mpm/experimental/perchild/perchild.c 
httpd-2.0/server/mpm/experimental/perchild/perchild.c
--- httpd-2.0-vanilla/server/mpm/experimental/perchild/perchild.c       Sat Oct 12 
02:12:30 2002
+++ httpd-2.0/server/mpm/experimental/perchild/perchild.c       Tue Oct 22 16:46:27 
+2002
@@ -1626,7 +1626,9 @@
 static int pass_request(request_rec *r)
 {
     int rv;
-    apr_socket_t *thesock = ap_get_module_config(r->connection->conn_config, 
&core_module);
+    core_conn_conf *ccc = ap_get_module_config(r->connection->conn_config,
+                                               &core_module);
+    apr_socket_t *thesock = ccc->csd;
     struct msghdr msg;
     struct cmsghdr *cmsg;
     int sfd;
@@ -1770,11 +1772,15 @@
 
     if (thread_socket_table[thread_num] != AP_PERCHILD_THISCHILD) {
         apr_socket_t *csd = NULL;
+        core_conn_conf *ccc = apr_pcalloc(r->connection->pool, sizeof(*ccc));
 
         apr_os_sock_put(&csd, &thread_socket_table[thread_num], 
                         r->connection->pool);
         ap_sock_disable_nagle(csd);
-        ap_set_module_config(r->connection->conn_config, &core_module, csd);
+
+        ccc->csd = csd;
+
+        ap_set_module_config(r->connection->conn_config, &core_module, ccc);
         return OK;
     }
     else {

Reply via email to