httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Stein <gst...@lyra.org>
Subject Re: I/O filtering in 2.0
Date Fri, 14 Apr 2000 20:13:14 GMT
On Fri, 14 Apr 2000 rbb@covalent.net wrote:
>...
> --- src/main/http_protocol.c	2000/04/14 15:58:56	1.61
> +++ src/main/http_protocol.c	2000/04/14 18:53:44
> @@ -83,6 +83,7 @@
>  	    HOOK_LINK(log_transaction)
>  	    HOOK_LINK(http_method)
>  	    HOOK_LINK(default_port)
> +	    HOOK_LINK(filter)
>  )
>  
>  #define SET_BYTES_SENT(r) \
> @@ -2114,8 +2115,8 @@
>          o = 0;
>  
>          while (n && !ap_is_aborted(r->connection)) {
> -            rv = ap_bwrite(r->connection->client, &buf[o], n, &w);
> -            if (w > 0) {
> +            rv = ap_rwrite(&buf[o], n, r);
> +/*            if (w > 0) {
>                  total_bytes_sent += w;
>                  n -= w;
>                  o += w;
> @@ -2128,7 +2129,7 @@
>                      r->connection->aborted = 1;
>                  }
>                  break;
> -            }
> +            }*/
>          }
>      }
>  
> @@ -2239,6 +2240,7 @@
>      ap_ssize_t w;
>      ap_status_t rv;
>      char *addr;
> +    char *copy;
>      
>      if (length == 0)
>          return 0;
> @@ -2255,13 +2257,15 @@
>  
>          while (n && !r->connection->aborted) {
>              ap_mmap_offset((void**)&addr, mm, offset);
> -            rv = ap_bwrite(r->connection->client, addr, n, &w);
> +            copy = ap_pcalloc(r->pool, n); 
> +            ap_cpystrn(copy, addr, n); 

Use memcpy() not ap_cpystrn(). The latter is only for strings. Whenever
you know the length of the input, string or not, then memcpy() should be
used. It will always be faster.

> +            w = ap_rwrite(copy, n, r);
>              if (w > 0) {
>                  total_bytes_sent += w;

Why this total_bytes_sent management, but not for the ap_rwrite() change
in ap_send_fb_lengt() ?

>                  n -= w;
>                  offset += w;
>              }
> -            else if (rv != APR_SUCCESS) {
> +/*            else if (rv != APR_SUCCESS) {
>                  if (r->connection->aborted)
>                      break;
>                  else if (rv == EAGAIN)
> @@ -2273,7 +2277,7 @@
>                      r->connection->aborted = 1;
>                      break;
>                  }
> -            }
> +            } */
>          }
>      }
>  
> @@ -2287,6 +2291,8 @@
>      if (r->connection->aborted)
>          return EOF;
>  
> +    ap_run_filter(r, (char *)&c, 1);
> +
>      if (ap_bputc(c, r->connection->client) < 0) {
>          if (!r->connection->aborted) {
>              ap_log_rerror(APLOG_MARK, APLOG_INFO,
> @@ -2308,6 +2314,8 @@
>      if (r->connection->aborted)
>          return EOF;
>      
> +    ap_run_filter(r, (char *)str, strlen(str));

Can't do this. The string that was passed to us is marked "const". It may
really be a const!

static const char * const signature = "gooblefarg";
...
   ap_rputs(signature, r);


> +
>      rcode = ap_bputs(str, r->connection->client);
>      if (rcode < 0) {
>          if (!r->connection->aborted) {
> @@ -2331,6 +2339,8 @@
>      if (r->connection->aborted)
>          return EOF;
>  
> +    ap_run_filter(r, (char *)buf, nbyte);

Same here.

> +
>      rv = ap_bwrite(r->connection->client, buf, nbyte, &n);
>      if (n < 0) {
>          if (!r->connection->aborted) {
> @@ -2352,6 +2362,8 @@
>      if (r->connection->aborted)
>          return -1;
>  
> +/*    ap_run_filter(r, str, strlen);
> +*/
>      n = ap_vbprintf(r->connection->client, fmt, ap);
>  
>      if (n < 0) {
> @@ -2376,6 +2388,8 @@
>      if (r->connection->aborted)
>          return -1;
>  
> +/*    ap_run_filter(r, str, strlen);
> +*/

Yes, these are a bit more difficult, eh?

>      va_start(vlist, fmt);
>      n = ap_vbprintf(r->connection->client, fmt, vlist);
>      va_end(vlist);
> @@ -2412,6 +2426,9 @@
>          if (x == NULL)
>              break;
>          j = strlen(x);
> +
> +/*        ap_run_filter(r, str, strlen);
> +*/
>          rv = ap_bwrite(fb, x, j, &i);

Switch to ap_rwrite() or add the run_filter here (but it would still need
a local copy).

>          if (i != j) {
>              va_end(args);
> @@ -2831,3 +2848,6 @@
>  			 NULL)
>  IMPLEMENT_HOOK_RUN_FIRST(unsigned short,default_port,(const request_rec *r),
>  			 (r),0)
> +IMPLEMENT_HOOK_VOID(filter,
> +                    (request_rec *r, char *str, int len),
> +                    (r, str, len))

This modifies the value in place. It doesn't make any provision for
altering the length. Modifying in place implies making a copy of the data
before passing it to the hook. Even then, you may not have enough buffer
for the cases where the output is expanded.

The hook strategy does not provide for deterministic output processing
(e.g. PHP runs first, then SSI).

Detailed writeup to follow.

Cheers,
-g

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


Mime
View raw message