You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by rb...@covalent.net on 2000/06/16 00:52:53 UTC

Filter I/O take 3.

This patch enable filtering output.  I have not implemented input
filtering, because I believe it is trivial once we have the output
done.

Issues resolved:
     Grouping filters by type
     allocating space on the stack or heap as appropriate
     memcpy'ing data that is never modified (not done anymore)
     Send headers after filters have sent the first block of data.

Issues not resolved:
     Negative pushback from the network (there is a comment in the code
for how to implement this)
     Filters that only deal with half the data.  (the basic idea is there,
but it is not well tested.  Still working on this).
     cleanup the code:  some stuff just commented out until it can be
tested better.
     insert ap_run_insert_filters for sub_requests???  I'm not sure about
this.  Maybe we just want to inherit these.
     Others?  I know there are others, but I can't think of them right
now.


Patch
_____

Index: src/include/ap_hooks.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/ap_hooks.h,v
retrieving revision 1.20
diff -u -d -b -w -u -r1.20 ap_hooks.h
--- src/include/ap_hooks.h	2000/05/27 22:53:46	1.20
+++ src/include/ap_hooks.h	2000/06/15 22:43:33
@@ -167,12 +167,153 @@
     return decline; \
     }
 
+/* Set of Hook definitions designed to put the list of functions off a
+ * pointer pre-defined in the request_rec.
+ */
+#define AP_DECLARE_RHOOK(ret,name,args) \
+typedef ret HOOK_##name args; \
+API_EXPORT(void) ap_rhook_##name(HOOK_##name *pf,request_rec *r, \
+                                 const char * const *aszPre,\
+		                 const char * const *aszSucc,int nOrder); \
+API_EXPORT(ret) ap_run_##name args; \
+typedef struct _LINK_##name \
+    { \
+    HOOK_##name *pFunc; \
+    const char *szName; \
+    const char * const *aszPredecessors; \
+    const char * const *aszSuccessors; \
+    int nOrder; \
+    } LINK_##name;
+
+#define AP_RHOOK_STRUCT(members) \
+struct { members } _hooks;
+
+#define AP_RHOOK_LINK(name) \
+    ap_array_header_t *link_##name;
+
+#define AP_IMPLEMENT_RHOOK_BASE(name) \
+API_EXPORT(void) ap_rhook_##name(HOOK_##name *pf,request_rec *r, \
+                                 const char * const *aszPre,\
+		                 const char * const *aszSucc,int nOrder) \
+    { \
+    LINK_##name *pHook; \
+    if(!r->_hooks.link_##name) \
+	{ \
+	r->_hooks.link_##name=ap_make_array(r->pool,1,sizeof(LINK_##name)); \
+	ap_hook_sort_register(#name,&r->_hooks.link_##name); \
+	} \
+    pHook=ap_push_array(r->_hooks.link_##name); \
+    pHook->pFunc=pf; \
+    pHook->aszPredecessors=aszPre; \
+    pHook->aszSuccessors=aszSucc; \
+    pHook->nOrder=nOrder; \
+    pHook->szName=ap_debug_module_name; \
+    if(ap_debug_module_hooks) \
+	ap_show_hook(#name,aszPre,aszSucc); \
+    }
+
+/* RUN_ALL runs to the first one to return other than ok or decline
+   RUN_FIRST runs to the first one to return other than decline
+   VOID runs all
+*/
+
+#define AP_IMPLEMENT_RHOOK_VOID(name,args_decl,args_use) \
+AP_IMPLEMENT_RHOOK_BASE(name) \
+API_EXPORT(void) ap_run_##name args_decl \
+    { \
+    LINK_##name *pHook; \
+    int n; \
+\
+    if(!r->_hooks.link_##name) \
+	return; \
+\
+    pHook=(LINK_##name *)r->_hooks.link_##name->elts; \
+    for(n=0 ; n < r->_hooks.link_##name->nelts ; ++n) \
+	pHook[n].pFunc args_use; \
+    }
+
+/* FIXME: note that this returns ok when nothing is run. I suspect it should
+   really return decline, but that breaks Apache currently - Ben
+*/
+#define AP_IMPLEMENT_RHOOK_RUN_ALL(ret,name,args_decl,args_use,ok,decline) \
+AP_IMPLEMENT_RHOOK_BASE(name) \
+API_EXPORT(ret) ap_run_##name args_decl \
+    { \
+    LINK_##name *pHook; \
+    int n; \
+    ret rv; \
+\
+    if(!r->_hooks.link_##name) \
+	return ok; \
+\
+    pHook=(LINK_##name *)r->_hooks.link_##name->elts; \
+    for(n=0 ; n < r->_hooks.link_##name->nelts ; ++n) \
+	{ \
+	rv=pHook[n].pFunc args_use; \
+\
+	if(rv != ok && rv != decline) \
+	    return rv; \
+	} \
+    return ok; \
+    }
+
+#define AP_IMPLEMENT_RHOOK_RUN_FIRST(ret,name,args_decl,args_use,decline) \
+AP_IMPLEMENT_RHOOK_BASE(name) \
+API_EXPORT(ret) ap_run_##name args_decl \
+    { \
+    LINK_##name *pHook; \
+    int n; \
+    ret rv; \
+\
+    if(!r->_hooks.link_##name) \
+	return decline; \
+\
+    pHook=(LINK_##name *)r->_hooks.link_##name->elts; \
+    for(n=0 ; n < r->_hooks.link_##name->nelts ; ++n) \
+	{ \
+	rv=pHook[n].pFunc args_use; \
+\
+	if(rv != decline) \
+	    return rv; \
+	} \
+    return decline; \
+    }
+
      /* Hook orderings */
 #define AP_HOOK_REALLY_FIRST	(-10)
 #define AP_HOOK_FIRST		0
 #define AP_HOOK_MIDDLE		10
 #define AP_HOOK_LAST		20
 #define AP_HOOK_REALLY_LAST	30
+
+/* I'm not sure if this is the right place for this or not, but it's a good
+ * starting point.  This is the filter hooks ordering definitions.
+ * The five classes are:
+ *
+ *    content-generators:   
+ *        These are ignored here, because all generators are implemented 
+ *        using handlers.
+ *    content-filter/munger/processor:
+ *        These are things like SSI, PHP, etc.  Anything that is likely
+ *        to change the meaning of the data being sent.
+ *    content-encoding:
+ *        Something like gzip would go here.  Anything that changes the data,
+ *        but not the meaning.
+ *    digest/message processor:
+ *        This would be something like mod_auth_digest.  Anything that
+ *        changes header fields but not the content.
+ *    transport encoding:
+ *        This is where chuncking, SSL belong.  Anything that modifies the
+ *        message for reasons related to the transport layer, but doesn't
+ *        modify the meaning of the body.
+ * 
+ * These filter types are called in the order the are listed above.
+ */
+
+#define AP_HOOK_FILTER          0      /* content-filter/munger/processor */
+#define AP_HOOK_ENCODING       10      /* content-encoding */
+#define AP_HOOK_PROCESSOR      20      /* digest/message processor */
+#define AP_HOOK_TRANSPORT      30      /* transport-encoding */
 
 extern API_VAR_EXPORT ap_pool_t *ap_global_hook_pool;
 extern API_VAR_EXPORT int ap_debug_module_hooks;
Index: src/include/http_request.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/http_request.h,v
retrieving revision 1.11
diff -u -d -b -w -u -r1.11 http_request.h
--- src/include/http_request.h	2000/05/27 22:53:47	1.11
+++ src/include/http_request.h	2000/06/15 22:43:34
@@ -120,6 +120,7 @@
 AP_DECLARE_HOOK(int,type_checker,(request_rec *))
 AP_DECLARE_HOOK(int,access_checker,(request_rec *))
 AP_DECLARE_HOOK(int,auth_checker,(request_rec *))
+AP_DECLARE_HOOK(void,insert_filter,(request_rec *))
 
 #ifdef __cplusplus
 }
Index: src/include/httpd.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/httpd.h,v
retrieving revision 1.56
diff -u -d -b -w -u -r1.56 httpd.h
--- src/include/httpd.h	2000/06/09 21:19:47	1.56
+++ src/include/httpd.h	2000/06/15 22:43:44
@@ -81,6 +81,8 @@
 #include "apr_network_io.h"
 #include "buff.h"
 #include "ap_mmn.h"
+#include "ap_hooks.h"
+#include "ap_ioblock.h"
 
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
@@ -598,6 +600,8 @@
     const char *short_name;
 };
 
+AP_DECLARE_RHOOK(ap_ioqueue_t *, filter, (request_rec *r, ap_ioqueue_t *strs));
+
 struct request_rec {
 
     ap_pool_t *pool;
@@ -615,6 +619,12 @@
 				 * pointer back to the main request.
 				 */
 
+    AP_RHOOK_STRUCT (
+        AP_RHOOK_LINK(filter)   /* per-request filter I/O hook. */
+    );
+    ap_ioqueue_t **unfiltered_data;	/* array of (ap_ioqueue_t *) that has
+                                         * not been filtered for */
+
     /* Info about the request itself... we begin with stuff that only
      * protocol.c should ever touch...
      */
@@ -662,6 +672,7 @@
     */
     int allowed;		/* Allowed methods - for 405, OPTIONS, etc */
 
+    int headers_sent;           /* have the headers been sent yet or not */
     int sent_bodyct;		/* byte count in stream is for body */
     long bytes_sent;		/* body byte count, for easy access */
     ap_time_t mtime;		/* Time the resource was last modified */
Index: src/main/Makefile.in
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/Makefile.in,v
retrieving revision 1.12
diff -u -d -b -w -u -r1.12 Makefile.in
--- src/main/Makefile.in	2000/06/11 11:20:58	1.12
+++ src/main/Makefile.in	2000/06/15 22:43:50
@@ -8,7 +8,7 @@
 	http_protocol.c http_request.c http_vhost.c util.c util_date.c \
 	util_script.c util_uri.c util_md5.c util_cfgtree.c util_ebcdic.c \
 	rfc1413.c http_connection.c iol_file.c listen.c mpm_common.c \
-	util_charset.c
+	util_charset.c ap_ioblock.c
 
 include $(top_srcdir)/build/ltlib.mk
 
Index: src/main/http_core.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_core.c,v
retrieving revision 1.74
diff -u -d -b -w -u -r1.74 http_core.c
--- src/main/http_core.c	2000/06/15 13:42:01	1.74
+++ src/main/http_core.c	2000/06/15 22:43:54
@@ -2628,8 +2628,8 @@
 
 	rangestatus = ap_set_byterange(r);
 
-	ap_send_http_header(r);
-	
+/*	ap_send_http_header(r);
+*/	
 	if (!r->header_only) {
 	    if (!rangestatus) {
 		ap_send_fd(fd, r);
@@ -2671,8 +2671,8 @@
 	}
 
 	rangestatus = ap_set_byterange(r);
-	ap_send_http_header(r);
-	
+	/*ap_send_http_header(r);
+	*/
 	if (!r->header_only) {
 	    if (!rangestatus) {
 		ap_send_mmap(mm, r, 0, r->finfo.size);
Index: src/main/http_protocol.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v
retrieving revision 1.79
diff -u -d -b -w -u -r1.79 http_protocol.c
--- src/main/http_protocol.c	2000/06/12 23:02:49	1.79
+++ src/main/http_protocol.c	2000/06/15 22:44:05
@@ -96,6 +96,86 @@
           ap_bgetopt (r->connection->client, BO_BYTECT, &r->bytes_sent); \
   } while (0)
 
+static int filter_io(request_rec *r, ap_ioqueue_t *iov)
+{
+    ap_ioblock_t *dptr = iov->head;
+    ap_ioqueue_t *unfiltered;
+#if 0
+    /* see below */
+    ap_size_t totlen = 0;
+#endif
+    int i, n;
+    int totsent = 0;
+    int rv;
+    int num_filters = r->_hooks.link_filter->nelts;
+
+    /* This should probably be done someplace else, but this will work for now.
+     */
+    if (r->unfiltered_data == NULL) {
+        r->unfiltered_data = ap_pcalloc(r->pool, num_filters * 
+                                           sizeof(ap_ioqueue_t *));
+    }
+    
+    for (i = 0; i < r->_hooks.link_filter->nelts; ++i) {
+        LINK_filter *hook;
+#if 0
+    /* Limit the amount of data sent to filters.  This logic needs to ensure
+     * we don't send too little or too much information.  I expect this will
+     * be added in the not too distant future.  Like days after the original
+     * filtered I/O patch.   rbb
+     */
+        while (dptr != iov->tail && (totlen < MAX_STRING_LEN)) {
+            totlen += dptr->len;
+            dptr = dptr->next;
+        }
+#endif
+
+        if (r->unfiltered_data[i] != NULL) {
+            ap_ioqueue_merge(r->unfiltered_data[i], iov);
+            iov = r->unfiltered_data[i];
+            r->unfiltered_data[i] = NULL;
+        }    
+
+        hook = (LINK_filter *)r->_hooks.link_filter->elts;
+        unfiltered = hook[i].pFunc(r, iov);
+
+        /* unfiltered is the data that the filter didn't modify for one reason
+         * or another.  This has not been tested, but the theory is sound.
+         * I'll test this after I send the patch.  I expect to have this fully
+         * tested either before the commit or just after.
+         */
+        if (unfiltered != NULL) {
+            r->unfiltered_data[i] = unfiltered;
+        }
+    }
+
+    dptr = iov->head;
+
+    if (r->headers_sent != 1) {
+        /* We haven't sent any headers yet.  We had better do that before
+         * we try to send the body.
+         */
+        ap_send_http_header(r);
+    }
+
+    while (dptr != NULL) {
+        rv = ap_bwrite(r->connection->client, dptr->vec, dptr->len, &n);
+        if (n < 0) {
+            if (!r->connection->aborted) {
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
+                    "client stopped connection before rwrite completed");
+                ap_bsetflag(r->connection->client, B_EOUT, 1);
+                r->connection->aborted = 1;
+            }
+            return EOF;
+        }
+        totsent += n;
+        dptr = dptr->next;
+    }
+    SET_BYTES_SENT(r);
+    return totsent;
+}
+
 /*
  * Builds the content-type that should be sent to the client from the
  * content-type specified.  The following rules are followed:
@@ -1394,7 +1474,8 @@
 API_EXPORT_NONSTD(int) ap_send_header_field(request_rec *r,
     const char *fieldname, const char *fieldval)
 {
-    return (0 < ap_rvputs(r, fieldname, ": ", fieldval, CRLF, NULL));
+    return (0 < ap_bvputs(r->connection->client, fieldname, ": ", fieldval, 
+                          CRLF, NULL));
 }
 
 API_EXPORT(void) ap_basic_http_header(request_rec *r)
@@ -1428,7 +1509,7 @@
 
     /* Output the HTTP/1.x Status-Line and the Date and Server fields */
 
-    ap_rvputs(r, protocol, " ", r->status_line, CRLF, NULL);
+    ap_bvputs(r->connection->client, protocol, " ", r->status_line, CRLF, NULL);
 
     date = ap_palloc(r->pool, AP_RFC822_DATE_LEN);
     ap_rfc822_date(date, r->request_time);
@@ -1465,9 +1546,9 @@
 
     ap_bgetopt(r->connection->client, BO_BYTECT, &bs);
     if (bs >= 255 && bs <= 257)
-        ap_rputs("X-Pad: avoid browser bug" CRLF, r);
+        ap_bputs("X-Pad: avoid browser bug" CRLF, r->connection->client);
 
-    ap_rputs(CRLF, r);  /* Send the terminating empty line */
+    ap_bputs(CRLF, r->connection->client); /* Send the terminating empty line */
 }
 
 /* Build the Allow field-value from the request handler method mask.
@@ -1734,6 +1815,10 @@
              (void *) r, r->headers_out, NULL);
 
     terminate_header(r);
+    /* We have sent the headers once, we don't ever want to try to send them
+     * again.
+     */
+    r->headers_sent = 1;
 
 
     ap_bsetopt(r->connection->client, BO_BYTECT, &zero);
@@ -2216,7 +2301,7 @@
         o = 0;
 
         while (n && !ap_is_aborted(r->connection)) {
-            rv = ap_bwrite(r->connection->client, &buf[o], n, &w);
+            w = ap_rwrite(&buf[o], n, r);
             if (w > 0) {
                 total_bytes_sent += w;
                 n -= w;
@@ -2347,13 +2432,11 @@
     size_t total_bytes_sent = 0;
     int n;
     ap_ssize_t w;
-    ap_status_t rv;
     char *addr;
     
     if (length == 0)
         return 0;
 
-
     length += offset;
     while (!r->connection->aborted && offset < length) {
         if (length - offset > MMAP_SEGMENT_SIZE) {
@@ -2365,25 +2448,12 @@
 
         while (n && !r->connection->aborted) {
             ap_mmap_offset((void**)&addr, mm, offset);
-            rv = ap_bwrite(r->connection->client, addr, n, &w);
+            w = ap_rwrite(addr, n, r);
             if (w > 0) {
                 total_bytes_sent += w;
                 n -= w;
                 offset += w;
             }
-            else if (rv != APR_SUCCESS) {
-                if (r->connection->aborted)
-                    break;
-                else if (ap_canonical_error(rv) == APR_EAGAIN)
-                    continue;
-                else {
-                    ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
-                     "client stopped connection before send mmap completed");
-                    ap_bsetflag(r->connection->client, B_EOUT, 1);
-                    r->connection->aborted = 1;
-                    break;
-                }
-            }
         }
     }
 
@@ -2397,6 +2467,8 @@
     if (r->connection->aborted)
         return EOF;
 
+    filter_io(r, ap_create_ioqueue(r->pool, (const char *)&c, 1));
+
     if (ap_bputc(c, r->connection->client) < 0) {
         if (!r->connection->aborted) {
             ap_log_rerror(APLOG_MARK, APLOG_INFO,
@@ -2414,10 +2486,14 @@
 API_EXPORT(int) ap_rputs(const char *str, request_rec *r)
 {
     int rcode;
+    int len;
 
     if (r->connection->aborted)
         return EOF;
     
+    len = strlen(str);
+    filter_io(r, ap_create_ioqueue(r->pool, str, len));
+
     rcode = ap_bputs(str, r->connection->client);
     if (rcode < 0) {
         if (!r->connection->aborted) {
@@ -2435,73 +2511,40 @@
 
 API_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r)
 {
-    ap_ssize_t n;
-    ap_status_t rv;
-
     if (r->connection->aborted)
         return EOF;
 
-    rv = ap_bwrite(r->connection->client, buf, nbyte, &n);
-    if (n < 0) {
-        if (!r->connection->aborted) {
-            ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
-                "client stopped connection before rwrite completed");
-            ap_bsetflag(r->connection->client, B_EOUT, 1);
-            r->connection->aborted = 1;
-        }
-        return EOF;
-    }
-    SET_BYTES_SENT(r);
-    return n;
+    return filter_io(r, ap_create_ioqueue(r->pool, buf, nbyte));
 }
 
 API_EXPORT(int) ap_vrprintf(request_rec *r, const char *fmt, va_list ap)
 {
-    int n;
+    int len;
+    char *str;
 
     if (r->connection->aborted)
         return -1;
-
-    n = ap_vbprintf(r->connection->client, fmt, ap);
 
-    if (n < 0) {
-        if (!r->connection->aborted) {
-            ap_log_rerror(APLOG_MARK, APLOG_INFO,
-                ap_berror(r->connection->client), r,
-                "client stopped connection before vrprintf completed");
-            ap_bsetflag(r->connection->client, B_EOUT, 1);
-            r->connection->aborted = 1;
-        }
-        return -1;
-    }
-    SET_BYTES_SENT(r);
-    return n;
+    str = ap_pvsprintf(r->pool, fmt, ap);    
+    len = strlen(str);
+    return filter_io(r, ap_create_ioqueue(r->pool, str, len));
 }
 
 API_EXPORT(int) ap_rprintf(request_rec *r, const char *fmt,...)
 {
     va_list vlist;
     int n;
+    char *str;
 
     if (r->connection->aborted)
         return -1;
 
     va_start(vlist, fmt);
-    n = ap_vbprintf(r->connection->client, fmt, vlist);
+    str = ap_pvsprintf(r->pool, fmt, vlist);
     va_end(vlist);
 
-    if (n < 0) {
-        if (!r->connection->aborted) {
-            ap_log_rerror(APLOG_MARK, APLOG_INFO,
-                ap_berror(r->connection->client), r,
-                "client stopped connection before rprintf completed");
-            ap_bsetflag(r->connection->client, B_EOUT, 1);
-            r->connection->aborted = 1;
-        }
-        return -1;
-    }
-    SET_BYTES_SENT(r);
-    return n;
+    n = strlen(str);
+    return filter_io(r, ap_create_ioqueue(r->pool, str, n));
 }
 
 API_EXPORT_NONSTD(int) ap_rvputs(request_rec *r,...)
@@ -2510,8 +2553,6 @@
     ap_ssize_t i;
     int j, k;
     const char *x;
-    BUFF *fb = r->connection->client;
-    ap_status_t rv;
 
     if (r->connection->aborted)
         return EOF;
@@ -2522,8 +2563,11 @@
         if (x == NULL)
             break;
         j = strlen(x);
-        rv = ap_bwrite(fb, x, j, &i);
-        if (i != j) {
+
+        i = filter_io(r, ap_create_ioqueue(r->pool, x, j));
+
+/* I think this can be removed, but I am leaving this here until I am 100% sure.  rbb  */ 
+/*        if (i != j) {
             va_end(args);
             if (!r->connection->aborted) {
                 ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
@@ -2532,7 +2576,7 @@
                 r->connection->aborted = 1;
             }
             return EOF;
-        }
+        }*/
         k += i;
     }
     va_end(args);
@@ -2609,7 +2653,7 @@
     }
 
     if (status == HTTP_NO_CONTENT) {
-        ap_send_http_header(r);
+        /*ap_send_http_header(r);*/
         ap_finalize_request_protocol(r);
         return;
     }
@@ -2644,7 +2688,7 @@
         if ((status == METHOD_NOT_ALLOWED) || (status == NOT_IMPLEMENTED))
             ap_table_setn(r->headers_out, "Allow", make_allow(r));
 
-        ap_send_http_header(r);
+        /*ap_send_http_header(r);*/
 
         if (r->header_only) {
             ap_finalize_request_protocol(r);
@@ -2952,3 +2996,4 @@
                             (const request_rec *r),(r),NULL)
 AP_IMPLEMENT_HOOK_RUN_FIRST(unsigned short,default_port,
                             (const request_rec *r),(r),0)
+AP_IMPLEMENT_RHOOK_BASE(filter)
Index: src/main/http_request.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_request.c,v
retrieving revision 1.32
diff -u -d -b -w -u -r1.32 http_request.c
--- src/main/http_request.c	2000/06/12 15:28:53	1.32
+++ src/main/http_request.c	2000/06/15 22:44:10
@@ -68,6 +68,7 @@
 
 #define CORE_PRIVATE
 #include "ap_config.h"
+#include "ap_hooks.h"
 #include "httpd.h"
 #include "http_config.h"
 #include "http_request.h"
@@ -86,6 +87,7 @@
 	    AP_HOOK_LINK(type_checker)
 	    AP_HOOK_LINK(access_checker)
 	    AP_HOOK_LINK(auth_checker)
+	    AP_HOOK_LINK(insert_filter)
 )
 
 AP_IMPLEMENT_HOOK_RUN_FIRST(int,translate_name,
@@ -100,6 +102,7 @@
                           (request_rec *r),(r),OK,DECLINED)
 AP_IMPLEMENT_HOOK_RUN_FIRST(int,auth_checker,
                             (request_rec *r),(r),DECLINED)
+AP_IMPLEMENT_HOOK_VOID(insert_filter, (request_rec *r), (r))
 
 /*****************************************************************
  *
@@ -1246,6 +1249,15 @@
         ap_die(access_status, r);
         return;
     }
+
+    /* The new insert_filter stage makes sense here IMHO.  We are sure that
+     * we are going to run the request now, so we may as well insert filters
+     * if any are available.  Since the goal of this phase is to allow all
+     * modules to insert a filter if they want to, this filter returns
+     * void.  I just can't see any way that this filter can reasonably
+     * fail, either your modules inserts something or it doesn't.  rbb
+     */
+    ap_run_insert_filter(r);
 
     if ((access_status = ap_invoke_handler(r)) != 0) {
         ap_die(access_status, r);

New files:
_________


ap_ioblock.c:
-------------

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * This file was originally written by Ryan Bloom for Covalent Technologies
 * and gifted exclusively to the The Apache Software Foundation in June 2000.
 */

#include "ap_ioblock.h"

ap_ioblock_t *ap_create_ioblock(ap_pool_t *p, const void *v, int length)
{
    ap_ioblock_t *vector;

    vector = ap_pcalloc(p, sizeof(*vector));
    vector->vec = (void *)v;
    vector->len = length;
    vector->bitmask = AP_NOT_WRITABLE;

    return vector;
}

ap_ioqueue_t *ap_start_ioqueue(ap_ioblock_t *b)
{
    ap_ioqueue_t *q;

    q = ap_pcalloc(b->p, sizeof(*q));
    q->p = b->p;
    q->head = b; 
    b->prev = NULL;
    
    while (b->next != NULL) {
        b = b->next;
    }
    q->tail = b;

    return q;
}

ap_ioqueue_t *ap_create_ioqueue(ap_pool_t *p, const void *v, int length)
{
    ap_ioqueue_t *q;

    q = ap_pcalloc(p, sizeof(*q));
    q->p = p;
    q->head = q->tail = ap_create_ioblock(q->p, v, length);

    return q;
}

ap_status_t ap_split_ioblock(ap_ioblock_t *vec, int offset)
{
    ap_ioblock_t *vector;

    vector = ap_pcalloc(vec->p, sizeof(*vector));
    vector->p = vec->p;

    vector->len = vec->len - offset; 
    vec->len = offset;
    vector->vec = vec->vec + offset;
    
    vector->next = vec->next;
    vector->prev = vec;
    vec->next = vector;
    vector->bitmask = vec->bitmask;
    return APR_SUCCESS;
}

ap_ioblock_t *ap_add_ioblock(ap_ioblock_t *vec, const void *v, int length, 
                           int front)
{
    ap_ioblock_t *vector = ap_create_ioblock(vec->p, v, length);
    ap_ioblock_t *dptr = vec;
    
    if (front) {
        vector->next = vec;
        vec->prev = vector;
        return vector; 
    }
    while (dptr->next) {
        dptr = dptr->next;
    }
    dptr->next = vector;
    vector->prev = dptr; 
    return vec;
}

ap_status_t ap_set_ioblock_writable(ap_ioblock_t *vec)
{
    if (vec->bitmask == AP_WRITABLE) {
        return APR_SUCCESS;
    }
    if (vec->bitmask == AP_NOT_WRITABLE) {
        void *v = ap_palloc(vec->p, vec->len);
        memcpy(v, vec->vec, vec->len);
        vec->vec = v;
        return APR_SUCCESS;
    }
    else return APR_ENOTIMPL;
}

ap_ioqueue_t *ap_ioblock_enqueue(ap_ioqueue_t *vec, ap_ioblock_t *toadd) 
{
    vec->tail->next = toadd;
    toadd->prev = vec->tail;
    vec->tail = toadd;
    return vec;
}

ap_ioqueue_t *ap_ioqueue_merge(ap_ioqueue_t *vec, ap_ioqueue_t *toadd) 
{
    vec->tail->next = toadd->head;
    toadd->head->prev = vec->tail;
    vec->tail = toadd->tail;
    return vec;
}


ap_ioblock.h:
-------------

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * This file was originally written by Ryan Bloom for Covalent Technologies
 * and gifted exclusively to the The Apache Software Foundation in June 2000.
 */

#ifndef AP_IOBLOCK_H
#define AP_IOBLOCK_H

#include "apr_pools.h"
#include "apr_file_io.h"
#include "ap_config.h"

#define AP_WRITABLE            1
#define AP_NOT_WRITABLE        2
#define AP_FILE_DESC           4

struct ap_ioblock_t {
    ap_pool_t *p;
    void *vec;
    int len;
    ap_file_t *fd;
    int bitmask;
    struct ap_ioblock_t *next;
    struct ap_ioblock_t *prev;
};

struct ap_ioqueue_t {
    ap_pool_t *p;
    struct ap_ioblock_t *head;
    struct ap_ioblock_t *tail;
};

typedef struct ap_ioblock_t ap_ioblock_t;
typedef struct ap_ioqueue_t ap_ioqueue_t;

API_EXPORT(ap_ioblock_t *) ap_create_ioblock(ap_pool_t *p, const void *v, 
                                           int length); 
API_EXPORT(ap_status_t) ap_split_ioblock(ap_ioblock_t *vec, int offset);
API_EXPORT(ap_ioblock_t *) ap_add_ioblock(ap_ioblock_t *vec, const void *v, 
                                        int length, int front);
API_EXPORT(ap_status_t) ap_set_ioblock_writable(ap_ioblock_t *vec);

API_EXPORT(ap_ioqueue_t *) ap_start_ioqueue(ap_ioblock_t *b); 
API_EXPORT(ap_ioqueue_t *) ap_create_ioqueue(ap_pool_t *p, const void *v, 
                                           int length); 
API_EXPORT(ap_ioqueue_t *) ap_ioblock_enqueue(ap_ioqueue_t *vec, ap_ioblock_t *toadd);
API_EXPORT(ap_ioqueue_t *) ap_ioqueue_merge(ap_ioqueue_t *vec, ap_ioqueue_t *toadd);

#endif


mod_gargle.c:
-------------

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * Portions of this software are based upon public domain software
 * originally written at the National Center for Supercomputing Applications,
 * University of Illinois, Urbana-Champaign.
 */

#include "httpd.h"
#include "ap_hooks.h"
#include "ap_ioblock.h"
#include "http_config.h"
#include "http_request.h"
#include "http_protocol.h"

module MODULE_VAR_EXPORT gargle_module;

typedef struct gargle_rec {
    int on;
} gargle_rec;


ap_ioqueue_t *gargle_filter(request_rec *r, ap_ioqueue_t *strs);

static void *create_gargle_config(ap_pool_t *p, char *dummy)
{
    gargle_rec *new = (gargle_rec *) ap_pcalloc(p, sizeof(gargle_rec));

    new->on = 0;
    return (void *)new;
}

ap_ioqueue_t *gargle_filter(request_rec *r, ap_ioqueue_t *strs)
{
    static int dummy = 0;
    ap_ioblock_t *dptr = strs->head;

    while (dptr != NULL) {
        if (dptr->len > 10) {
            ap_ioblock_t *temp;

            ap_split_ioblock(dptr, 9);
            dptr = dptr->next;
            ap_split_ioblock(dptr, 1);
            ap_split_ioblock(dptr->next, 1);
           
            temp = dptr->next;
            temp->prev = dptr->prev;
            dptr->next = temp->next;
            temp->next = dptr;
            dptr->prev->next = temp;
            dptr->prev = temp;
        }
#if 0
        if (dummy == 0) {
            ap_ioqueue_t *d2 = ap_start_ioqueue(dptr->next);
            dummy = 1;
            dptr->next = NULL;
            return d2;
        }
#endif
        dptr = dptr->next;
    }
    return NULL;
}

static const char *gargle_on(cmd_parms *cmd, void *dummy, char *arg)
{
    gargle_rec *cfg = (gargle_rec *)dummy;

    cfg->on = atoi(arg);

    return NULL;
}

static const command_rec gargle_cmds[] = {
    {"GargleIt", gargle_on, NULL, ACCESS_CONF, TAKE1, 
     "should this request be gargled"},
    {NULL}
}; 

static int gargle_insert_filter(request_rec *r)
{
    gargle_rec *cfg = (gargle_rec *)ap_get_module_config(r->per_dir_config,
                                                         &gargle_module);

    if (cfg->on) {
        ap_rhook_filter(gargle_filter, r, NULL, NULL, AP_HOOK_FILTER);
    }
    return DECLINED;
}

static void register_hooks(void)
{
    ap_hook_insert_filter(gargle_insert_filter, NULL, NULL, AP_HOOK_FILTER);
}

module MODULE_VAR_EXPORT gargle_module =
{
    STANDARD20_MODULE_STUFF,
    create_gargle_config,     /* dir config creater */
    NULL,                     /* dir merger --- default is to override */
    NULL,                     /* server config */
    NULL,                     /* merge server config */
    gargle_cmds,              /* command ap_table_t */
    NULL,                     /* handlers */
    register_hooks            /* register hooks */
};

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------



Re: Filter I/O take 3.

Posted by "Life is hard, and then you die" <ro...@innovation.ch>.
On Sun, Jun 18, 2000 at 03:39:45AM -0700, Greg Stein wrote:
>    [ caveat: actually, there may be subtle gradations here; need to check
>      with Ronald for the digest stuff; for example: when generating a
>      multipart message, what parts do we digest? just the parts, or do we
>      include the whole response body, which includes the boundaries and
>      per-part headers? the answer could change some of the writes. ]

The digest is calculated on the entity-body (the same as for
Content-MD5). This means it includes the whole body, including
boundaries and per-part headers in the case of multipart contents. The
entity body is the same as the message body (which is the actual bytes
sent over the net) except when a transfer encoding is present, in which
case message-body=transfer-encoding(entity-body). But multipart's are
not transfer encodings.


  Cheers,

  Ronald


Re: Filter I/O take 3.

Posted by Rodent of Unusual Size <Ke...@Golux.Com>.
rbb@covalent.net wrote:
> 
> But in committing this, you broke a patch that has been submitted
> for review and you did it intentionally.  It doesn't matter if you
> veto'ed the patch or not.

Yes it does.

> Right now, nobody else can even review the patch to form
> their own opinions.  Which means, you and I are really the only
> two who can easily debate this patch, because anybody who tries
> to apply it now just gets errors.  That is a very bad thing.

'Anyone else' who is interested can roll back Greg's patch before
applying yours.  Or Greg's can be rolled back in the repository
is someone vetoes it with justification.

> The approach to the fundamentals can have an effect on the "meat".
> Please don't make any more changes like this until we have decided
> on an approach.

Play nice, people.  No pre-emption here, please.  Greg, maybe you
could consider rolling back your changes (which I haven't seen) and
posting them for RTC?

> It is true.  Whether you have vetoed it or not, it is being
> considered.

No, not really.  At this point the patch is dead forever unless
Greg decides to rescind his veto.
-- 
#ken    P-)}

Ken Coar                    <http://Golux.Com/coar/>
Apache Software Foundation  <http://www.apache.org/>
"Apache Server for Dummies" <http://Apache-Server.Com/>
"Apache Server Unleashed"   <http://ApacheUnleashed.Com/>

Re: Filter I/O take 3.

Posted by rb...@covalent.net.
> > A couple of things.  Don't do this!  By you making these changes now, you
> > break a patch that is being considered.
> 
> 1) There are common elements between both approaches. I believe we should
>    get that stuff ironed out first. That will make the "meat" of the
>    filtering much smaller and reviewable.

But in committing this, you broke a patch that has been submitted for
review and you did it intentionally.  It doesn't matter if you veto'ed the
patch or not.  Right now, nobody else can even review the patch to form
their own opinions.  Which means, you and I are really the only two who
can easily debate this patch, because anybody who tries to apply it now
just gets errors.  That is a very bad thing.

>    It also means that the non-meat portions can be effectively reviewed. For
>    example, your change from ap_rvputs() to ap_bvputs() was incorrect. I saw
>    it because I'm reviewing your filtering patches very closely. Did anybody
>    else? I seriously doubt it. It seems most people have tuned out :-(

I did.  In fact, I specifically mentioned that the headers stuff had to be
reviewed closer.  (If I didn't, I meant to, and I'm sorry.  I have other
e-mail that definately mentions it that I didn't send).  Just because
there are minor issues, doesn't mean  something is wrong, it's just not
perfect.

>    We are in no rush to get the "meat" checked in, so it seems eminently
>    better to work on getting the fundamentals completed first. Specifically,
>    that means changing ap_rwrite types of calls, which write non-content,
>    over to direct buffer calls.

The approach to the fundamentals can have an effect on the "meat".  Please
don't make any more changes like this until we have decided on an
approach.  For example, I wouldn't have made you change, because it
doesn't make any sense in the hook scheme.

> 2) "considered" isn't entirely true, as the patch has been vetoed. Until
>    some basic changes occur, I don't see that veto changing.

It is true.  Whether you have vetoed it or not, it is being
considered.  And, it will continue to be considered until you or somebody
else post a new patch.  This is because other people can review the patch
and help to convince either you or me that we are wrong.  One veto does
not mean the patch has been removed from consideration.  It means one
person is stopping it from being committed.  Those are VERY different
things.

> > 1)  Modules must maintain their own stat for the data they haven't dealt
> > with yet.
> 
> In the link scheme, each ap_layer_t structure has a context pointer. This
> allows a layer to store arbitrary context about where they are.

But it is up to the module to maintain this state.

> These context pointers are analogous to the r->unfiltered[] concept that you
> introduced in your latest patch. You alloc one per layer; I put them right
> in with the layer. The unfiltered[] thing is specific to "unprocessed input"
> while the context pointer is arbitrary (and may include unprocessed input
> along with other values, such as the parsing state of a finite automata that
> is operating within the filter).

The difference is who maintains the state.  You make the module do it.  I
make the core do it.  If the module does it, then the module has to
implement it's own iovec's.  If the core does it, then the iovec's have
one implementation, and the modules only have deal with iovec's, not
iovec's and regular strings.

> IMO, associating the state in the ap_layer_t is more direct than a secondary
> array. I'm also a bit uneasy about keeping the two in sync (although it is
> quite unlikely that a filter would be added/removed/re-ordered after the
> first content byte goes out), and that it relies on the .nelts field which
> seems rather private to the hook implementation.

The reliance on nelts will be fixed as soon as their is a
ap_get_nelts() function for tables.  If a request re-orders the layers, it
has to make sure that all data has been flushed from the layers that are
being re-ordered otherwise the results will be very strange.  If the data
is empty, re-ordering is simple in the hook scheme.

> I'm unaware of any particular issues with storing state in the ap_layer_t.
> It doesn't seem like the considerations mentioned just above apply; please
> correct me otherwise.

Take mod_foo, which has saved in it's layer context the string "waiting to
be dealt with".  Now, the next time the filter is called (passed the data 
"just arrived to the filter", with the link scheme, the module has to
parse "waiting to be dealt with" and "just arrived to the filter".  This
is an iovec.  Why should a module writer have to deal with both regular
strings and iovecs?  Even if you don't use iovec's, you have to mimic
them.  Take this instance:

first call to filter:   <!--
second call:            #set
third call:             foo=bar -->

The module has just been forced to implement iovec's.  :-)

> Eh? This is the entire design of the BUFF code. Accumulate data into a
> pre-alloc'd buffer. When it gets large enough, dump it to the network. If
> the input buffer is large enough, then drop it straight to the network.
> 
> I disagree with your characterization about the two schemes. I look at your
> mod_gargle and see a bunch of small buffers created, and each is dumped to
> ap_bwrite() in the filter_io() function.

This is because it hasn't been optimized.  Do not take non-optimized code
for the final thing.  It is VERY easy to re-write bwrite (or create
ap_bvwrite) to sum up the amount of data passed and use that value as the
size.

> As you make it easier to create ioblocks (e.g. ap_ioblock_add("string")),
> then people will start appending little bits to the ioqueue. Same situation
> as the link-based scheme. Any coalescing that can be done in the hook scheme
> would duplicate what BUFF is already doing. IOW, even if one of the schemes
> "can" coalesce blocks, it is a moot point.

See above.

> Neither filtering scheme is going to encourage any particular buffer size.
> They'll be big or small, many or few, as the module writer desires. I don't
> see this (2) as an actionable "issue" with the link-based scheme.

See above.

> > 3)  Modules must filter data without any context about what else is going
> > on around the data they are directly working on.  Unless of course they
> > maintain that data themselves.  There is an obvious change to the hook
> > scheme that allows us to send a minimum amount of data to a hook at any
> > one time.  This cannot be done for the link based scheme (at least not
> > cleanly IMHO.)
> 
> I am unsure what you are saying here. It seems like you're suggesting that
> we buffer up data and pass larger chunks to the filters. That seems possible
> with either scheme.
> 
> Am I missing something here?

Yes, in the link-based scheme, the module has a small piece of data to
work with, which provides no context for the module.  If you start to
buffer stuff up in the link-based scheme, you are using iovec's to do
it.  This removes your objection to the complexity of the iovec's.  BTW, I
believe you have just described Roy's bucket brigades.

> Common work that still needs to be done:
> - add the "insert_filters" hook
> - some ap_rputs() calls switched to use an internal function (which looks
>   exactly like today's ap_rputs); later, we'll switch ap_rputs() to filter
>   content, which won't affect the non-content writes.
> - automatically call ap_send_http_header() on the first output, or when the
>   request terminates with an empty-body response such as 204
> - add/use trailer_hdrs to request_rec for mod_auth_digest
> - create a flush_filters() to be called from ap_finalize_request_protocol();
>   will be filled in later.
>   (this is also where the trailer_hdrs are sent out)

I am -1 veto'ing any changes to this code until a decision is made on the
approach.  Breaking patches that are currently being reviewed is a VERY
bad precedence to set.  The patch that has already been committed makes it
impossible for anybody new to review the patch.  Adding more to that is a
very bad idea.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: Filter I/O take 3.

Posted by Greg Stein <gs...@lyra.org>.
On Sat, Jun 17, 2000 at 06:00:59AM -0700, rbb@covalent.net wrote:
> 
> > *) complexity due to the ioblock/ioqueue stuff
> > 
> > *) I do not understand how sub requests are handled in this scheme
> >    (essentially, how are the two sets of hooks joined together)
> > 
> > *) if I fetch 100Mb from a database for insertion into the content stream,
> >    how does that work in this scheme? (flow control, working set)
> > 
> > *) flow control (I didn't see how this works)
> > 
> > *) working set size (since all data must occur on the heap)
> > 
> > I'm off to sleep soon, but today I'm going to work on fixing up the common
> > stuff between the alternate schemes. For example, we agree that an
> > "insert_filters" hook needs to be added. There are a number of ap_rputs()
> > (and similar) calls that need to change to BUFF operations. etc.
> 
> A couple of things.  Don't do this!  By you making these changes now, you
> break a patch that is being considered.

1) There are common elements between both approaches. I believe we should
   get that stuff ironed out first. That will make the "meat" of the
   filtering much smaller and reviewable.

   It also means that the non-meat portions can be effectively reviewed. For
   example, your change from ap_rvputs() to ap_bvputs() was incorrect. I saw
   it because I'm reviewing your filtering patches very closely. Did anybody
   else? I seriously doubt it. It seems most people have tuned out :-(
   
   We are in no rush to get the "meat" checked in, so it seems eminently
   better to work on getting the fundamentals completed first. Specifically,
   that means changing ap_rwrite types of calls, which write non-content,
   over to direct buffer calls.
   [ caveat: actually, there may be subtle gradations here; need to check
     with Ronald for the digest stuff; for example: when generating a
     multipart message, what parts do we digest? just the parts, or do we
     include the whole response body, which includes the boundaries and
     per-part headers? the answer could change some of the writes. ]

2) "considered" isn't entirely true, as the patch has been vetoed. Until
   some basic changes occur, I don't see that veto changing.

>... commentary on link-based scheme:

> 1)  Modules must maintain their own stat for the data they haven't dealt
> with yet.

In the link scheme, each ap_layer_t structure has a context pointer. This
allows a layer to store arbitrary context about where they are.

These context pointers are analogous to the r->unfiltered[] concept that you
introduced in your latest patch. You alloc one per layer; I put them right
in with the layer. The unfiltered[] thing is specific to "unprocessed input"
while the context pointer is arbitrary (and may include unprocessed input
along with other values, such as the parsing state of a finite automata that
is operating within the filter).

IMO, associating the state in the ap_layer_t is more direct than a secondary
array. I'm also a bit uneasy about keeping the two in sync (although it is
quite unlikely that a filter would be added/removed/re-ordered after the
first content byte goes out), and that it relies on the .nelts field which
seems rather private to the hook implementation.

> The hook scheme just has them return that data, and Apache
> hands it back to them later.  BTW, the only way I can see to really solve
> this is to either use iovec's inside the module (invalidating the
> ioblock/ioqueue argument) or strcat data (invalidating the working
> set/ stack/heap argument).

I'm unaware of any particular issues with storing state in the ap_layer_t.
It doesn't seem like the considerations mentioned just above apply; please
correct me otherwise.

> 2)  Take a look at the bwrite code.  If we don't write enough data at
> once, bwrite makes a copy of all of the data in order to concatenate it
> together.  The hook based scheme minimizes this problem in two
> ways.  1)  It encourages people to maintain big chunks to send at
> once.  2)  There is an obvious optimization where we can combine data to
> create larger chunks.  The link based scheme is going to promote writing
> small chunks of data down the pipe.  IMNSHO, this invalidates the working
> set/stack/heap argument, because both cases have this problem due to
> bwrite.

Eh? This is the entire design of the BUFF code. Accumulate data into a
pre-alloc'd buffer. When it gets large enough, dump it to the network. If
the input buffer is large enough, then drop it straight to the network.

I disagree with your characterization about the two schemes. I look at your
mod_gargle and see a bunch of small buffers created, and each is dumped to
ap_bwrite() in the filter_io() function.

As you make it easier to create ioblocks (e.g. ap_ioblock_add("string")),
then people will start appending little bits to the ioqueue. Same situation
as the link-based scheme. Any coalescing that can be done in the hook scheme
would duplicate what BUFF is already doing. IOW, even if one of the schemes
"can" coalesce blocks, it is a moot point.

In today's Apache, I look at output_directories() in mod_autoindex.c, and
see a function which calls a bazillion ap_rputs() calls for small buffers.
Apache does okay there, buffering those babies up.

Neither filtering scheme is going to encourage any particular buffer size.
They'll be big or small, many or few, as the module writer desires. I don't
see this (2) as an actionable "issue" with the link-based scheme.

> 3)  Modules must filter data without any context about what else is going
> on around the data they are directly working on.  Unless of course they
> maintain that data themselves.  There is an obvious change to the hook
> scheme that allows us to send a minimum amount of data to a hook at any
> one time.  This cannot be done for the link based scheme (at least not
> cleanly IMHO.)

I am unsure what you are saying here. It seems like you're suggesting that
we buffer up data and pass larger chunks to the filters. That seems possible
with either scheme.

Am I missing something here?

> 4)  We are jumping up and down the stack and basically arriving at the
> same place.  The link based scheme encourages people to write small bits
> of data to the next filter, which will make us jump up and down the stack
> all the time.  The only solution to this is to use iovecs (Roy's bucket
> brigade) which invalidates the ioblock/ioqueue argument.

This characterization is similar to (2), which I don't feel is a valid
assessment. There is no "encouragement" one way or another.

I do not see how an iovec can assist here (in accumulating larger bits).

Recap:

1) state. stored in the ap_layer_t as a void*
2) "the link scheme encourages small writes; small writes are a problem"
   I disagree on both accounts.
3) buffering data to pass to the filters. possible for both. this would look
   about the same for both, too.
