httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject Re: calling ap_get_brigade with nonempty brigade
Date Mon, 09 Jun 2003 04:50:33 GMT
Joe Schaefer wrote:
> ap_http_filter seems to assume it will receive an empty 
> brigade from its caller. The problem is around lines 
> 1028 - 1035 in http_protocol.c:
>     rv = ap_get_brigade(f->next, b, mode, block, readbytes);
>     if (rv != APR_SUCCESS) {
>         return rv;
>     }
>     /* How many bytes did we just read? */
>     apr_brigade_length(b, 0, &totalread);
> totalread is only accurate in this context if b was 
> empty to begin with.  Is this is a bug in ap_http_filter?

I think that assumptions is valid for all filters and is correct by (an 
undocumented) design.

If I understand things correctly, If you want to re-use some older bbs (e.g. 
from previous invocations or if you have an underrun and ask for more during 
the same invocation), you should create a new bb, pass it to ap_get_brigade() 
and then merge with the previous one.

Here is a snippet from t/filter/TestFilter/, though I rip 
the data off, rather than merge.

     # fetch and consume bucket brigades untill we have at least SIZE
     # bytes to work with
     do {
         my $tbb = APR::Brigade->new($filter->r->pool, $ba);
         my $rv = $filter->next->get_brigade($tbb, $mode, $block, $readbytes);
         ($data, $seen_eos) = flatten_bb($tbb);
         $buffer .= $data;
     } while (!$seen_eos && length($buffer) < SIZE);

it should be pretty much the same in C.

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

View raw message