4) similar to (2). something about an iovec.

> I think that's it.  BTW, as far as getting negative feedback from the
> network, Apache doesn't do that currently.  Apache checks to see how much
> data is being written, and if it is less than a certain size, it buffers
> it.  If it is larger, it writes.

And that write will block if you shove too much into the socket.

Consider the following link-based filter:

    my_callback(layer, buf, len):
        ... figure out we're inserting database content here ...
	blob = fetch_blob_cursor(...)
	while db.more_exists():
	    ap_lwrite(blob.next_chunk())
	blob.close()
	... other stuff ...

Since the ap_lwrite() can potentially block on the network, it means that
the entire database -> network copy will be paced at the speed that the
client truly needs/desires.

In the hook-based scheme, the entire blob must be read onto the heap and
passed back through the ioqueue. That falls down *very* hard when that blob
is a gigabyte of streaming video being yanked out of a database.

[ this example demonstrates flow control and working set problems with the
  hook-based scheme ]

> Look for LARGE_WRITE_THRESHOLD in
> buff.c.  The hook scheme easily duplicates this behavior and there is a
> comment on how to do it.  In the patch I submitted there is a comment with
> MAX_STRING_SIZE in it.  That needs to be changed to
> LARGE_WRITE_THRESHOLD.

That would be an artificial limiter. The network is where the true limit and
pace is determined.


Okay, the "bad" news. I'm off to Napa for a few days. I'll be back
Wednesday. I might get a chance to read email in between the wine and
relaxation :-), but maybe not. Unfortunately, this also means that I won't
have an opportunity to remove my current veto on any hook-based patches.

Common work that still needs to be done:
- add the "insert_filters" hook
- some ap_rputs() calls switched to use an internal function (which looks
  exactly like today's ap_rputs); later, we'll switch ap_rputs() to filter
  content, which won't affect the non-content writes.
- automatically call ap_send_http_header() on the first output, or when the
  request terminates with an empty-body response such as 204
- add/use trailer_hdrs to request_rec for mod_auth_digest
- create a flush_filters() to be called from ap_finalize_request_protocol();
  will be filled in later.
  (this is also where the trailer_hdrs are sent out)

Back on Wednesday...

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Filter I/O take 3.

Posted by Rodent of Unusual Size <Ke...@Golux.Com>.
rbb@covalent.net wrote:
> 
> A couple of things.  Don't do this!

Out of order; procedural error.

> By you making these changes now, you break a patch that is being
> considered.

No, it has been vetoed.  It's not under consideration any more.
And it can't hold up anyone else's work.  If you want, you can
veto Greg's patch (giving a technical justification) and it'll
be rolled back.

> This has the side effect of making it impossible for somebody
> new to even apply my patch, and it makes updating my tree a real
> mess.

Anyone who wants to apply your patch is free and able to roll
Greg's back first.  You CAN'T issue a pre-emptive veto, and
certainly not because it messes up *your* tree.

> Your patch however basically does some of what I did (and it makes
> little sense to have a separate function for this in my scheme).

Alternatives are good, and at the moment the jury is still waaaay
out on whether *your* scheme is the best approach.  Since it's
been vetoed..
-- 
#ken    P-)}

Ken Coar                    <http://Golux.Com/coar/>
Apache Software Foundation  <http://www.apache.org/>
"Apache Server for Dummies" <http://Apache-Server.Com/>
"Apache Server Unleashed"   <http://ApacheUnleashed.Com/>

Re: Filter I/O take 3.

Posted by rb...@covalent.net.
> *) complexity due to the ioblock/ioqueue stuff
> 
> *) I do not understand how sub requests are handled in this scheme
>    (essentially, how are the two sets of hooks joined together)
> 
> *) if I fetch 100Mb from a database for insertion into the content stream,
>    how does that work in this scheme? (flow control, working set)
> 
> *) flow control (I didn't see how this works)
> 
> *) working set size (since all data must occur on the heap)
> 
> I'm off to sleep soon, but today I'm going to work on fixing up the common
> stuff between the alternate schemes. For example, we agree that an
> "insert_filters" hook needs to be added. There are a number of ap_rputs()
> (and similar) calls that need to change to BUFF operations. etc.

A couple of things.  Don't do this!  By you making these changes now, you
break a patch that is being considered.  And they way you have started,
you have broken the patch completely.  This has the side effect of making
it impossible for somebody new to even apply my patch, and it makes
updating my tree a real mess.  I can not re-create the patch this
weekend, because I am at a wedding in NH and can't take the time to 
do it.  This effectively stops all discussion on this topic for a few
days.  Breaking a patch because two people are working in the same section
of code on two different projects, I can understand that.  Your patch
however basically does some of what I did (and it makes little sense to
have a separate function for this in my scheme).

Now, because you have done a wonderful job expressing where the hook
scheme falls down, allow me to do the same for the link scheme:

1)  Modules must maintain their own stat for the data they haven't dealt
with yet.  The hook scheme just has them return that data, and Apache
hands it back to them later.  BTW, the only way I can see to really solve
this is to either use iovec's inside the module (invalidating the
ioblock/ioqueue argument) or strcat data (invalidating the working
set/ stack/heap argument).

2)  Take a look at the bwrite code.  If we don't write enough data at
once, bwrite makes a copy of all of the data in order to concatenate it
together.  The hook based scheme minimizes this problem in two
ways.  1)  It encourages people to maintain big chunks to send at
once.  2)  There is an obvious optimization where we can combine data to
create larger chunks.  The link based scheme is going to promote writing
small chunks of data down the pipe.  IMNSHO, this invalidates the working
set/stack/heap argument, because both cases have this problem due to
bwrite.

3)  Modules must filter data without any context about what else is going
on around the data they are directly working on.  Unless of course they
maintain that data themselves.  There is an obvious change to the hook
scheme that allows us to send a minimum amount of data to a hook at any
one time.  This cannot be done for the link based scheme (at least not
cleanly IMHO.)

4)  We are jumping up and down the stack and basically arriving at the
same place.  The link based scheme encourages people to write small bits
of data to the next filter, which will make us jump up and down the stack
all the time.  The only solution to this is to use iovecs (Roy's bucket
brigade) which invalidates the ioblock/ioqueue argument.

I think that's it.  BTW, as far as getting negative feedback from the
network, Apache doesn't do that currently.  Apache checks to see how much
data is being written, and if it is less than a certain size, it buffers
it.  If it is larger, it writes.  Look for LARGE_WRITE_THRESHOLD in
buff.c.  The hook scheme easily duplicates this behavior and there is a
comment on how to do it.  In the patch I submitted there is a comment with
MAX_STRING_SIZE in it.  That needs to be changed to
LARGE_WRITE_THRESHOLD.

Ryan


_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------




Re: Filter I/O take 3.

Posted by rb...@covalent.net.
> > Issues not resolved:
> >      Negative pushback from the network (there is a comment in the code
> > for how to implement this)
> 
> I could not find this comment, or see how it could be done.

Look for MAX_STRING_LENGTH.  This is to throttle the server from sending
too much data.

> This solution has covered the "return an FD so that sendfile() can be used",
> but doesn't cover these items very well:  (from my "recap" email)
> 
> *) complexity due to the ioblock/ioqueue stuff

I still don't agree with the complexity issue.  Especially not with all of
the helper functions that can/will/have been created.  

> *) I do not understand how sub requests are handled in this scheme
>    (essentially, how are the two sets of hooks joined together)

Since a sub request and main request share the buffer, and the filters,
this should just work.  I don't see the issue (see my last note about my
day and why I shouldn't be reading e-mail if this is something obvious I
am missing).

> *) if I fetch 100Mb from a database for insertion into the content stream,
>    how does that work in this scheme? (flow control, working set)

The same way it works in your scheme.  You add a 100MB iovec, and it gets
sent to the next filter.  In my scheme, that 100MB will be chuncked and
sent in smaller chunks, my it gets there all the same.

> >...
> > @@ -1394,7 +1474,8 @@
> >  API_EXPORT_NONSTD(int) ap_send_header_field(request_rec *r,
> >      const char *fieldname, const char *fieldval)
> >  {
> > -    return (0 < ap_rvputs(r, fieldname, ": ", fieldval, CRLF, NULL));
> > +    return (0 < ap_bvputs(r->connection->client, fieldname, ": ", fieldval, 
> > +                          CRLF, NULL));
> 
> These are not equivalent. Specifically, ap_rvputs() deals with aborted
> connections, and with logging an error when a connection aborts.
> 
> I think we need a few "internal" functions that http_protocol can use which
> are just slim covers over ap_bvputs() and friends. They would be equivalent
> to the *current* ap_rvputs() and friends (the new ap_rvputs calls into the
> filtering/layering).

That's fine.  This is a first pass, and I didn't really investigate the
headers stuff too much.

> > ap_ioqueue_t *gargle_filter(request_rec *r, ap_ioqueue_t *strs)
> > {
> >     static int dummy = 0;
> >     ap_ioblock_t *dptr = strs->head;
> > 
> >     while (dptr != NULL) {
> >         if (dptr->len > 10) {
> >             ap_ioblock_t *temp;
> > 
> >             ap_split_ioblock(dptr, 9);
> >             dptr = dptr->next;
> >             ap_split_ioblock(dptr, 1);
> >             ap_split_ioblock(dptr->next, 1);
> >            
> >             temp = dptr->next;
> >             temp->prev = dptr->prev;
> >             dptr->next = temp->next;
> >             temp->next = dptr;
> >             dptr->prev->next = temp;
> >             dptr->prev = temp;
> >         }
> > #if 0
> >         if (dummy == 0) {
> >             ap_ioqueue_t *d2 = ap_start_ioqueue(dptr->next);
> >             dummy = 1;
> >             dptr->next = NULL;
> >             return d2;
> >         }
> > #endif
> >         dptr = dptr->next;
> >     }
> >     return NULL;
> > }
> 
> Um... what does this do? I can't tell. It looks like it is breaking up input
> chunks into smaller chunks, then doing something.
> 
> I'll write an equivalent mod_gargle and/or some other examples, but at this
> point, I can't duplicate the above code until I know what it does :-)

It just flips the every 10 and 11 characters.  I did some messy pointer
stuff because I really didn't care about this being clean.  I also have
some code in there to test some other features that aren't fully
implemented yet.  That makes some of this code ugly, because I am setting
up contrived situations.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: Filter I/O take 3.

Posted by Greg Stein <gs...@lyra.org>.
On Thu, Jun 15, 2000 at 03:52:53PM -0700, rbb@covalent.net wrote:
>... 
> Issues resolved:
>      Grouping filters by type
>      allocating space on the stack or heap as appropriate

I'm not sure that I understand how data can be allocated on the stack, since
the call into the hook function unwinds before data is sent to the network
layer.

>      memcpy'ing data that is never modified (not done anymore)
>      Send headers after filters have sent the first block of data.
> 
> Issues not resolved:
>      Negative pushback from the network (there is a comment in the code
> for how to implement this)

I could not find this comment, or see how it could be done.

>      Filters that only deal with half the data.  (the basic idea is there,
> but it is not well tested.  Still working on this).
>      cleanup the code:  some stuff just commented out until it can be
> tested better.
>      insert ap_run_insert_filters for sub_requests???  I'm not sure about
> this.  Maybe we just want to inherit these.

The sub-request thing is tricky. I believe the "main" request is the only
one that should be allowed to insert encoding/digest/transport filters. Any
(sub)request can insert "processors" at will. Effectively, this recognizes
the fact that certain classes of filters operate on the "final" content,
these should be installed once, and that means the "main" request is the one
that does the final processing.

For example, we want a subrequest to install an PHP filter, but we don't
want it to install the Digest filter (cuz the "main" request has done so).
More explicitly:

    /foo/page.shtml
        (contains <!--#cgi /cgi/whatever)
    /cgi/whatever

The /cgi directory is configured to process output thru PHP. The request on
/foo/page.shtml is done via Digest, so a Digest message filter has been
installed on the request. Note that the main request also has an SSI filter
being processed.


>      Others?  I know there are others, but I can't think of them right
> now.

This solution has covered the "return an FD so that sendfile() can be used",
but doesn't cover these items very well:  (from my "recap" email)

*) complexity due to the ioblock/ioqueue stuff

*) I do not understand how sub requests are handled in this scheme
   (essentially, how are the two sets of hooks joined together)

*) if I fetch 100Mb from a database for insertion into the content stream,
   how does that work in this scheme? (flow control, working set)

*) flow control (I didn't see how this works)

*) working set size (since all data must occur on the heap)


I'm off to sleep soon, but today I'm going to work on fixing up the common
stuff between the alternate schemes. For example, we agree that an
"insert_filters" hook needs to be added. There are a number of ap_rputs()
(and similar) calls that need to change to BUFF operations. etc.

After doing the basic work, then I'm going to write a patch for the
link-based scheme. We can then do a direct comparison of the two approaches
and get comments.

A few comments below:

>...
> @@ -1394,7 +1474,8 @@
>  API_EXPORT_NONSTD(int) ap_send_header_field(request_rec *r,
>      const char *fieldname, const char *fieldval)
>  {
> -    return (0 < ap_rvputs(r, fieldname, ": ", fieldval, CRLF, NULL));
> +    return (0 < ap_bvputs(r->connection->client, fieldname, ": ", fieldval, 
> +                          CRLF, NULL));

These are not equivalent. Specifically, ap_rvputs() deals with aborted
connections, and with logging an error when a connection aborts.

I think we need a few "internal" functions that http_protocol can use which
are just slim covers over ap_bvputs() and friends. They would be equivalent
to the *current* ap_rvputs() and friends (the new ap_rvputs calls into the
filtering/layering).

>...
> ap_ioqueue_t *gargle_filter(request_rec *r, ap_ioqueue_t *strs)
> {
>     static int dummy = 0;
>     ap_ioblock_t *dptr = strs->head;
> 
>     while (dptr != NULL) {
>         if (dptr->len > 10) {
>             ap_ioblock_t *temp;
> 
>             ap_split_ioblock(dptr, 9);
>             dptr = dptr->next;
>             ap_split_ioblock(dptr, 1);
>             ap_split_ioblock(dptr->next, 1);
>            
>             temp = dptr->next;
>             temp->prev = dptr->prev;
>             dptr->next = temp->next;
>             temp->next = dptr;
>             dptr->prev->next = temp;
>             dptr->prev = temp;
>         }
> #if 0
>         if (dummy == 0) {
>             ap_ioqueue_t *d2 = ap_start_ioqueue(dptr->next);
>             dummy = 1;
>             dptr->next = NULL;
>             return d2;
>         }
> #endif
>         dptr = dptr->next;
>     }
>     return NULL;
> }

Um... what does this do? I can't tell. It looks like it is breaking up input
chunks into smaller chunks, then doing something.

I'll write an equivalent mod_gargle and/or some other examples, but at this
point, I can't duplicate the above code until I know what it does :-)

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Filter I/O take 3.

Posted by rb...@covalent.net.
> I just had a quick perusal and missed two things, both of which are
> essential for mod_auth_digest to amke any use of filtering at all:

It has been anincredibly long day (including 5 hours in Cleveland waiting
for a plane), so I probably shouldn't even be reading e-mail, but.....

> 1) being able to set trailers in the response. When using qop=auth-int,
>    mod_auth_digest needs to calculate a hash of the entity as it's being
>    written, and then needs to put that hash in a trailer which gets sent
>    with the last chunk (yes, this doesn't work for HTTP/1.0 clients -
>    however, I'm not aware of any HTTP/1.0 clients which do digest auth).

I would think this would be solved by making ap_flush go through the
filters.  Or, adding a trailers table to the request_rec that the filter
code outputs.  I didn't know about this issue, so I haven't thought it
through yet.

> 2) Layering on the request body. If a request comes in with qop=auth-int
>    then mod_auth_digest needs to be able to calculate a hash of the request
>    body. It'll also need to be able to access the trailers in case the
>    client put the info in the trailer.

That is input filtering, which I didn't implement.  I believe filtering
input is simple once we filter output.  We just need to insert the right
calls.

> Btw., great to the the grouping by type!

At least something was good.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: Filter I/O take 3.

Posted by "Life is hard, and then you die" <ro...@innovation.ch>.
On Thu, Jun 15, 2000 at 03:52:53PM -0700, rbb@covalent.net wrote:
> 
> This patch enable filtering output.  I have not implemented input
> filtering, because I believe it is trivial once we have the output
> done.
> 
> Issues resolved:
>      Grouping filters by type
>      allocating space on the stack or heap as appropriate
>      memcpy'ing data that is never modified (not done anymore)
>      Send headers after filters have sent the first block of data.
> 
> Issues not resolved:
>      Negative pushback from the network (there is a comment in the code
> for how to implement this)
>      Filters that only deal with half the data.  (the basic idea is there,
> but it is not well tested.  Still working on this).
>      cleanup the code:  some stuff just commented out until it can be
> tested better.
>      insert ap_run_insert_filters for sub_requests???  I'm not sure about
> this.  Maybe we just want to inherit these.
>      Others?  I know there are others, but I can't think of them right
> now.

I just had a quick perusal and missed two things, both of which are
essential for mod_auth_digest to amke any use of filtering at all:

1) being able to set trailers in the response. When using qop=auth-int,
   mod_auth_digest needs to calculate a hash of the entity as it's being
   written, and then needs to put that hash in a trailer which gets sent
   with the last chunk (yes, this doesn't work for HTTP/1.0 clients -
   however, I'm not aware of any HTTP/1.0 clients which do digest auth).

2) Layering on the request body. If a request comes in with qop=auth-int
   then mod_auth_digest needs to be able to calculate a hash of the request
   body. It'll also need to be able to access the trailers in case the
   client put the info in the trailer.

Btw., great to the the grouping by type!


  Cheers,

  Ronald


Re: Filter I/O take 3.

Posted by Manoj Kasichainula <ma...@io.com>.
On Fri, Jun 16, 2000 at 07:49:43PM -0700, rbb@covalent.net wrote:
> I agree.  Apache 2.0 is not going to be async, and it doesn't need to
> support it.  3.0 may be async.  It will require almost a complete re-write
> if that is going to happen.  Take a look at the STATUS file, a re-org for
> async is actually in there for post-2.0.  I do not want 2.0 to become a
> kitchen sink again.  Adding async I/O to 2.0 is a bad idea and I will
> fight it.

+1. No, I don't think the current I/O architectures being discussed
will necessarily fit in well with an async architecture, but an async
architecture also allows some much cooler layering systems I think, so
I figure it'll all get thrown out for 3.0.


Re: Filter I/O take 3.

Posted by David Reid <dr...@jetnet.co.uk>.
> Apache moving to an async model simply looks impossible, without a
**HUGE**
> overhaul in every facet of its operation. At that point, it just won't be
> Apache. I could see a case where a module can say "I can deal with async;
> here is my API to call for read/write availability." To support that,
> though, would still require a huge revamp on the Apache-side of the
equation.
>

And...

> Async I/O would be nice, but it just won't be happening in Apache any time
> soon or far. I really don't think we can start saying "well, if that
doesn't
> support async, then it is out." By that rule, we could hardly make any
> changes :-)

As Dean keeps pointing out, asynch should be a big win, but it will need, as
jeff pointed out, carefully planning and forethought.

Think back to the origins of the A2 tree.  Dean took some time and ripped
apart 1.3 to create the MPM's.  From there APR was added and off we went to
roughly where we are now.

I'd suggest that once we get A2 out the door that maybe someone should do
the same radical reshape for asynch.  We ran with a small group looking at
A2 while most people carried on with 1.3 so why not do it again?  I just
can't see any other way of doing such a large revamp, so I agree that
support for asynch can't be used as a valid reason for vetos at present.
Sorry Bill :(

I seem to remember this being discussed before and we had a "rough" roadmap
to this effect didn't we?

> I'd love to be educated on how to change Apache to an async model. I just
> don't see it right now.

That would be good for all of us.  Maybe someone should either write a piece
on how it could be done or point us all at a document that gives that
information?  But maybe we should also wait until we get A2 out the door?

david


Re: Filter I/O take 3.

Posted by Jeff Trawick <tr...@ibm.net>.
> Date: Fri, 16 Jun 2000 14:40:05 -0700
> From: Greg Stein <gs...@lyra.org>
> 
> > Note that various folks have pointed out that doing async I/O only on
> > read (and perhaps only when reading/waiting for the first header of a
> > request) brings a lot of bang for the buck (I don't mean that
> > literally, Ralf).  
> 
> Can't do this either. Consider the various calls to ap_get_client_block()
> which are (again) scattered down "inside" modules which then rely on
> context which is defined by the stack.
> 
> Apache moving to an async model simply looks impossible, without a **HUGE**
> overhaul in every facet of its operation. At that point, it just won't be
> Apache. I could see a case where a module can say "I can deal with async;
> here is my API to call for read/write availability." To support that,
> though, would still require a huge revamp on the Apache-side of the
> equation.

I think it would be fairly straightforward and non-intrusive to use an
async read to keep from tying up lots of threads in keepalive:

  In ap_process_http_connection(), before calling ap_read_request()
  have a way to detect whether or not there is data from the network
  already available in the underlying BUFF.  If no data available,
  return to the MPM code, which will start an async read request with
  the BUFF's internal buffer as the place where the data should land.
  This worker thread then looks for work to do on other connections.

  (Possible optimizations: if no data in BUFF's buffer, call poll() or
  select() to see if we would block; maybe we always want to block for
  the first request on a connection)

  When the MPM is notified by the kernel (hopefully with the conn_rec
  address as user data), the MPM maps the request to a worker thread,
  which calls ap_process_connection() again.  It has data this time so
  it does ap_read_request() and processes the request and again, just
  before ap_read_request(), makes the decision about whether to commit
  to processing another request or returning back to the MPM.

  Every second or so, the MPM would cancel the async read requests for
  connections that have exceeded the keepalive timeout and close their
  sockets.

As for async I/O elsewhere...  order of magnitude more trouble

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Re: Filter I/O take 3.

Posted by Greg Stein <gs...@lyra.org>.
On Fri, Jun 16, 2000 at 02:44:56PM -0000, Jeff Trawick (httpd) wrote:
> > Date: Fri, 16 Jun 2000 07:27:34 -0700
> > From: Greg Stein <gs...@lyra.org>
> 
> >           I presume for an async I/O approach, you would need to flip
> > this around where the network layer says "I'm ready for more" and "pulls"
> > content. Is my read on the situation correct?
> 
> (I'm only familiar with async I/O on OS/390, but I would hope it works
> similarly on other platforms.)
> 
> I don't see it as flipping it around.  Instead it is more like

The pull vs push is what I meant by "flipping." The async model is pull.
Apache is built entirely around push.

>...
> If we're in an output pipeline and we get to the point of doing a
> write to the TCP stack and we make the request async, we just need to
> save our state (in a way that any other thread in the process can pick
> it back up when the I/O is complete) and see if there is work on
> another connection for us to carry forward before we go to sleep.

Yah, that is what I surmised. Apache simply cannot do async output. Its
entire processing model is built around calling to a module and having that
module call ap_rwrite() as it goes.

Take my favorite example for a content-generator: mod_autoindex. Examine the
emit_link() function and how it calls ap_rvputs(). If that blocks, then what
do you do? The thread simply blocks... there isn't a way to do async I/O.

> Depending on where state is saved and buffers are handled and how you
> choose to switch the context from one connection to another, async I/O
> may or may not be broken.  If state (and I/O  buffers) live on the
> stack, that places some extreme (perhaps fatal) limitations on how the
> state of one connection can be saved for picking back up later.  This
> is more to say that it can be done in a way that allows async I/O to
> be done.  I don't think we would want to get in a position where we
> were forced to use a user-level thread package to make it work.

We're already there :-)

> Note that various folks have pointed out that doing async I/O only on
> read (and perhaps only when reading/waiting for the first header of a
> request) brings a lot of bang for the buck (I don't mean that
> literally, Ralf).  

Can't do this either. Consider the various calls to ap_get_client_block()
which are (again) scattered down "inside" modules which then rely on
context which is defined by the stack.

Apache moving to an async model simply looks impossible, without a **HUGE**
overhaul in every facet of its operation. At that point, it just won't be
Apache. I could see a case where a module can say "I can deal with async;
here is my API to call for read/write availability." To support that,
though, would still require a huge revamp on the Apache-side of the equation.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Filter I/O take 3.

Posted by "Jeff Trawick (httpd)" <tr...@ibm.net>.
> Date: Fri, 16 Jun 2000 07:27:34 -0700
> From: Greg Stein <gs...@lyra.org>

>           I presume for an async I/O approach, you would need to flip
> this around where the network layer says "I'm ready for more" and "pulls"
> content. Is my read on the situation correct?

(I'm only familiar with async I/O on OS/390, but I would hope it works
similarly on other platforms.)

I don't see it as flipping it around.  Instead it is more like
multiplexing the work of sending data on multiple sockets using select
and non-blocking sockets.  You do what you can on one socket (without
blocking) and move on to the next socket.

With asynch I/O, the program issues a request (consider just read/write
for now) and can then go about its business (but not touching the
buffers handed off to the request) until at some later time the system
notifies the program that the request is complete.

If we're in an output pipeline and we get to the point of doing a
write to the TCP stack and we make the request async, we just need to
save our state (in a way that any other thread in the process can pick
it back up when the I/O is complete) and see if there is work on
another connection for us to carry forward before we go to sleep.

Depending on where state is saved and buffers are handled and how you
choose to switch the context from one connection to another, async I/O
may or may not be broken.  If state (and I/O  buffers) live on the
stack, that places some extreme (perhaps fatal) limitations on how the
state of one connection can be saved for picking back up later.  This
is more to say that it can be done in a way that allows async I/O to
be done.  I don't think we would want to get in a position where we
were forced to use a user-level thread package to make it work.

Note that various folks have pointed out that doing async I/O only on
read (and perhaps only when reading/waiting for the first header of a
request) brings a lot of bang for the buck (I don't mean that
literally, Ralf).  

Jeff
(anybody got a sig I can have?)

Re: Filter I/O take 3.

Posted by rb...@covalent.net.
> At the moment, Apache is a "push" model, from the original content source,
> down to the network layer. That is pretty ingrained into Apache's
> architecture. I presume for an async I/O approach, you would need to flip
> this around where the network layer says "I'm ready for more" and "pulls"
> content. Is my read on the situation correct?
> 
> If so, then I will venture a guess that we aren't going to be able to get
> Apache to an async model because of that ingrained "push" model.

I agree.  Apache 2.0 is not going to be async, and it doesn't need to
support it.  3.0 may be async.  It will require almost a complete re-write
if that is going to happen.  Take a look at the STATUS file, a re-org for
async is actually in there for post-2.0.  I do not want 2.0 to become a
kitchen sink again.  Adding async I/O to 2.0 is a bad idea and I will
fight it.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: Filter I/O take 3.

Posted by Greg Stein <gs...@lyra.org>.
At the moment, Apache is a "push" model, from the original content source,
down to the network layer. That is pretty ingrained into Apache's
architecture. I presume for an async I/O approach, you would need to flip
this around where the network layer says "I'm ready for more" and "pulls"
content. Is my read on the situation correct?

If so, then I will venture a guess that we aren't going to be able to get
Apache to an async model because of that ingrained "push" model.

Cheers,
-g

On Fri, Jun 16, 2000 at 09:59:16AM -0400, Bill Stoddard wrote:
> I haven't been following the debate closely so I may not understand all the details here,
> but I have a concern...
> 
> I strongly believe that making Apache do async network I/O is very important. It allows us
> to do the work of 1000's blocking threads with just a few threads. Will this patch make it
> substantially more difficult to cleanely implement async network i/o? I fear it does (with
> all the talk of allocating storage out of the stack, etc.)
> 
> Bill
> 
> ----- Original Message -----
> From: <rb...@covalent.net>
> To: <ne...@apache.org>
> Sent: Thursday, June 15, 2000 6:52 PM
> Subject: Filter I/O take 3.
> 
> 
> >
> > This patch enable filtering output.  I have not implemented input
> > filtering, because I believe it is trivial once we have the output
> > done.
> >
> > Issues resolved:
> >      Grouping filters by type
> >      allocating space on the stack or heap as appropriate
> >      memcpy'ing data that is never modified (not done anymore)
> >      Send headers after filters have sent the first block of data.
> >
> > Issues not resolved:
> >      Negative pushback from the network (there is a comment in the code
> > for how to implement this)
> >      Filters that only deal with half the data.  (the basic idea is there,
> > but it is not well tested.  Still working on this).
> >      cleanup the code:  some stuff just commented out until it can be
> > tested better.
> >      insert ap_run_insert_filters for sub_requests???  I'm not sure about
> > this.  Maybe we just want to inherit these.
> >      Others?  I know there are others, but I can't think of them right
> > now.
> >
> >
> > Patch
> > _____
> >
> > Index: src/include/ap_hooks.h
> > ===================================================================
> > RCS file: /home/cvs/apache-2.0/src/include/ap_hooks.h,v
> > retrieving revision 1.20
> > diff -u -d -b -w -u -r1.20 ap_hooks.h
> > --- src/include/ap_hooks.h 2000/05/27 22:53:46 1.20
> > +++ src/include/ap_hooks.h 2000/06/15 22:43:33
> > @@ -167,12 +167,153 @@
> >      return decline; \
> >      }
> >
> > +/* Set of Hook definitions designed to put the list of functions off a
> > + * pointer pre-defined in the request_rec.
> > + */
> > +#define AP_DECLARE_RHOOK(ret,name,args) \
> > +typedef ret HOOK_##name args; \
> > +API_EXPORT(void) ap_rhook_##name(HOOK_##name *pf,request_rec *r, \
> > +                                 const char * const *aszPre,\
> > +                  const char * const *aszSucc,int nOrder); \
> > +API_EXPORT(ret) ap_run_##name args; \
> > +typedef struct _LINK_##name \
> > +    { \
> > +    HOOK_##name *pFunc; \
> > +    const char *szName; \
> > +    const char * const *aszPredecessors; \
> > +    const char * const *aszSuccessors; \
> > +    int nOrder; \
> > +    } LINK_##name;
> > +
> > +#define AP_RHOOK_STRUCT(members) \
> > +struct { members } _hooks;
> > +
> > +#define AP_RHOOK_LINK(name) \
> > +    ap_array_header_t *link_##name;
> > +
> > +#define AP_IMPLEMENT_RHOOK_BASE(name) \
> > +API_EXPORT(void) ap_rhook_##name(HOOK_##name *pf,request_rec *r, \
> > +                                 const char * const *aszPre,\
> > +                  const char * const *aszSucc,int nOrder) \
> > +    { \
> > +    LINK_##name *pHook; \
> > +    if(!r->_hooks.link_##name) \
> > + { \
> > + r->_hooks.link_##name=ap_make_array(r->pool,1,sizeof(LINK_##name)); \
> > + ap_hook_sort_register(#name,&r->_hooks.link_##name); \
> > + } \
> > +    pHook=ap_push_array(r->_hooks.link_##name); \
> > +    pHook->pFunc=pf; \
> > +    pHook->aszPredecessors=aszPre; \
> > +    pHook->aszSuccessors=aszSucc; \
> > +    pHook->nOrder=nOrder; \
> > +    pHook->szName=ap_debug_module_name; \
> > +    if(ap_debug_module_hooks) \
> > + ap_show_hook(#name,aszPre,aszSucc); \
> > +    }
> > +
> > +/* RUN_ALL runs to the first one to return other than ok or decline
> > +   RUN_FIRST runs to the first one to return other than decline
> > +   VOID runs all
> > +*/
> > +
> > +#define AP_IMPLEMENT_RHOOK_VOID(name,args_decl,args_use) \
> > +AP_IMPLEMENT_RHOOK_BASE(name) \
> > +API_EXPORT(void) ap_run_##name args_decl \
> > +    { \
> > +    LINK_##name *pHook; \
> > +    int n; \
> > +\
> > +    if(!r->_hooks.link_##name) \
> > + return; \
> > +\
> > +    pHook=(LINK_##name *)r->_hooks.link_##name->elts; \
> > +    for(n=0 ; n < r->_hooks.link_##name->nelts ; ++n) \
> > + pHook[n].pFunc args_use; \
> > +    }
> > +
> > +/* FIXME: note that this returns ok when nothing is run. I suspect it should
> > +   really return decline, but that breaks Apache currently - Ben
> > +*/
> > +#define AP_IMPLEMENT_RHOOK_RUN_ALL(ret,name,args_decl,args_use,ok,decline) \
> > +AP_IMPLEMENT_RHOOK_BASE(name) \
> > +API_EXPORT(ret) ap_run_##name args_decl \
> > +    { \
> > +    LINK_##name *pHook; \
> > +    int n; \
> > +    ret rv; \
> > +\
> > +    if(!r->_hooks.link_##name) \
> > + return ok; \
> > +\
> > +    pHook=(LINK_##name *)r->_hooks.link_##name->elts; \
> > +    for(n=0 ; n < r->_hooks.link_##name->nelts ; ++n) \
> > + { \
> > + rv=pHook[n].pFunc args_use; \
> > +\
> > + if(rv != ok && rv != decline) \
> > +     return rv; \
> > + } \
> > +    return ok; \
> > +    }
> > +
> > +#define AP_IMPLEMENT_RHOOK_RUN_FIRST(ret,name,args_decl,args_use,decline) \
> > +AP_IMPLEMENT_RHOOK_BASE(name) \
> > +API_EXPORT(ret) ap_run_##name args_decl \
> > +    { \
> > +    LINK_##name *pHook; \
> > +    int n; \
> > +    ret rv; \
> > +\
> > +    if(!r->_hooks.link_##name) \
> > + return decline; \
> > +\
> > +    pHook=(LINK_##name *)r->_hooks.link_##name->elts; \
> > +    for(n=0 ; n < r->_hooks.link_##name->nelts ; ++n) \
> > + { \
> > + rv=pHook[n].pFunc args_use; \
> > +\
> > + if(rv != decline) \
> > +     return rv; \
> > + } \
> > +    return decline; \
> > +    }
> > +
> >       /* Hook orderings */
> >  #define AP_HOOK_REALLY_FIRST (-10)
> >  #define AP_HOOK_FIRST 0
> >  #define AP_HOOK_MIDDLE 10
> >  #define AP_HOOK_LAST 20
> >  #define AP_HOOK_REALLY_LAST 30
> > +
> > +/* I'm not sure if this is the right place for this or not, but it's a good
> > + * starting point.  This is the filter hooks ordering definitions.
> > + * The five classes are:
> > + *
> > + *    content-generators:
> > + *        These are ignored here, because all generators are implemented
> > + *        using handlers.
> > + *    content-filter/munger/processor:
> > + *        These are things like SSI, PHP, etc.  Anything that is likely
> > + *        to change the meaning of the data being sent.
> > + *    content-encoding:
> > + *        Something like gzip would go here.  Anything that changes the data,
> > + *        but not the meaning.
> > + *    digest/message processor:
> > + *        This would be something like mod_auth_digest.  Anything that
> > + *        changes header fields but not the content.
> > + *    transport encoding:
> > + *        This is where chuncking, SSL belong.  Anything that modifies the
> > + *        message for reasons related to the transport layer, but doesn't
> > + *        modify the meaning of the body.
> > + *
> > + * These filter types are called in the order the are listed above.
> > + */
> > +
> > +#define AP_HOOK_FILTER          0      /* content-filter/munger/processor */
> > +#define AP_HOOK_ENCODING       10      /* content-encoding */
> > +#define AP_HOOK_PROCESSOR      20      /* digest/message processor */
> > +#define AP_HOOK_TRANSPORT      30      /* transport-encoding */
> >
> >  extern API_VAR_EXPORT ap_pool_t *ap_global_hook_pool;
> >  extern API_VAR_EXPORT int ap_debug_module_hooks;
> > Index: src/include/http_request.h
> > ===================================================================
> > RCS file: /home/cvs/apache-2.0/src/include/http_request.h,v
> > retrieving revision 1.11
> > diff -u -d -b -w -u -r1.11 http_request.h
> > --- src/include/http_request.h 2000/05/27 22:53:47 1.11
> > +++ src/include/http_request.h 2000/06/15 22:43:34
> > @@ -120,6 +120,7 @@
> >  AP_DECLARE_HOOK(int,type_checker,(request_rec *))
> >  AP_DECLARE_HOOK(int,access_checker,(request_rec *))
> >  AP_DECLARE_HOOK(int,auth_checker,(request_rec *))
> > +AP_DECLARE_HOOK(void,insert_filter,(request_rec *))
> >
> >  #ifdef __cplusplus
> >  }
> > Index: src/include/httpd.h
> > ===================================================================
> > RCS file: /home/cvs/apache-2.0/src/include/httpd.h,v
> > retrieving revision 1.56
> > diff -u -d -b -w -u -r1.56 httpd.h
> > --- src/include/httpd.h 2000/06/09 21:19:47 1.56
> > +++ src/include/httpd.h 2000/06/15 22:43:44
> > @@ -81,6 +81,8 @@
> >  #include "apr_network_io.h"
> >  #include "buff.h"
> >  #include "ap_mmn.h"
> > +#include "ap_hooks.h"
> > +#include "ap_ioblock.h"
> >
> >  #ifdef HAVE_NETINET_IN_H
> >  #include <netinet/in.h>
> > @@ -598,6 +600,8 @@
> >      const char *short_name;
> >  };
> >
> > +AP_DECLARE_RHOOK(ap_ioqueue_t *, filter, (request_rec *r, ap_ioqueue_t *strs));
> > +
> >  struct request_rec {
> >
> >      ap_pool_t *pool;
> > @@ -615,6 +619,12 @@
> >   * pointer back to the main request.
> >   */
> >
> > +    AP_RHOOK_STRUCT (
> > +        AP_RHOOK_LINK(filter)   /* per-request filter I/O hook. */
> > +    );
> > +    ap_ioqueue_t **unfiltered_data; /* array of (ap_ioqueue_t *) that has
> > +                                         * not been filtered for */
> > +
> >      /* Info about the request itself... we begin with stuff that only
> >       * protocol.c should ever touch...
> >       */
> > @@ -662,6 +672,7 @@
> >      */
> >      int allowed; /* Allowed methods - for 405, OPTIONS, etc */
> >
> > +    int headers_sent;           /* have the headers been sent yet or not */
> >      int sent_bodyct; /* byte count in stream is for body */
> >      long bytes_sent; /* body byte count, for easy access */
> >      ap_time_t mtime; /* Time the resource was last modified */
> > Index: src/main/Makefile.in
> > ===================================================================
> > RCS file: /home/cvs/apache-2.0/src/main/Makefile.in,v
> > retrieving revision 1.12
> > diff -u -d -b -w -u -r1.12 Makefile.in
> > --- src/main/Makefile.in 2000/06/11 11:20:58 1.12
> > +++ src/main/Makefile.in 2000/06/15 22:43:50
> > @@ -8,7 +8,7 @@
> >   http_protocol.c http_request.c http_vhost.c util.c util_date.c \
> >   util_script.c util_uri.c util_md5.c util_cfgtree.c util_ebcdic.c \
> >   rfc1413.c http_connection.c iol_file.c listen.c mpm_common.c \
> > - util_charset.c
> > + util_charset.c ap_ioblock.c
> >
> >  include $(top_srcdir)/build/ltlib.mk
> >
> > Index: src/main/http_core.c
> > ===================================================================
> > RCS file: /home/cvs/apache-2.0/src/main/http_core.c,v
> > retrieving revision 1.74
> > diff -u -d -b -w -u -r1.74 http_core.c
> > --- src/main/http_core.c 2000/06/15 13:42:01 1.74
> > +++ src/main/http_core.c 2000/06/15 22:43:54
> > @@ -2628,8 +2628,8 @@
> >
> >   rangestatus = ap_set_byterange(r);
> >
> > - ap_send_http_header(r);
> > -
> > +/* ap_send_http_header(r);
> > +*/
> >   if (!r->header_only) {
> >       if (!rangestatus) {
> >   ap_send_fd(fd, r);
> > @@ -2671,8 +2671,8 @@
> >   }
> >
> >   rangestatus = ap_set_byterange(r);
> > - ap_send_http_header(r);
> > -
> > + /*ap_send_http_header(r);
> > + */
> >   if (!r->header_only) {
> >       if (!rangestatus) {
> >   ap_send_mmap(mm, r, 0, r->finfo.size);
> > Index: src/main/http_protocol.c
> > ===================================================================
> > RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v
> > retrieving revision 1.79
> > diff -u -d -b -w -u -r1.79 http_protocol.c
> > --- src/main/http_protocol.c 2000/06/12 23:02:49 1.79
> > +++ src/main/http_protocol.c 2000/06/15 22:44:05
> > @@ -96,6 +96,86 @@
> >            ap_bgetopt (r->connection->client, BO_BYTECT, &r->bytes_sent); \
> >    } while (0)
> >
> > +static int filter_io(request_rec *r, ap_ioqueue_t *iov)
> > +{
> > +    ap_ioblock_t *dptr = iov->head;
> > +    ap_ioqueue_t *unfiltered;
> > +#if 0
> > +    /* see below */
> > +    ap_size_t totlen = 0;
> > +#endif
> > +    int i, n;
> > +    int totsent = 0;
> > +    int rv;
> > +    int num_filters = r->_hooks.link_filter->nelts;
> > +
> > +    /* This should probably be done someplace else, but this will work for now.
> > +     */
> > +    if (r->unfiltered_data == NULL) {
> > +        r->unfiltered_data = ap_pcalloc(r->pool, num_filters *
> > +                                           sizeof(ap_ioqueue_t *));
> > +    }
> > +
> > +    for (i = 0; i < r->_hooks.link_filter->nelts; ++i) {
> > +        LINK_filter *hook;
> > +#if 0
> > +    /* Limit the amount of data sent to filters.  This logic needs to ensure
> > +     * we don't send too little or too much information.  I expect this will
> > +     * be added in the not too distant future.  Like days after the original
> > +     * filtered I/O patch.   rbb
> > +     */
> > +        while (dptr != iov->tail && (totlen < MAX_STRING_LEN)) {
> > +            totlen += dptr->len;
> > +            dptr = dptr->next;
> > +        }
> > +#endif
> > +
> > +        if (r->unfiltered_data[i] != NULL) {
> > +            ap_ioqueue_merge(r->unfiltered_data[i], iov);
> > +            iov = r->unfiltered_data[i];
> > +            r->unfiltered_data[i] = NULL;
> > +        }
> > +
> > +        hook = (LINK_filter *)r->_hooks.link_filter->elts;
> > +        unfiltered = hook[i].pFunc(r, iov);
> > +
> > +        /* unfiltered is the data that the filter didn't modify for one reason
> > +         * or another.  This has not been tested, but the theory is sound.
> > +         * I'll test this after I send the patch.  I expect to have this fully
> > +         * tested either before the commit or just after.
> > +         */
> > +        if (unfiltered != NULL) {
> > +            r->unfiltered_data[i] = unfiltered;
> > +        }
> > +    }
> > +
> > +    dptr = iov->head;
> > +
> > +    if (r->headers_sent != 1) {
> > +        /* We haven't sent any headers yet.  We had better do that before
> > +         * we try to send the body.
> > +         */
> > +        ap_send_http_header(r);
> > +    }
> > +
> > +    while (dptr != NULL) {
> > +        rv = ap_bwrite(r->connection->client, dptr->vec, dptr->len, &n);
> > +        if (n < 0) {
> > +            if (!r->connection->aborted) {
> > +                ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
> > +                    "client stopped connection before rwrite completed");
> > +                ap_bsetflag(r->connection->client, B_EOUT, 1);
> > +                r->connection->aborted = 1;
> > +            }
> > +            return EOF;
> > +        }
> > +        totsent += n;
> > +        dptr = dptr->next;
> > +    }
> > +    SET_BYTES_SENT(r);
> > +    return totsent;
> > +}
> > +
> >  /*
> >   * Builds the content-type that should be sent to the client from the
> >   * content-type specified.  The following rules are followed:
> > @@ -1394,7 +1474,8 @@
> >  API_EXPORT_NONSTD(int) ap_send_header_field(request_rec *r,
> >      const char *fieldname, const char *fieldval)
> >  {
> > -    return (0 < ap_rvputs(r, fieldname, ": ", fieldval, CRLF, NULL));
> > +    return (0 < ap_bvputs(r->connection->client, fieldname, ": ", fieldval,
> > +                          CRLF, NULL));
> >  }
> >
> >  API_EXPORT(void) ap_basic_http_header(request_rec *r)
> > @@ -1428,7 +1509,7 @@
> >
> >      /* Output the HTTP/1.x Status-Line and the Date and Server fields */
> >
> > -    ap_rvputs(r, protocol, " ", r->status_line, CRLF, NULL);
> > +    ap_bvputs(r->connection->client, protocol, " ", r->status_line, CRLF, NULL);
> >
> >      date = ap_palloc(r->pool, AP_RFC822_DATE_LEN);
> >      ap_rfc822_date(date, r->request_time);
> > @@ -1465,9 +1546,9 @@
> >
> >      ap_bgetopt(r->connection->client, BO_BYTECT, &bs);
> >      if (bs >= 255 && bs <= 257)
> > -        ap_rputs("X-Pad: avoid browser bug" CRLF, r);
> > +        ap_bputs("X-Pad: avoid browser bug" CRLF, r->connection->client);
> >
> > -    ap_rputs(CRLF, r);  /* Send the terminating empty line */
> > +    ap_bputs(CRLF, r->connection->client); /* Send the terminating empty line */
> >  }
> >
> >  /* Build the Allow field-value from the request handler method mask.
> > @@ -1734,6 +1815,10 @@
> >               (void *) r, r->headers_out, NULL);
> >
> >      terminate_header(r);
> > +    /* We have sent the headers once, we don't ever want to try to send them
> > +     * again.
> > +     */
> > +    r->headers_sent = 1;
> >
> >
> >      ap_bsetopt(r->connection->client, BO_BYTECT, &zero);
> > @@ -2216,7 +2301,7 @@
> >          o = 0;
> >
> >          while (n && !ap_is_aborted(r->connection)) {
> > -            rv = ap_bwrite(r->connection->client, &buf[o], n, &w);
> > +            w = ap_rwrite(&buf[o], n, r);
> >              if (w > 0) {
> >                  total_bytes_sent += w;
> >                  n -= w;
> > @@ -2347,13 +2432,11 @@
> >      size_t total_bytes_sent = 0;
> >      int n;
> >      ap_ssize_t w;
> > -    ap_status_t rv;
> >      char *addr;
> >
> >      if (length == 0)
> >          return 0;
> >
> > -
> >      length += offset;
> >      while (!r->connection->aborted && offset < length) {
> >          if (length - offset > MMAP_SEGMENT_SIZE) {
> > @@ -2365,25 +2448,12 @@
> >
> >          while (n && !r->connection->aborted) {
> >              ap_mmap_offset((void**)&addr, mm, offset);
> > -            rv = ap_bwrite(r->connection->client, addr, n, &w);
> > +            w = ap_rwrite(addr, n, r);
> >              if (w > 0) {
> >                  total_bytes_sent += w;
> >                  n -= w;
> >                  offset += w;
> >              }
> > -            else if (rv != APR_SUCCESS) {
> > -                if (r->connection->aborted)
> > -                    break;
> > -                else if (ap_canonical_error(rv) == APR_EAGAIN)
> > -                    continue;
> > -                else {
> > -                    ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
> > -                     "client stopped connection before send mmap completed");
> > -                    ap_bsetflag(r->connection->client, B_EOUT, 1);
> > -                    r->connection->aborted = 1;
> > -                    break;
> > -                }
> > -            }
> >          }
> >      }
> >
> > @@ -2397,6 +2467,8 @@
> >      if (r->connection->aborted)
> >          return EOF;
> >
> > +    filter_io(r, ap_create_ioqueue(r->pool, (const char *)&c, 1));
> > +
> >      if (ap_bputc(c, r->connection->client) < 0) {
> >          if (!r->connection->aborted) {
> >              ap_log_rerror(APLOG_MARK, APLOG_INFO,
> > @@ -2414,10 +2486,14 @@
> >  API_EXPORT(int) ap_rputs(const char *str, request_rec *r)
> >  {
> >      int rcode;
> > +    int len;
> >
> >      if (r->connection->aborted)
> >          return EOF;
> >
> > +    len = strlen(str);
> > +    filter_io(r, ap_create_ioqueue(r->pool, str, len));
> > +
> >      rcode = ap_bputs(str, r->connection->client);
> >      if (rcode < 0) {
> >          if (!r->connection->aborted) {
> > @@ -2435,73 +2511,40 @@
> >
> >  API_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r)
> >  {
> > -    ap_ssize_t n;
> > -    ap_status_t rv;
> > -
> >      if (r->connection->aborted)
> >          return EOF;
> >
> > -    rv = ap_bwrite(r->connection->client, buf, nbyte, &n);
> > -    if (n < 0) {
> > -        if (!r->connection->aborted) {
> > -            ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
> > -                "client stopped connection before rwrite completed");
> > -            ap_bsetflag(r->connection->client, B_EOUT, 1);
> > -            r->connection->aborted = 1;
> > -        }
> > -        return EOF;
> > -    }
> > -    SET_BYTES_SENT(r);
> > -    return n;
> > +    return filter_io(r, ap_create_ioqueue(r->pool, buf, nbyte));
> >  }
> >
> >  API_EXPORT(int) ap_vrprintf(request_rec *r, const char *fmt, va_list ap)
> >  {
> > -    int n;
> > +    int len;
> > +    char *str;
> >
> >      if (r->connection->aborted)
> >          return -1;
> > -
> > -    n = ap_vbprintf(r->connection->client, fmt, ap);
> >
> > -    if (n < 0) {
> > -        if (!r->connection->aborted) {
> > -            ap_log_rerror(APLOG_MARK, APLOG_INFO,
> > -                ap_berror(r->connection->client), r,
> > -                "client stopped connection before vrprintf completed");
> > -            ap_bsetflag(r->connection->client, B_EOUT, 1);
> > -            r->connection->aborted = 1;
> > -        }
> > -        return -1;
> > -    }
> > -    SET_BYTES_SENT(r);
> > -    return n;
> > +    str = ap_pvsprintf(r->pool, fmt, ap);
> > +    len = strlen(str);
> > +    return filter_io(r, ap_create_ioqueue(r->pool, str, len));
> >  }
> >
> >  API_EXPORT(int) ap_rprintf(request_rec *r, const char *fmt,...)
> >  {
> >      va_list vlist;
> >      int n;
> > +    char *str;
> >
> >      if (r->connection->aborted)
> >          return -1;
> >
> >      va_start(vlist, fmt);
> > -    n = ap_vbprintf(r->connection->client, fmt, vlist);
> > +    str = ap_pvsprintf(r->pool, fmt, vlist);
> >      va_end(vlist);
> >
> > -    if (n < 0) {
> > -        if (!r->connection->aborted) {
> > -            ap_log_rerror(APLOG_MARK, APLOG_INFO,
> > -                ap_berror(r->connection->client), r,
> > -                "client stopped connection before rprintf completed");
> > -            ap_bsetflag(r->connection->client, B_EOUT, 1);
> > -            r->connection->aborted = 1;
> > -        }
> > -        return -1;
> > -    }
> > -    SET_BYTES_SENT(r);
> > -    return n;
> > +    n = strlen(str);
> > +    return filter_io(r, ap_create_ioqueue(r->pool, str, n));
> >  }
> >
> >  API_EXPORT_NONSTD(int) ap_rvputs(request_rec *r,...)
> > @@ -2510,8 +2553,6 @@
> >      ap_ssize_t i;
> >      int j, k;
> >      const char *x;
> > -    BUFF *fb = r->connection->client;
> > -    ap_status_t rv;
> >
> >      if (r->connection->aborted)
> >          return EOF;
> > @@ -2522,8 +2563,11 @@
> >          if (x == NULL)
> >              break;
> >          j = strlen(x);
> > -        rv = ap_bwrite(fb, x, j, &i);
> > -        if (i != j) {
> > +
> > +        i = filter_io(r, ap_create_ioqueue(r->pool, x, j));
> > +
> > +/* I think this can be removed, but I am leaving this here until I am 100% sure.  rbb
> */
> > +/*        if (i != j) {
> >              va_end(args);
> >              if (!r->connection->aborted) {
> >                  ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
> > @@ -2532,7 +2576,7 @@
> >                  r->connection->aborted = 1;
> >              }
> >              return EOF;
> > -        }
> > +        }*/
> >          k += i;
> >      }
> >      va_end(args);
> > @@ -2609,7 +2653,7 @@
> >      }
> >
> >      if (status == HTTP_NO_CONTENT) {
> > -        ap_send_http_header(r);
> > +        /*ap_send_http_header(r);*/
> >          ap_finalize_request_protocol(r);
> >          return;
> >      }
> > @@ -2644,7 +2688,7 @@
> >          if ((status == METHOD_NOT_ALLOWED) || (status == NOT_IMPLEMENTED))
> >              ap_table_setn(r->headers_out, "Allow", make_allow(r));
> >
> > -        ap_send_http_header(r);
> > +        /*ap_send_http_header(r);*/
> >
> >          if (r->header_only) {
> >              ap_finalize_request_protocol(r);
> > @@ -2952,3 +2996,4 @@
> >                              (const request_rec *r),(r),NULL)
> >  AP_IMPLEMENT_HOOK_RUN_FIRST(unsigned short,default_port,
> >                              (const request_rec *r),(r),0)
> > +AP_IMPLEMENT_RHOOK_BASE(filter)
> > Index: src/main/http_request.c
> > ===================================================================
> > RCS file: /home/cvs/apache-2.0/src/main/http_request.c,v
> > retrieving revision 1.32
> > diff -u -d -b -w -u -r1.32 http_request.c
> > --- src/main/http_request.c 2000/06/12 15:28:53 1.32
> > +++ src/main/http_request.c 2000/06/15 22:44:10
> > @@ -68,6 +68,7 @@
> >
> >  #define CORE_PRIVATE
> >  #include "ap_config.h"
> > +#include "ap_hooks.h"
> >  #include "httpd.h"
> >  #include "http_config.h"
> >  #include "http_request.h"
> > @@ -86,6 +87,7 @@
> >       AP_HOOK_LINK(type_checker)
> >       AP_HOOK_LINK(access_checker)
> >       AP_HOOK_LINK(auth_checker)
> > +     AP_HOOK_LINK(insert_filter)
> >  )
> >
> >  AP_IMPLEMENT_HOOK_RUN_FIRST(int,translate_name,
> > @@ -100,6 +102,7 @@
> >                            (request_rec *r),(r),OK,DECLINED)
> >  AP_IMPLEMENT_HOOK_RUN_FIRST(int,auth_checker,
> >                              (request_rec *r),(r),DECLINED)
> > +AP_IMPLEMENT_HOOK_VOID(insert_filter, (request_rec *r), (r))
> >
> >  /*****************************************************************
> >   *
> > @@ -1246,6 +1249,15 @@
> >          ap_die(access_status, r);
> >          return;
> >      }
> > +
> > +    /* The new insert_filter stage makes sense here IMHO.  We are sure that
> > +     * we are going to run the request now, so we may as well insert filters
> > +     * if any are available.  Since the goal of this phase is to allow all
> > +     * modules to insert a filter if they want to, this filter returns
> > +     * void.  I just can't see any way that this filter can reasonably
> > +     * fail, either your modules inserts something or it doesn't.  rbb
> > +     */
> > +    ap_run_insert_filter(r);
> >
> >      if ((access_status = ap_invoke_handler(r)) != 0) {
> >          ap_die(access_status, r);
> >
> > New files:
> > _________
> >
> >
> > ap_ioblock.c:
> > -------------
> >
> > /* ====================================================================
> >  * The Apache Software License, Version 1.1
> >  *
> >  * Copyright (c) 2000 The Apache Software Foundation.  All rights
> >  * reserved.
> >  *
> >  * Redistribution and use in source and binary forms, with or without
> >  * modification, are permitted provided that the following conditions
> >  * are met:
> >  *
> >  * 1. Redistributions of source code must retain the above copyright
> >  *    notice, this list of conditions and the following disclaimer.
> >  *
> >  * 2. Redistributions in binary form must reproduce the above copyright
> >  *    notice, this list of conditions and the following disclaimer in
> >  *    the documentation and/or other materials provided with the
> >  *    distribution.
> >  *
> >  * 3. The end-user documentation included with the redistribution,
> >  *    if any, must include the following acknowledgment:
> >  *       "This product includes software developed by the
> >  *        Apache Software Foundation (http://www.apache.org/)."
> >  *    Alternately, this acknowledgment may appear in the software itself,
> >  *    if and wherever such third-party acknowledgments normally appear.
> >  *
> >  * 4. The names "Apache" and "Apache Software Foundation" must
> >  *    not be used to endorse or promote products derived from this
> >  *    software without prior written permission. For written
> >  *    permission, please contact apache@apache.org.
> >  *
> >  * 5. Products derived from this software may not be called "Apache",
> >  *    nor may "Apache" appear in their name, without prior written
> >  *    permission of the Apache Software Foundation.
> >  *
> >  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> >  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> >  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> >  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> >  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> >  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> >  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> >  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> >  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> >  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> >  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> >  * SUCH DAMAGE.
> >  * ====================================================================
> >  *
> >  * This software consists of voluntary contributions made by many
> >  * individuals on behalf of the Apache Software Foundation.  For more
> >  * information on the Apache Software Foundation, please see
> >  * <http://www.apache.org/>.
> >  *
> >  * This file was originally written by Ryan Bloom for Covalent Technologies
> >  * and gifted exclusively to the The Apache Software Foundation in June 2000.
> >  */
> >
> > #include "ap_ioblock.h"
> >
> > ap_ioblock_t *ap_create_ioblock(ap_pool_t *p, const void *v, int length)
> > {
> >     ap_ioblock_t *vector;
> >
> >     vector = ap_pcalloc(p, sizeof(*vector));
> >     vector->vec = (void *)v;
> >     vector->len = length;
> >     vector->bitmask = AP_NOT_WRITABLE;
> >
> >     return vector;
> > }
> >
> > ap_ioqueue_t *ap_start_ioqueue(ap_ioblock_t *b)
> > {
> >     ap_ioqueue_t *q;
> >
> >     q = ap_pcalloc(b->p, sizeof(*q));
> >     q->p = b->p;
> >     q->head = b;
> >     b->prev = NULL;
> >
> >     while (b->next != NULL) {
> >         b = b->next;
> >     }
> >     q->tail = b;
> >
> >     return q;
> > }
> >
> > ap_ioqueue_t *ap_create_ioqueue(ap_pool_t *p, const void *v, int length)
> > {
> >     ap_ioqueue_t *q;
> >
> >     q = ap_pcalloc(p, sizeof(*q));
> >     q->p = p;
> >     q->head = q->tail = ap_create_ioblock(q->p, v, length);
> >
> >     return q;
> > }
> >
> > ap_status_t ap_split_ioblock(ap_ioblock_t *vec, int offset)
> > {
> >     ap_ioblock_t *vector;
> >
> >     vector = ap_pcalloc(vec->p, sizeof(*vector));
> >     vector->p = vec->p;
> >
> >     vector->len = vec->len - offset;
> >     vec->len = offset;
> >     vector->vec = vec->vec + offset;
> >
> >     vector->next = vec->next;
> >     vector->prev = vec;
> >     vec->next = vector;
> >     vector->bitmask = vec->bitmask;
> >     return APR_SUCCESS;
> > }
> >
> > ap_ioblock_t *ap_add_ioblock(ap_ioblock_t *vec, const void *v, int length,
> >                            int front)
> > {
> >     ap_ioblock_t *vector = ap_create_ioblock(vec->p, v, length);
> >     ap_ioblock_t *dptr = vec;
> >
> >     if (front) {
> >         vector->next = vec;
> >         vec->prev = vector;
> >         return vector;
> >     }
> >     while (dptr->next) {
> >         dptr = dptr->next;
> >     }
> >     dptr->next = vector;
> >     vector->prev = dptr;
> >     return vec;
> > }
> >
> > ap_status_t ap_set_ioblock_writable(ap_ioblock_t *vec)
> > {
> >     if (vec->bitmask == AP_WRITABLE) {
> >         return APR_SUCCESS;
> >     }
> >     if (vec->bitmask == AP_NOT_WRITABLE) {
> >         void *v = ap_palloc(vec->p, vec->len);
> >         memcpy(v, vec->vec, vec->len);
> >         vec->vec = v;
> >         return APR_SUCCESS;
> >     }
> >     else return APR_ENOTIMPL;
> > }
> >
> > ap_ioqueue_t *ap_ioblock_enqueue(ap_ioqueue_t *vec, ap_ioblock_t *toadd)
> > {
> >     vec->tail->next = toadd;
> >     toadd->prev = vec->tail;
> >     vec->tail = toadd;
> >     return vec;
> > }
> >
> > ap_ioqueue_t *ap_ioqueue_merge(ap_ioqueue_t *vec, ap_ioqueue_t *toadd)
> > {
> >     vec->tail->next = toadd->head;
> >     toadd->head->prev = vec->tail;
> >     vec->tail = toadd->tail;
> >     return vec;
> > }
> >
> >
> > ap_ioblock.h:
> > -------------
> >
> > /* ====================================================================
> >  * The Apache Software License, Version 1.1
> >  *
> >  * Copyright (c) 2000 The Apache Software Foundation.  All rights
> >  * reserved.
> >  *
> >  * Redistribution and use in source and binary forms, with or without
> >  * modification, are permitted provided that the following conditions
> >  * are met:
> >  *
> >  * 1. Redistributions of source code must retain the above copyright
> >  *    notice, this list of conditions and the following disclaimer.
> >  *
> >  * 2. Redistributions in binary form must reproduce the above copyright
> >  *    notice, this list of conditions and the following disclaimer in
> >  *    the documentation and/or other materials provided with the
> >  *    distribution.
> >  *
> >  * 3. The end-user documentation included with the redistribution,
> >  *    if any, must include the following acknowledgment:
> >  *       "This product includes software developed by the
> >  *        Apache Software Foundation (http://www.apache.org/)."
> >  *    Alternately, this acknowledgment may appear in the software itself,
> >  *    if and wherever such third-party acknowledgments normally appear.
> >  *
> >  * 4. The names "Apache" and "Apache Software Foundation" must
> >  *    not be used to endorse or promote products derived from this
> >  *    software without prior written permission. For written
> >  *    permission, please contact apache@apache.org.
> >  *
> >  * 5. Products derived from this software may not be called "Apache",
> >  *    nor may "Apache" appear in their name, without prior written
> >  *    permission of the Apache Software Foundation.
> >  *
> >  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> >  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> >  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> >  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> >  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> >  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> >  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> >  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> >  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> >  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> >  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> >  * SUCH DAMAGE.
> >  * ====================================================================
> >  *
> >  * This software consists of voluntary contributions made by many
> >  * individuals on behalf of the Apache Software Foundation.  For more
> >  * information on the Apache Software Foundation, please see
> >  * <http://www.apache.org/>.
> >  *
> >  * This file was originally written by Ryan Bloom for Covalent Technologies
> >  * and gifted exclusively to the The Apache Software Foundation in June 2000.
> >  */
> >
> > #ifndef AP_IOBLOCK_H
> > #define AP_IOBLOCK_H
> >
> > #include "apr_pools.h"
> > #include "apr_file_io.h"
> > #include "ap_config.h"
> >
> > #define AP_WRITABLE            1
> > #define AP_NOT_WRITABLE        2
> > #define AP_FILE_DESC           4
> >
> > struct ap_ioblock_t {
> >     ap_pool_t *p;
> >     void *vec;
> >     int len;
> >     ap_file_t *fd;
> >     int bitmask;
> >     struct ap_ioblock_t *next;
> >     struct ap_ioblock_t *prev;
> > };
> >
> > struct ap_ioqueue_t {
> >     ap_pool_t *p;
> >     struct ap_ioblock_t *head;
> >     struct ap_ioblock_t *tail;
> > };
> >
> > typedef struct ap_ioblock_t ap_ioblock_t;
> > typedef struct ap_ioqueue_t ap_ioqueue_t;
> >
> > API_EXPORT(ap_ioblock_t *) ap_create_ioblock(ap_pool_t *p, const void *v,
> >                                            int length);
> > API_EXPORT(ap_status_t) ap_split_ioblock(ap_ioblock_t *vec, int offset);
> > API_EXPORT(ap_ioblock_t *) ap_add_ioblock(ap_ioblock_t *vec, const void *v,
> >                                         int length, int front);
> > API_EXPORT(ap_status_t) ap_set_ioblock_writable(ap_ioblock_t *vec);
> >
> > API_EXPORT(ap_ioqueue_t *) ap_start_ioqueue(ap_ioblock_t *b);
> > API_EXPORT(ap_ioqueue_t *) ap_create_ioqueue(ap_pool_t *p, const void *v,
> >                                            int length);
> > API_EXPORT(ap_ioqueue_t *) ap_ioblock_enqueue(ap_ioqueue_t *vec, ap_ioblock_t *toadd);
> > API_EXPORT(ap_ioqueue_t *) ap_ioqueue_merge(ap_ioqueue_t *vec, ap_ioqueue_t *toadd);
> >
> > #endif
> >
> >
> > mod_gargle.c:
> > -------------
> >
> > /* ====================================================================
> >  * The Apache Software License, Version 1.1
> >  *
> >  * Copyright (c) 2000 The Apache Software Foundation.  All rights
> >  * reserved.
> >  *
> >  * Redistribution and use in source and binary forms, with or without
> >  * modification, are permitted provided that the following conditions
> >  * are met:
> >  *
> >  * 1. Redistributions of source code must retain the above copyright
> >  *    notice, this list of conditions and the following disclaimer.
> >  *
> >  * 2. Redistributions in binary form must reproduce the above copyright
> >  *    notice, this list of conditions and the following disclaimer in
> >  *    the documentation and/or other materials provided with the
> >  *    distribution.
> >  *
> >  * 3. The end-user documentation included with the redistribution,
> >  *    if any, must include the following acknowledgment:
> >  *       "This product includes software developed by the
> >  *        Apache Software Foundation (http://www.apache.org/)."
> >  *    Alternately, this acknowledgment may appear in the software itself,
> >  *    if and wherever such third-party acknowledgments normally appear.
> >  *
> >  * 4. The names "Apache" and "Apache Software Foundation" must
> >  *    not be used to endorse or promote products derived from this
> >  *    software without prior written permission. For written
> >  *    permission, please contact apache@apache.org.
> >  *
> >  * 5. Products derived from this software may not be called "Apache",
> >  *    nor may "Apache" appear in their name, without prior written
> >  *    permission of the Apache Software Foundation.
> >  *
> >  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> >  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> >  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> >  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> >  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> >  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> >  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> >  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> >  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> >  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> >  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> >  * SUCH DAMAGE.
> >  * ====================================================================
> >  *
> >  * This software consists of voluntary contributions made by many
> >  * individuals on behalf of the Apache Software Foundation.  For more
> >  * information on the Apache Software Foundation, please see
> >  * <http://www.apache.org/>.
> >  *
> >  * Portions of this software are based upon public domain software
> >  * originally written at the National Center for Supercomputing Applications,
> >  * University of Illinois, Urbana-Champaign.
> >  */
> >
> > #include "httpd.h"
> > #include "ap_hooks.h"
> > #include "ap_ioblock.h"
> > #include "http_config.h"
> > #include "http_request.h"
> > #include "http_protocol.h"
> >
> > module MODULE_VAR_EXPORT gargle_module;
> >
> > typedef struct gargle_rec {
> >     int on;
> > } gargle_rec;
> >
> >
> > ap_ioqueue_t *gargle_filter(request_rec *r, ap_ioqueue_t *strs);
> >
> > static void *create_gargle_config(ap_pool_t *p, char *dummy)
> > {
> >     gargle_rec *new = (gargle_rec *) ap_pcalloc(p, sizeof(gargle_rec));
> >
> >     new->on = 0;
> >     return (void *)new;
> > }
> >
> > ap_ioqueue_t *gargle_filter(request_rec *r, ap_ioqueue_t *strs)
> > {
> >     static int dummy = 0;
> >     ap_ioblock_t *dptr = strs->head;
> >
> >     while (dptr != NULL) {
> >         if (dptr->len > 10) {
> >             ap_ioblock_t *temp;
> >
> >             ap_split_ioblock(dptr, 9);
> >             dptr = dptr->next;
> >             ap_split_ioblock(dptr, 1);
> >             ap_split_ioblock(dptr->next, 1);
> >
> >             temp = dptr->next;
> >             temp->prev = dptr->prev;
> >             dptr->next = temp->next;
> >             temp->next = dptr;
> >             dptr->prev->next = temp;
> >             dptr->prev = temp;
> >         }
> > #if 0
> >         if (dummy == 0) {
> >             ap_ioqueue_t *d2 = ap_start_ioqueue(dptr->next);
> >             dummy = 1;
> >             dptr->next = NULL;
> >             return d2;
> >         }
> > #endif
> >         dptr = dptr->next;
> >     }
> >     return NULL;
> > }
> >
> > static const char *gargle_on(cmd_parms *cmd, void *dummy, char *arg)
> > {
> >     gargle_rec *cfg = (gargle_rec *)dummy;
> >
> >     cfg->on = atoi(arg);
> >
> >     return NULL;
> > }
> >
> > static const command_rec gargle_cmds[] = {
> >     {"GargleIt", gargle_on, NULL, ACCESS_CONF, TAKE1,
> >      "should this request be gargled"},
> >     {NULL}
> > };
> >
> > static int gargle_insert_filter(request_rec *r)
> > {
> >     gargle_rec *cfg = (gargle_rec *)ap_get_module_config(r->per_dir_config,
> >                                                          &gargle_module);
> >
> >     if (cfg->on) {
> >         ap_rhook_filter(gargle_filter, r, NULL, NULL, AP_HOOK_FILTER);
> >     }
> >     return DECLINED;
> > }
> >
> > static void register_hooks(void)
> > {
> >     ap_hook_insert_filter(gargle_insert_filter, NULL, NULL, AP_HOOK_FILTER);
> > }
> >
> > module MODULE_VAR_EXPORT gargle_module =
> > {
> >     STANDARD20_MODULE_STUFF,
> >     create_gargle_config,     /* dir config creater */
> >     NULL,                     /* dir merger --- default is to override */
> >     NULL,                     /* server config */
> >     NULL,                     /* merge server config */
> >     gargle_cmds,              /* command ap_table_t */
> >     NULL,                     /* handlers */
> >     register_hooks            /* register hooks */
> > };
> >
> > _______________________________________________________________________________
> > Ryan Bloom                        rbb@apache.org
> > 406 29th St.
> > San Francisco, CA 94131
> > -------------------------------------------------------------------------------
> >
> >

-- 
Greg Stein, http://www.lyra.org/

Re: Filter I/O take 3.

Posted by Bill Stoddard <st...@raleigh.ibm.com>.
I haven't been following the debate closely so I may not understand all the details here,
but I have a concern...

I strongly believe that making Apache do async network I/O is very important. It allows us
to do the work of 1000's blocking threads with just a few threads. Will this patch make it
substantially more difficult to cleanely implement async network i/o? I fear it does (with
all the talk of allocating storage out of the stack, etc.)

Bill

----- Original Message -----
From: <rb...@covalent.net>
To: <ne...@apache.org>
Sent: Thursday, June 15, 2000 6:52 PM
Subject: Filter I/O take 3.


>
> This patch enable filtering output.  I have not implemented input
> filtering, because I believe it is trivial once we have the output
> done.
>
> Issues resolved:
>      Grouping filters by type
>      allocating space on the stack or heap as appropriate
>      memcpy'ing data that is never modified (not done anymore)
>      Send headers after filters have sent the first block of data.
>
> Issues not resolved:
>      Negative pushback from the network (there is a comment in the code
> for how to implement this)
>      Filters that only deal with half the data.  (the basic idea is there,
> but it is not well tested.  Still working on this).
>      cleanup the code:  some stuff just commented out until it can be
> tested better.
>      insert ap_run_insert_filters for sub_requests???  I'm not sure about
> this.  Maybe we just want to inherit these.
>      Others?  I know there are others, but I can't think of them right
> now.
>
>
> Patch
> _____
>
> Index: src/include/ap_hooks.h
> ===================================================================
> RCS file: /home/cvs/apache-2.0/src/include/ap_hooks.h,v
> retrieving revision 1.20
> diff -u -d -b -w -u -r1.20 ap_hooks.h
> --- src/include/ap_hooks.h 2000/05/27 22:53:46 1.20
> +++ src/include/ap_hooks.h 2000/06/15 22:43:33
> @@ -167,12 +167,153 @@
>      return decline; \
>      }
>
> +/* Set of Hook definitions designed to put the list of functions off a
> + * pointer pre-defined in the request_rec.
> + */
> +#define AP_DECLARE_RHOOK(ret,name,args) \
> +typedef ret HOOK_##name args; \
> +API_EXPORT(void) ap_rhook_##name(HOOK_##name *pf,request_rec *r, \
> +                                 const char * const *aszPre,\
> +                  const char * const *aszSucc,int nOrder); \
> +API_EXPORT(ret) ap_run_##name args; \
> +typedef struct _LINK_##name \
> +    { \
> +    HOOK_##name *pFunc; \
> +    const char *szName; \
> +    const char * const *aszPredecessors; \
> +    const char * const *aszSuccessors; \
> +    int nOrder; \
> +    } LINK_##name;
> +
> +#define AP_RHOOK_STRUCT(members) \
> +struct { members } _hooks;
> +
> +#define AP_RHOOK_LINK(name) \
> +    ap_array_header_t *link_##name;
> +
> +#define AP_IMPLEMENT_RHOOK_BASE(name) \
> +API_EXPORT(void) ap_rhook_##name(HOOK_##name *pf,request_rec *r, \
> +                                 const char * const *aszPre,\
> +                  const char * const *aszSucc,int nOrder) \
> +    { \
> +    LINK_##name *pHook; \
> +    if(!r->_hooks.link_##name) \
> + { \
> + r->_hooks.link_##name=ap_make_array(r->pool,1,sizeof(LINK_##name)); \
> + ap_hook_sort_register(#name,&r->_hooks.link_##name); \
> + } \
> +    pHook=ap_push_array(r->_hooks.link_##name); \
> +    pHook->pFunc=pf; \
> +    pHook->aszPredecessors=aszPre; \
> +    pHook->aszSuccessors=aszSucc; \
> +    pHook->nOrder=nOrder; \
> +    pHook->szName=ap_debug_module_name; \
> +    if(ap_debug_module_hooks) \
> + ap_show_hook(#name,aszPre,aszSucc); \
> +    }
> +
> +/* RUN_ALL runs to the first one to return other than ok or decline
> +   RUN_FIRST runs to the first one to return other than decline
> +   VOID runs all
> +*/
> +
> +#define AP_IMPLEMENT_RHOOK_VOID(name,args_decl,args_use) \
> +AP_IMPLEMENT_RHOOK_BASE(name) \
> +API_EXPORT(void) ap_run_##name args_decl \
> +    { \
> +    LINK_##name *pHook; \
> +    int n; \
> +\
> +    if(!r->_hooks.link_##name) \
> + return; \
> +\
> +    pHook=(LINK_##name *)r->_hooks.link_##name->elts; \
> +    for(n=0 ; n < r->_hooks.link_##name->nelts ; ++n) \
> + pHook[n].pFunc args_use; \
> +    }
> +
> +/* FIXME: note that this returns ok when nothing is run. I suspect it should
> +   really return decline, but that breaks Apache currently - Ben
> +*/
> +#define AP_IMPLEMENT_RHOOK_RUN_ALL(ret,name,args_decl,args_use,ok,decline) \
> +AP_IMPLEMENT_RHOOK_BASE(name) \
> +API_EXPORT(ret) ap_run_##name args_decl \
> +    { \
> +    LINK_##name *pHook; \
> +    int n; \
> +    ret rv; \
> +\
> +    if(!r->_hooks.link_##name) \
> + return ok; \
> +\
> +    pHook=(LINK_##name *)r->_hooks.link_##name->elts; \
> +    for(n=0 ; n < r->_hooks.link_##name->nelts ; ++n) \
> + { \
> + rv=pHook[n].pFunc args_use; \
> +\
> + if(rv != ok && rv != decline) \
> +     return rv; \
> + } \
> +    return ok; \
> +    }
> +
> +#define AP_IMPLEMENT_RHOOK_RUN_FIRST(ret,name,args_decl,args_use,decline) \
> +AP_IMPLEMENT_RHOOK_BASE(name) \
> +API_EXPORT(ret) ap_run_##name args_decl \
> +    { \
> +    LINK_##name *pHook; \
> +    int n; \
> +    ret rv; \
> +\
> +    if(!r->_hooks.link_##name) \
> + return decline; \
> +\
> +    pHook=(LINK_##name *)r->_hooks.link_##name->elts; \
> +    for(n=0 ; n < r->_hooks.link_##name->nelts ; ++n) \
> + { \
> + rv=pHook[n].pFunc args_use; \
> +\
> + if(rv != decline) \
> +     return rv; \
> + } \
> +    return decline; \
> +    }
> +
>       /* Hook orderings */
>  #define AP_HOOK_REALLY_FIRST (-10)
>  #define AP_HOOK_FIRST 0
>  #define AP_HOOK_MIDDLE 10
>  #define AP_HOOK_LAST 20
>  #define AP_HOOK_REALLY_LAST 30
> +
> +/* I'm not sure if this is the right place for this or not, but it's a good
> + * starting point.  This is the filter hooks ordering definitions.
> + * The five classes are:
> + *
> + *    content-generators:
> + *        These are ignored here, because all generators are implemented
> + *        using handlers.
> + *    content-filter/munger/processor:
> + *        These are things like SSI, PHP, etc.  Anything that is likely
> + *        to change the meaning of the data being sent.
> + *    content-encoding:
> + *        Something like gzip would go here.  Anything that changes the data,
> + *        but not the meaning.
> + *    digest/message processor:
> + *        This would be something like mod_auth_digest.  Anything that
> + *        changes header fields but not the content.
> + *    transport encoding:
> + *        This is where chuncking, SSL belong.  Anything that modifies the
> + *        message for reasons related to the transport layer, but doesn't
> + *        modify the meaning of the body.
> + *
> + * These filter types are called in the order the are listed above.
> + */
> +
> +#define AP_HOOK_FILTER          0      /* content-filter/munger/processor */
> +#define AP_HOOK_ENCODING       10      /* content-encoding */
> +#define AP_HOOK_PROCESSOR      20      /* digest/message processor */
> +#define AP_HOOK_TRANSPORT      30      /* transport-encoding */
>
>  extern API_VAR_EXPORT ap_pool_t *ap_global_hook_pool;
>  extern API_VAR_EXPORT int ap_debug_module_hooks;
> Index: src/include/http_request.h
> ===================================================================
> RCS file: /home/cvs/apache-2.0/src/include/http_request.h,v
> retrieving revision 1.11
> diff -u -d -b -w -u -r1.11 http_request.h
> --- src/include/http_request.h 2000/05/27 22:53:47 1.11
> +++ src/include/http_request.h 2000/06/15 22:43:34
> @@ -120,6 +120,7 @@
>  AP_DECLARE_HOOK(int,type_checker,(request_rec *))
>  AP_DECLARE_HOOK(int,access_checker,(request_rec *))
>  AP_DECLARE_HOOK(int,auth_checker,(request_rec *))
> +AP_DECLARE_HOOK(void,insert_filter,(request_rec *))
>
>  #ifdef __cplusplus
>  }
> Index: src/include/httpd.h
> ===================================================================
> RCS file: /home/cvs/apache-2.0/src/include/httpd.h,v
> retrieving revision 1.56
> diff -u -d -b -w -u -r1.56 httpd.h
> --- src/include/httpd.h 2000/06/09 21:19:47 1.56
> +++ src/include/httpd.h 2000/06/15 22:43:44
> @@ -81,6 +81,8 @@
>  #include "apr_network_io.h"
>  #include "buff.h"
>  #include "ap_mmn.h"
> +#include "ap_hooks.h"
> +#include "ap_ioblock.h"
>
>  #ifdef HAVE_NETINET_IN_H
>  #include <netinet/in.h>
> @@ -598,6 +600,8 @@
>      const char *short_name;
>  };
>
> +AP_DECLARE_RHOOK(ap_ioqueue_t *, filter, (request_rec *r, ap_ioqueue_t *strs));
> +
>  struct request_rec {
>
>      ap_pool_t *pool;
> @@ -615,6 +619,12 @@
>   * pointer back to the main request.
>   */
>
> +    AP_RHOOK_STRUCT (
> +        AP_RHOOK_LINK(filter)   /* per-request filter I/O hook. */
> +    );
> +    ap_ioqueue_t **unfiltered_data; /* array of (ap_ioqueue_t *) that has
> +                                         * not been filtered for */
> +
>      /* Info about the request itself... we begin with stuff that only
>       * protocol.c should ever touch...
>       */
> @@ -662,6 +672,7 @@
>      */
>      int allowed; /* Allowed methods - for 405, OPTIONS, etc */
>
> +    int headers_sent;           /* have the headers been sent yet or not */
>      int sent_bodyct; /* byte count in stream is for body */
>      long bytes_sent; /* body byte count, for easy access */
>      ap_time_t mtime; /* Time the resource was last modified */
> Index: src/main/Makefile.in
> ===================================================================
> RCS file: /home/cvs/apache-2.0/src/main/Makefile.in,v
> retrieving revision 1.12
> diff -u -d -b -w -u -r1.12 Makefile.in
> --- src/main/Makefile.in 2000/06/11 11:20:58 1.12
> +++ src/main/Makefile.in 2000/06/15 22:43:50
> @@ -8,7 +8,7 @@
>   http_protocol.c http_request.c http_vhost.c util.c util_date.c \
>   util_script.c util_uri.c util_md5.c util_cfgtree.c util_ebcdic.c \
>   rfc1413.c http_connection.c iol_file.c listen.c mpm_common.c \
> - util_charset.c
> + util_charset.c ap_ioblock.c
>
>  include $(top_srcdir)/build/ltlib.mk
>
> Index: src/main/http_core.c
> ===================================================================
> RCS file: /home/cvs/apache-2.0/src/main/http_core.c,v
> retrieving revision 1.74
> diff -u -d -b -w -u -r1.74 http_core.c
> --- src/main/http_core.c 2000/06/15 13:42:01 1.74
> +++ src/main/http_core.c 2000/06/15 22:43:54
> @@ -2628,8 +2628,8 @@
>
>   rangestatus = ap_set_byterange(r);
>
> - ap_send_http_header(r);
> -
> +/* ap_send_http_header(r);
> +*/
>   if (!r->header_only) {
>       if (!rangestatus) {
>   ap_send_fd(fd, r);
> @@ -2671,8 +2671,8 @@
>   }
>
>   rangestatus = ap_set_byterange(r);
> - ap_send_http_header(r);
> -
> + /*ap_send_http_header(r);
> + */
>   if (!r->header_only) {
>       if (!rangestatus) {
>   ap_send_mmap(mm, r, 0, r->finfo.size);
> Index: src/main/http_protocol.c
> ===================================================================
> RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v
> retrieving revision 1.79
> diff -u -d -b -w -u -r1.79 http_protocol.c
> --- src/main/http_protocol.c 2000/06/12 23:02:49 1.79
> +++ src/main/http_protocol.c 2000/06/15 22:44:05
> @@ -96,6 +96,86 @@
>            ap_bgetopt (r->connection->client, BO_BYTECT, &r->bytes_sent); \
>    } while (0)
>
> +static int filter_io(request_rec *r, ap_ioqueue_t *iov)
> +{
> +    ap_ioblock_t *dptr = iov->head;
> +    ap_ioqueue_t *unfiltered;
> +#if 0
> +    /* see below */
> +    ap_size_t totlen = 0;
> +#endif
> +    int i, n;
> +    int totsent = 0;
> +    int rv;
> +    int num_filters = r->_hooks.link_filter->nelts;
> +
> +    /* This should probably be done someplace else, but this will work for now.
> +     */
> +    if (r->unfiltered_data == NULL) {
> +        r->unfiltered_data = ap_pcalloc(r->pool, num_filters *
> +                                           sizeof(ap_ioqueue_t *));
> +    }
> +
> +    for (i = 0; i < r->_hooks.link_filter->nelts; ++i) {
> +        LINK_filter *hook;
> +#if 0
> +    /* Limit the amount of data sent to filters.  This logic needs to ensure
> +     * we don't send too little or too much information.  I expect this will
> +     * be added in the not too distant future.  Like days after the original
> +     * filtered I/O patch.   rbb
> +     */
> +        while (dptr != iov->tail && (totlen < MAX_STRING_LEN)) {
> +            totlen += dptr->len;
> +            dptr = dptr->next;
> +        }
> +#endif
> +
> +        if (r->unfiltered_data[i] != NULL) {
> +            ap_ioqueue_merge(r->unfiltered_data[i], iov);
> +            iov = r->unfiltered_data[i];
> +            r->unfiltered_data[i] = NULL;
> +        }
> +
> +        hook = (LINK_filter *)r->_hooks.link_filter->elts;
> +        unfiltered = hook[i].pFunc(r, iov);
> +
> +        /* unfiltered is the data that the filter didn't modify for one reason
> +         * or another.  This has not been tested, but the theory is sound.
> +         * I'll test this after I send the patch.  I expect to have this fully
> +         * tested either before the commit or just after.
> +         */
> +        if (unfiltered != NULL) {
> +            r->unfiltered_data[i] = unfiltered;
> +        }
> +    }
> +
> +    dptr = iov->head;
> +
> +    if (r->headers_sent != 1) {
> +        /* We haven't sent any headers yet.  We had better do that before
> +         * we try to send the body.
> +         */
> +        ap_send_http_header(r);
> +    }
> +
> +    while (dptr != NULL) {
> +        rv = ap_bwrite(r->connection->client, dptr->vec, dptr->len, &n);
> +        if (n < 0) {
> +            if (!r->connection->aborted) {
> +                ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
> +                    "client stopped connection before rwrite completed");
> +                ap_bsetflag(r->connection->client, B_EOUT, 1);
> +                r->connection->aborted = 1;
> +            }
> +            return EOF;
> +        }
> +        totsent += n;
> +        dptr = dptr->next;
> +    }
> +    SET_BYTES_SENT(r);
> +    return totsent;
> +}
> +
>  /*
>   * Builds the content-type that should be sent to the client from the
>   * content-type specified.  The following rules are followed:
> @@ -1394,7 +1474,8 @@
>  API_EXPORT_NONSTD(int) ap_send_header_field(request_rec *r,
>      const char *fieldname, const char *fieldval)
>  {
> -    return (0 < ap_rvputs(r, fieldname, ": ", fieldval, CRLF, NULL));
> +    return (0 < ap_bvputs(r->connection->client, fieldname, ": ", fieldval,
> +                          CRLF, NULL));
>  }
>
>  API_EXPORT(void) ap_basic_http_header(request_rec *r)
> @@ -1428,7 +1509,7 @@
>
>      /* Output the HTTP/1.x Status-Line and the Date and Server fields */
>
> -    ap_rvputs(r, protocol, " ", r->status_line, CRLF, NULL);
> +    ap_bvputs(r->connection->client, protocol, " ", r->status_line, CRLF, NULL);
>
>      date = ap_palloc(r->pool, AP_RFC822_DATE_LEN);
>      ap_rfc822_date(date, r->request_time);
> @@ -1465,9 +1546,9 @@
>
>      ap_bgetopt(r->connection->client, BO_BYTECT, &bs);
>      if (bs >= 255 && bs <= 257)
> -        ap_rputs("X-Pad: avoid browser bug" CRLF, r);
> +        ap_bputs("X-Pad: avoid browser bug" CRLF, r->connection->client);
>
> -    ap_rputs(CRLF, r);  /* Send the terminating empty line */
> +    ap_bputs(CRLF, r->connection->client); /* Send the terminating empty line */
>  }
>
>  /* Build the Allow field-value from the request handler method mask.
> @@ -1734,6 +1815,10 @@
>               (void *) r, r->headers_out, NULL);
>
>      terminate_header(r);
> +    /* We have sent the headers once, we don't ever want to try to send them
> +     * again.
> +     */
> +    r->headers_sent = 1;
>
>
>      ap_bsetopt(r->connection->client, BO_BYTECT, &zero);
> @@ -2216,7 +2301,7 @@
>          o = 0;
>
>          while (n && !ap_is_aborted(r->connection)) {
> -            rv = ap_bwrite(r->connection->client, &buf[o], n, &w);
> +            w = ap_rwrite(&buf[o], n, r);
>              if (w > 0) {
>                  total_bytes_sent += w;
>                  n -= w;
> @@ -2347,13 +2432,11 @@
>      size_t total_bytes_sent = 0;
>      int n;
>      ap_ssize_t w;
> -    ap_status_t rv;
>      char *addr;
>
>      if (length == 0)
>          return 0;
>
> -
>      length += offset;
>      while (!r->connection->aborted && offset < length) {
>          if (length - offset > MMAP_SEGMENT_SIZE) {
> @@ -2365,25 +2448,12 @@
>
>          while (n && !r->connection->aborted) {
>              ap_mmap_offset((void**)&addr, mm, offset);
> -            rv = ap_bwrite(r->connection->client, addr, n, &w);
> +            w = ap_rwrite(addr, n, r);
>              if (w > 0) {
>                  total_bytes_sent += w;
>                  n -= w;
>                  offset += w;
>              }
> -            else if (rv != APR_SUCCESS) {
> -                if (r->connection->aborted)
> -                    break;
> -                else if (ap_canonical_error(rv) == APR_EAGAIN)
> -                    continue;
> -                else {
> -                    ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
> -                     "client stopped connection before send mmap completed");
> -                    ap_bsetflag(r->connection->client, B_EOUT, 1);
> -                    r->connection->aborted = 1;
> -                    break;
> -                }
> -            }
>          }
>      }
>
> @@ -2397,6 +2467,8 @@
>      if (r->connection->aborted)
>          return EOF;
>
> +    filter_io(r, ap_create_ioqueue(r->pool, (const char *)&c, 1));
> +
>      if (ap_bputc(c, r->connection->client) < 0) {
>          if (!r->connection->aborted) {
>              ap_log_rerror(APLOG_MARK, APLOG_INFO,
> @@ -2414,10 +2486,14 @@
>  API_EXPORT(int) ap_rputs(const char *str, request_rec *r)
>  {
>      int rcode;
> +    int len;
>
>      if (r->connection->aborted)
>          return EOF;
>
> +    len = strlen(str);
> +    filter_io(r, ap_create_ioqueue(r->pool, str, len));
> +
>      rcode = ap_bputs(str, r->connection->client);
>      if (rcode < 0) {
>          if (!r->connection->aborted) {
> @@ -2435,73 +2511,40 @@
>
>  API_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r)
>  {
> -    ap_ssize_t n;
> -    ap_status_t rv;
> -
>      if (r->connection->aborted)
>          return EOF;
>
> -    rv = ap_bwrite(r->connection->client, buf, nbyte, &n);
> -    if (n < 0) {
> -        if (!r->connection->aborted) {
> -            ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
> -                "client stopped connection before rwrite completed");
> -            ap_bsetflag(r->connection->client, B_EOUT, 1);
> -            r->connection->aborted = 1;
> -        }
> -        return EOF;
> -    }
> -    SET_BYTES_SENT(r);
> -    return n;
> +    return filter_io(r, ap_create_ioqueue(r->pool, buf, nbyte));
>  }
>
>  API_EXPORT(int) ap_vrprintf(request_rec *r, const char *fmt, va_list ap)
>  {
> -    int n;
> +    int len;
> +    char *str;
>
>      if (r->connection->aborted)
>          return -1;
> -
> -    n = ap_vbprintf(r->connection->client, fmt, ap);
>
> -    if (n < 0) {
> -        if (!r->connection->aborted) {
> -            ap_log_rerror(APLOG_MARK, APLOG_INFO,
> -                ap_berror(r->connection->client), r,
> -                "client stopped connection before vrprintf completed");
> -            ap_bsetflag(r->connection->client, B_EOUT, 1);
> -            r->connection->aborted = 1;
> -        }
> -        return -1;
> -    }
> -    SET_BYTES_SENT(r);
> -    return n;
> +    str = ap_pvsprintf(r->pool, fmt, ap);
> +    len = strlen(str);
> +    return filter_io(r, ap_create_ioqueue(r->pool, str, len));
>  }
>
>  API_EXPORT(int) ap_rprintf(request_rec *r, const char *fmt,...)
>  {
>      va_list vlist;
>      int n;
> +    char *str;
>
>      if (r->connection->aborted)
>          return -1;
>
>      va_start(vlist, fmt);
> -    n = ap_vbprintf(r->connection->client, fmt, vlist);
> +    str = ap_pvsprintf(r->pool, fmt, vlist);
>      va_end(vlist);
>
> -    if (n < 0) {
> -        if (!r->connection->aborted) {
> -            ap_log_rerror(APLOG_MARK, APLOG_INFO,
> -                ap_berror(r->connection->client), r,
> -                "client stopped connection before rprintf completed");
> -            ap_bsetflag(r->connection->client, B_EOUT, 1);
> -            r->connection->aborted = 1;
> -        }
> -        return -1;
> -    }
> -    SET_BYTES_SENT(r);
> -    return n;
> +    n = strlen(str);
> +    return filter_io(r, ap_create_ioqueue(r->pool, str, n));
>  }
>
>  API_EXPORT_NONSTD(int) ap_rvputs(request_rec *r,...)
> @@ -2510,8 +2553,6 @@
>      ap_ssize_t i;
>      int j, k;
>      const char *x;
> -    BUFF *fb = r->connection->client;
> -    ap_status_t rv;
>
>      if (r->connection->aborted)
>          return EOF;
> @@ -2522,8 +2563,11 @@
>          if (x == NULL)
>              break;
>          j = strlen(x);
> -        rv = ap_bwrite(fb, x, j, &i);
> -        if (i != j) {
> +
> +        i = filter_io(r, ap_create_ioqueue(r->pool, x, j));
> +
> +/* I think this can be removed, but I am leaving this here until I am 100% sure.  rbb
*/
> +/*        if (i != j) {
>              va_end(args);
>              if (!r->connection->aborted) {
>                  ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
> @@ -2532,7 +2576,7 @@
>                  r->connection->aborted = 1;
>              }
>              return EOF;
> -        }
> +        }*/
>          k += i;
>      }
>      va_end(args);
> @@ -2609,7 +2653,7 @@
>      }
>
>      if (status == HTTP_NO_CONTENT) {
> -        ap_send_http_header(r);
> +        /*ap_send_http_header(r);*/
>          ap_finalize_request_protocol(r);
>          return;
>      }
> @@ -2644,7 +2688,7 @@
>          if ((status == METHOD_NOT_ALLOWED) || (status == NOT_IMPLEMENTED))
>              ap_table_setn(r->headers_out, "Allow", make_allow(r));
>
> -        ap_send_http_header(r);
> +        /*ap_send_http_header(r);*/
>
>          if (r->header_only) {
>              ap_finalize_request_protocol(r);
> @@ -2952,3 +2996,4 @@
>                              (const request_rec *r),(r),NULL)
>  AP_IMPLEMENT_HOOK_RUN_FIRST(unsigned short,default_port,
>                              (const request_rec *r),(r),0)
> +AP_IMPLEMENT_RHOOK_BASE(filter)
> Index: src/main/http_request.c
> ===================================================================
> RCS file: /home/cvs/apache-2.0/src/main/http_request.c,v
> retrieving revision 1.32
> diff -u -d -b -w -u -r1.32 http_request.c
> --- src/main/http_request.c 2000/06/12 15:28:53 1.32
> +++ src/main/http_request.c 2000/06/15 22:44:10
> @@ -68,6 +68,7 @@
>
>  #define CORE_PRIVATE
>  #include "ap_config.h"
> +#include "ap_hooks.h"
>  #include "httpd.h"
>  #include "http_config.h"
>  #include "http_request.h"
> @@ -86,6 +87,7 @@
>       AP_HOOK_LINK(type_checker)
>       AP_HOOK_LINK(access_checker)
>       AP_HOOK_LINK(auth_checker)
> +     AP_HOOK_LINK(insert_filter)
>  )
>
>  AP_IMPLEMENT_HOOK_RUN_FIRST(int,translate_name,
> @@ -100,6 +102,7 @@
>                            (request_rec *r),(r),OK,DECLINED)
>  AP_IMPLEMENT_HOOK_RUN_FIRST(int,auth_checker,
>                              (request_rec *r),(r),DECLINED)
> +AP_IMPLEMENT_HOOK_VOID(insert_filter, (request_rec *r), (r))
>
>  /*****************************************************************
>   *
> @@ -1246,6 +1249,15 @@
>          ap_die(access_status, r);
>          return;
>      }
> +
> +    /* The new insert_filter stage makes sense here IMHO.  We are sure that
> +     * we are going to run the request now, so we may as well insert filters
> +     * if any are available.  Since the goal of this phase is to allow all
> +     * modules to insert a filter if they want to, this filter returns
> +     * void.  I just can't see any way that this filter can reasonably
> +     * fail, either your modules inserts something or it doesn't.  rbb
> +     */
> +    ap_run_insert_filter(r);
>
>      if ((access_status = ap_invoke_handler(r)) != 0) {
>          ap_die(access_status, r);
>
> New files:
> _________
>
>
> ap_ioblock.c:
> -------------
>
> /* ====================================================================
>  * The Apache Software License, Version 1.1
>  *
>  * Copyright (c) 2000 The Apache Software Foundation.  All rights
>  * reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  *
>  * 1. Redistributions of source code must retain the above copyright
>  *    notice, this list of conditions and the following disclaimer.
>  *
>  * 2. Redistributions in binary form must reproduce the above copyright
>  *    notice, this list of conditions and the following disclaimer in
>  *    the documentation and/or other materials provided with the
>  *    distribution.
>  *
>  * 3. The end-user documentation included with the redistribution,
>  *    if any, must include the following acknowledgment:
>  *       "This product includes software developed by the
>  *        Apache Software Foundation (http://www.apache.org/)."
>  *    Alternately, this acknowledgment may appear in the software itself,
>  *    if and wherever such third-party acknowledgments normally appear.
>  *
>  * 4. The names "Apache" and "Apache Software Foundation" must
>  *    not be used to endorse or promote products derived from this
>  *    software without prior written permission. For written
>  *    permission, please contact apache@apache.org.
>  *
>  * 5. Products derived from this software may not be called "Apache",
>  *    nor may "Apache" appear in their name, without prior written
>  *    permission of the Apache Software Foundation.
>  *
>  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
>  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
>  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
>  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
>  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
>  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
>  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
>  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
>  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
>  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
>  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>  * SUCH DAMAGE.
>  * ====================================================================
>  *
>  * This software consists of voluntary contributions made by many
>  * individuals on behalf of the Apache Software Foundation.  For more
>  * information on the Apache Software Foundation, please see
>  * <http://www.apache.org/>.
>  *
>  * This file was originally written by Ryan Bloom for Covalent Technologies
>  * and gifted exclusively to the The Apache Software Foundation in June 2000.
>  */
>
> #include "ap_ioblock.h"
>
> ap_ioblock_t *ap_create_ioblock(ap_pool_t *p, const void *v, int length)
> {
>     ap_ioblock_t *vector;
>
>     vector = ap_pcalloc(p, sizeof(*vector));
>     vector->vec = (void *)v;
>     vector->len = length;
>     vector->bitmask = AP_NOT_WRITABLE;
>
>     return vector;
> }
>
> ap_ioqueue_t *ap_start_ioqueue(ap_ioblock_t *b)
> {
>     ap_ioqueue_t *q;
>
>     q = ap_pcalloc(b->p, sizeof(*q));
>     q->p = b->p;
>     q->head = b;
>     b->prev = NULL;
>
>     while (b->next != NULL) {
>         b = b->next;
>     }
>     q->tail = b;
>
>     return q;
> }
>
> ap_ioqueue_t *ap_create_ioqueue(ap_pool_t *p, const void *v, int length)
> {
>     ap_ioqueue_t *q;
>
>     q = ap_pcalloc(p, sizeof(*q));
>     q->p = p;
>     q->head = q->tail = ap_create_ioblock(q->p, v, length);
>
>     return q;
> }
>
> ap_status_t ap_split_ioblock(ap_ioblock_t *vec, int offset)
> {
>     ap_ioblock_t *vector;
>
>     vector = ap_pcalloc(vec->p, sizeof(*vector));
>     vector->p = vec->p;
>
>     vector->len = vec->len - offset;
>     vec->len = offset;
>     vector->vec = vec->vec + offset;
>
>     vector->next = vec->next;
>     vector->prev = vec;
>     vec->next = vector;
>     vector->bitmask = vec->bitmask;
>     return APR_SUCCESS;
> }
>
> ap_ioblock_t *ap_add_ioblock(ap_ioblock_t *vec, const void *v, int length,
>                            int front)
> {
>     ap_ioblock_t *vector = ap_create_ioblock(vec->p, v, length);
>     ap_ioblock_t *dptr = vec;
>
>     if (front) {
>         vector->next = vec;
>         vec->prev = vector;
>         return vector;
>     }
>     while (dptr->next) {
>         dptr = dptr->next;
>     }
>     dptr->next = vector;
>     vector->prev = dptr;
>     return vec;
> }
>
> ap_status_t ap_set_ioblock_writable(ap_ioblock_t *vec)
> {
>     if (vec->bitmask == AP_WRITABLE) {
>         return APR_SUCCESS;
>     }
>     if (vec->bitmask == AP_NOT_WRITABLE) {
>         void *v = ap_palloc(vec->p, vec->len);
>         memcpy(v, vec->vec, vec->len);
>         vec->vec = v;
>         return APR_SUCCESS;
>     }
>     else return APR_ENOTIMPL;
> }
>
> ap_ioqueue_t *ap_ioblock_enqueue(ap_ioqueue_t *vec, ap_ioblock_t *toadd)
> {
>     vec->tail->next = toadd;
>     toadd->prev = vec->tail;
>     vec->tail = toadd;
>     return vec;
> }
>
> ap_ioqueue_t *ap_ioqueue_merge(ap_ioqueue_t *vec, ap_ioqueue_t *toadd)
> {
>     vec->tail->next = toadd->head;
>     toadd->head->prev = vec->tail;
>     vec->tail = toadd->tail;
>     return vec;
> }
>
>
> ap_ioblock.h:
> -------------
>
> /* ====================================================================
>  * The Apache Software License, Version 1.1
>  *
>  * Copyright (c) 2000 The Apache Software Foundation.  All rights
>  * reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  *
>  * 1. Redistributions of source code must retain the above copyright
>  *    notice, this list of conditions and the following disclaimer.
>  *
>  * 2. Redistributions in binary form must reproduce the above copyright
>  *    notice, this list of conditions and the following disclaimer in
>  *    the documentation and/or other materials provided with the
>  *    distribution.
>  *
>  * 3. The end-user documentation included with the redistribution,
>  *    if any, must include the following acknowledgment:
>  *       "This product includes software developed by the
>  *        Apache Software Foundation (http://www.apache.org/)."
>  *    Alternately, this acknowledgment may appear in the software itself,
>  *    if and wherever such third-party acknowledgments normally appear.
>  *
>  * 4. The names "Apache" and "Apache Software Foundation" must
>  *    not be used to endorse or promote products derived from this
>  *    software without prior written permission. For written
>  *    permission, please contact apache@apache.org.
>  *
>  * 5. Products derived from this software may not be called "Apache",
>  *    nor may "Apache" appear in their name, without prior written
>  *    permission of the Apache Software Foundation.
>  *
>  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
>  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
>  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
>  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
>  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
>  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
>  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
>  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
>  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
>  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
>  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>  * SUCH DAMAGE.
>  * ====================================================================
>  *
>  * This software consists of voluntary contributions made by many
>  * individuals on behalf of the Apache Software Foundation.  For more
>  * information on the Apache Software Foundation, please see
>  * <http://www.apache.org/>.
>  *
>  * This file was originally written by Ryan Bloom for Covalent Technologies
>  * and gifted exclusively to the The Apache Software Foundation in June 2000.
>  */
>
> #ifndef AP_IOBLOCK_H
> #define AP_IOBLOCK_H
>
> #include "apr_pools.h"
> #include "apr_file_io.h"
> #include "ap_config.h"
>
> #define AP_WRITABLE            1
> #define AP_NOT_WRITABLE        2
> #define AP_FILE_DESC           4
>
> struct ap_ioblock_t {
>     ap_pool_t *p;
>     void *vec;
>     int len;
>     ap_file_t *fd;
>     int bitmask;
>     struct ap_ioblock_t *next;
>     struct ap_ioblock_t *prev;
> };
>
> struct ap_ioqueue_t {
>     ap_pool_t *p;
>     struct ap_ioblock_t *head;
>     struct ap_ioblock_t *tail;
> };
>
> typedef struct ap_ioblock_t ap_ioblock_t;
> typedef struct ap_ioqueue_t ap_ioqueue_t;
>
> API_EXPORT(ap_ioblock_t *) ap_create_ioblock(ap_pool_t *p, const void *v,
>                                            int length);
> API_EXPORT(ap_status_t) ap_split_ioblock(ap_ioblock_t *vec, int offset);
> API_EXPORT(ap_ioblock_t *) ap_add_ioblock(ap_ioblock_t *vec, const void *v,
>                                         int length, int front);
> API_EXPORT(ap_status_t) ap_set_ioblock_writable(ap_ioblock_t *vec);
>
> API_EXPORT(ap_ioqueue_t *) ap_start_ioqueue(ap_ioblock_t *b);
> API_EXPORT(ap_ioqueue_t *) ap_create_ioqueue(ap_pool_t *p, const void *v,
>                                            int length);
> API_EXPORT(ap_ioqueue_t *) ap_ioblock_enqueue(ap_ioqueue_t *vec, ap_ioblock_t *toadd);
> API_EXPORT(ap_ioqueue_t *) ap_ioqueue_merge(ap_ioqueue_t *vec, ap_ioqueue_t *toadd);
>
> #endif
>
>
> mod_gargle.c:
> -------------
>
> /* ====================================================================
>  * The Apache Software License, Version 1.1
>  *
>  * Copyright (c) 2000 The Apache Software Foundation.  All rights
>  * reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  *
>  * 1. Redistributions of source code must retain the above copyright
>  *    notice, this list of conditions and the following disclaimer.
>  *
>  * 2. Redistributions in binary form must reproduce the above copyright
>  *    notice, this list of conditions and the following disclaimer in
>  *    the documentation and/or other materials provided with the
>  *    distribution.
>  *
>  * 3. The end-user documentation included with the redistribution,
>  *    if any, must include the following acknowledgment:
>  *       "This product includes software developed by the
>  *        Apache Software Foundation (http://www.apache.org/)."
>  *    Alternately, this acknowledgment may appear in the software itself,
>  *    if and wherever such third-party acknowledgments normally appear.
>  *
>  * 4. The names "Apache" and "Apache Software Foundation" must
>  *    not be used to endorse or promote products derived from this
>  *    software without prior written permission. For written
>  *    permission, please contact apache@apache.org.
>  *
>  * 5. Products derived from this software may not be called "Apache",
>  *    nor may "Apache" appear in their name, without prior written
>  *    permission of the Apache Software Foundation.
>  *
>  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
>  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
>  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
>  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
>  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
>  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
>  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
>  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
>  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
>  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
>  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>  * SUCH DAMAGE.
>  * ====================================================================
>  *
>  * This software consists of voluntary contributions made by many
>  * individuals on behalf of the Apache Software Foundation.  For more
>  * information on the Apache Software Foundation, please see
>  * <http://www.apache.org/>.
>  *
>  * Portions of this software are based upon public domain software
>  * originally written at the National Center for Supercomputing Applications,
>  * University of Illinois, Urbana-Champaign.
>  */
>
> #include "httpd.h"
> #include "ap_hooks.h"
> #include "ap_ioblock.h"
> #include "http_config.h"
> #include "http_request.h"
> #include "http_protocol.h"
>
> module MODULE_VAR_EXPORT gargle_module;
>
> typedef struct gargle_rec {
>     int on;
> } gargle_rec;
>
>
> ap_ioqueue_t *gargle_filter(request_rec *r, ap_ioqueue_t *strs);
>
> static void *create_gargle_config(ap_pool_t *p, char *dummy)
> {
>     gargle_rec *new = (gargle_rec *) ap_pcalloc(p, sizeof(gargle_rec));
>
>     new->on = 0;
>     return (void *)new;
> }
>
> ap_ioqueue_t *gargle_filter(request_rec *r, ap_ioqueue_t *strs)
> {
>     static int dummy = 0;
>     ap_ioblock_t *dptr = strs->head;
>
>     while (dptr != NULL) {
>         if (dptr->len > 10) {
>             ap_ioblock_t *temp;
>
>             ap_split_ioblock(dptr, 9);
>             dptr = dptr->next;
>             ap_split_ioblock(dptr, 1);
>             ap_split_ioblock(dptr->next, 1);
>
>             temp = dptr->next;
>             temp->prev = dptr->prev;
>             dptr->next = temp->next;
>             temp->next = dptr;
>             dptr->prev->next = temp;
>             dptr->prev = temp;
>         }
> #if 0
>         if (dummy == 0) {
>             ap_ioqueue_t *d2 = ap_start_ioqueue(dptr->next);
>             dummy = 1;
>             dptr->next = NULL;
>             return d2;
>         }
> #endif
>         dptr = dptr->next;
>     }
>     return NULL;
> }
>
> static const char *gargle_on(cmd_parms *cmd, void *dummy, char *arg)
> {
>     gargle_rec *cfg = (gargle_rec *)dummy;
>
>     cfg->on = atoi(arg);
>
>     return NULL;
> }
>
> static const command_rec gargle_cmds[] = {
>     {"GargleIt", gargle_on, NULL, ACCESS_CONF, TAKE1,
>      "should this request be gargled"},
>     {NULL}
> };
>
> static int gargle_insert_filter(request_rec *r)
> {
>     gargle_rec *cfg = (gargle_rec *)ap_get_module_config(r->per_dir_config,
>                                                          &gargle_module);
>
>     if (cfg->on) {
>         ap_rhook_filter(gargle_filter, r, NULL, NULL, AP_HOOK_FILTER);
>     }
>     return DECLINED;
> }
>
> static void register_hooks(void)
> {
>     ap_hook_insert_filter(gargle_insert_filter, NULL, NULL, AP_HOOK_FILTER);
> }
>
> module MODULE_VAR_EXPORT gargle_module =
> {
>     STANDARD20_MODULE_STUFF,
>     create_gargle_config,     /* dir config creater */
>     NULL,                     /* dir merger --- default is to override */
>     NULL,                     /* server config */
>     NULL,                     /* merge server config */
>     gargle_cmds,              /* command ap_table_t */
>     NULL,                     /* handlers */
>     register_hooks            /* register hooks */
> };
>
> _______________________________________________________________________________
> Ryan Bloom                        rbb@apache.org
> 406 29th St.
> San Francisco, CA 94131
> -------------------------------------------------------------------------------
>
>


async IO (was: Re: Filter I/O take 3.)

Posted by Greg Stein <gs...@lyra.org>.
On Fri, Jun 16, 2000 at 05:41:11PM -0700, Marc Slemko wrote:
> On Fri, 16 Jun 2000, Greg Stein wrote:
> 
> > Async I/O would be nice, but it just won't be happening in Apache any time
> > soon or far. I really don't think we can start saying "well, if that doesn't
> > support async, then it is out." By that rule, we could hardly make any
> > changes :-)
> > 
> > I'd love to be educated on how to change Apache to an async model. I just
> > don't see it right now.
> 
> Sorry for the previous empty message, my thinkpad sucks.
> 
> Anyway, why not make it use async IO only for things served by the default
> handler, ie. static content?  Nothing is stopping you from optimizing
> default content while still sticking with the same old way for anything
> harder.

Agreed. That was basically my comment "well, some stuff could signal that
they can handle async IO." And yah: we'd start with the default handlers :-)

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Filter I/O take 3.

Posted by Marc Slemko <ma...@go2net.com>.

On Fri, 16 Jun 2000, Greg Stein wrote:

> On Fri, Jun 16, 2000 at 10:07:50AM -0400, Bill Stoddard wrote:
> > > >...
> > > > If you have a veto, please speak up within 24 hours.  I will be flying to
> > > > NH tomorrow, and I will likely commit as soon as I get back to the hotel
> > > > after dinner, unless there is a veto pending.
> > > 
> > > -1 until it is apparent how the following can be done: flow control, large
> > > filtered content, and sub-requests. (more detail in the other note)
> > > 
> > And async network i/o
> 
> Async I/O would be nice, but it just won't be happening in Apache any time
> soon or far. I really don't think we can start saying "well, if that doesn't
> support async, then it is out." By that rule, we could hardly make any
> changes :-)
> 
> I'd love to be educated on how to change Apache to an async model. I just
> don't see it right now.
> 
> Cheers,
> -g
> 
> -- 
> Greg Stein, http://www.lyra.org/
> 


Re: Filter I/O take 3.

Posted by rb...@covalent.net.
> Yes, exactly my thinking. And we do not expose this to the general
> Apache API either. We
> are having this discussion about hacking into Apache a filter API and I
> question it's
> usefulness. I've had people ask for it here at IBM, but in general,
> there are always other
> ways to accomplish what they are trying to accomplish.

Considering this is one of the most asked for things in Apache, I think it
is VERY useful.

> IMO, getting async network reads into the default handlers is much more
> valuable than
> filtered i/o (okay, someone shoot me if I am mistaken). At ApacheCon
> 98, Filo clearly
> stated scalability was #1 on his requirement list. I think the same is
> true for anyone
> running a large sites and async i/o is the way to get there.

It really doesn't matter if async is the way to get there or not.  Async
is really almost impossible in the 2.0 server.  This really requires a
re-write of Apache.  This is a 3.0 thing.

Regardless, I am having a hard time seeing how filtering the data really
affects async I/O.  The place to make things async is as we are sending
them out on the wire.  We are modifying the data that is going to be
sent.  Filters are one level above async.

Plus, if there is no filter installed, there is no performance hit at all
with any of the filter proposals.

I am -1 for even thinking about trying to get async I/O into the 2.0
server.  I am also -1 for holding up other features because they do not
fit with async.  When 3.0 is a reality and we have async I/O, there will
be new possabilities for filtering.  This is not the current case.  I
would hate to hold up development just because something is possible in
the future.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: Filter I/O take 3.

Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> On Fri, 16 Jun 2000, Greg Stein wrote:
>
> > Async I/O would be nice, but it just won't be happening in Apache any time
> > soon or far. I really don't think we can start saying "well, if that doesn't
> > support async, then it is out." By that rule, we could hardly make any
> > changes :-)
> >
> > I'd love to be educated on how to change Apache to an async model. I just
> > don't see it right now.
>
> Sorry for the previous empty message, my thinkpad sucks.
>
> Anyway, why not make it use async IO only for things served by the default
> handler, ie. static content?  Nothing is stopping you from optimizing
> default content while still sticking with the same old way for anything
> harder.
>
> Or just a big select() loop w/nonblocking IO.
>

Yes, exactly my thinking. And we do not expose this to the general Apache API either. We
are having this discussion about hacking into Apache a filter API and I question it's
usefulness. I've had people ask for it here at IBM, but in general, there are always other
ways to accomplish what they are trying to accomplish.

IMO, getting async network reads into the default handlers is much more valuable than
filtered i/o (okay, someone shoot me if I am mistaken). At ApacheCon 98, Filo clearly
stated scalability was #1 on his requirement list. I think the same is true for anyone
running a large sites and async i/o is the way to get there.

Bill


Re: Filter I/O take 3.

Posted by Marc Slemko <ma...@znep.com>.
On Fri, 16 Jun 2000, Greg Stein wrote:

> Async I/O would be nice, but it just won't be happening in Apache any time
> soon or far. I really don't think we can start saying "well, if that doesn't
> support async, then it is out." By that rule, we could hardly make any
> changes :-)
> 
> I'd love to be educated on how to change Apache to an async model. I just
> don't see it right now.

Sorry for the previous empty message, my thinkpad sucks.

Anyway, why not make it use async IO only for things served by the default
handler, ie. static content?  Nothing is stopping you from optimizing
default content while still sticking with the same old way for anything
harder.

Or just a big select() loop w/nonblocking IO.


Re: Filter I/O take 3.

Posted by Greg Stein <gs...@lyra.org>.
On Fri, Jun 16, 2000 at 10:07:50AM -0400, Bill Stoddard wrote:
> > >...
> > > If you have a veto, please speak up within 24 hours.  I will be flying to
> > > NH tomorrow, and I will likely commit as soon as I get back to the hotel
> > > after dinner, unless there is a veto pending.
> > 
> > -1 until it is apparent how the following can be done: flow control, large
> > filtered content, and sub-requests. (more detail in the other note)
> > 
> And async network i/o

Async I/O would be nice, but it just won't be happening in Apache any time
soon or far. I really don't think we can start saying "well, if that doesn't
support async, then it is out." By that rule, we could hardly make any
changes :-)

I'd love to be educated on how to change Apache to an async model. I just
don't see it right now.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Filter I/O take 3.

Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> >...
> > If you have a veto, please speak up within 24 hours.  I will be flying to
> > NH tomorrow, and I will likely commit as soon as I get back to the hotel
> > after dinner, unless there is a veto pending.
> 
> -1 until it is apparent how the following can be done: flow control, large
> filtered content, and sub-requests. (more detail in the other note)
> 
And async network i/o

Bill


Re: Filter I/O take 3.

Posted by Greg Stein <gs...@lyra.org>.
On Thu, Jun 15, 2000 at 03:59:37PM -0700, rbb@covalent.net wrote:
>...
> I would like to commit this in about 24 hours.  We have discussed this
> concept before, and I believe this patch handlers (or is capable with a
> few lines of code) every major issue that has been raised.

I'm really sorry, but I just don't see how a few, key things are going to
work in this scheme. I listed those in my response to the original note.

>...
> If you have a veto, please speak up within 24 hours.  I will be flying to
> NH tomorrow, and I will likely commit as soon as I get back to the hotel
> after dinner, unless there is a veto pending.

-1 until it is apparent how the following can be done: flow control, large
filtered content, and sub-requests. (more detail in the other note)

I'll do some work on common items first, then put together an alternative
patch.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Filter I/O take 3.

Posted by rb...@covalent.net.
I wanted this in a separate message so it didn't get lost in all the text
of the patch.

I would like to commit this in about 24 hours.  We have discussed this
concept before, and I believe this patch handlers (or is capable with a
few lines of code) every major issue that has been raised.  I see no real
reason to drag on the debate again.

If you have a veto, please speak up within 24 hours.  I will be flying to
NH tomorrow, and I will likely commit as soon as I get back to the hotel
after dinner, unless there is a veto pending.

Ryan


On Thu, 15 Jun 2000 rbb@covalent.net wrote:

> 
> This patch enable filtering output.  I have not implemented input
> filtering, because I believe it is trivial once we have the output
> done.
> 
> Issues resolved:
>      Grouping filters by type
>      allocating space on the stack or heap as appropriate
>      memcpy'ing data that is never modified (not done anymore)
>      Send headers after filters have sent the first block of data.
> 
> Issues not resolved:
>      Negative pushback from the network (there is a comment in the code
> for how to implement this)
>      Filters that only deal with half the data.  (the basic idea is there,
> but it is not well tested.  Still working on this).
>      cleanup the code:  some stuff just commented out until it can be
> tested better.
>      insert ap_run_insert_filters for sub_requests???  I'm not sure about
> this.  Maybe we just want to inherit these.
>      Others?  I know there are others, but I can't think of them right
> now.


_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------