httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cliff Woolley <cliffwool...@yahoo.com>
Subject Re: are we ready to roll?
Date Thu, 09 Aug 2001 23:32:42 GMT
On Thu, 9 Aug 2001, Doug MacEachern wrote:

> well, i found a solution when writing a c version of the test.
>
> APR_BRIGADE_FOREACH(bucket, bb) {
> ...
> }
>
> does not work, but this does:
>
> while (!APR_BRIGADE_EMPTY(bb)) {
>     bucket = APR_BRIGADE_FIRST(bb);
>     ...
>     if (APR_BUCKET_IS_EOS(bucket)) {
>         break;
>     }
> }
>
> i've seen other cases of this, in ssl_engine_io.c for example:
>
>     /* XXX: shame that APR_BRIGADE_FOREACH doesn't work here */
>
> what's up with that?


The question is what's in the '...' in the code snippet above.

APR_BRIGADE_FOREACH is finicky... in order to access the next bucket on
the next iteration, it assumes you didn't mess with the bucket pointer it
gave you on the last iteration.  If you fiddle with the bucket pointer
that APR_BRIGADE_FOREACH gave you rather than just treating as a constant
value, you're almost certain to break the assumptions made by that macro.

Given the example you list above of what will work and what won't, I'm
guessing that what your loop is doing is taking each bucket in the brigade
one at a time, dinking with the contents (unencrypting them, perhaps),
removing the bucket from the brigade, and re-injecting the data either
into either a completely different bucket or possibly even into a
different ("output") brigade.  That just won't work with
APR_BRIGADE_FOREACH, because when you destroy the bucket it gave you
during the course of one iteration, it has no way to find out what the
APR_BUCKET_NEXT(bucket) value is in order to move on to the next bucket in
the brigade.  (Did that make sense?  I'm rambling...)

The "while (!APR_BRIGADE_EMPTY(bb)) {}" trick is a very commonly-used way
to avoid these sorts of problems when doing these sorts of things.  It
probably deserves a big honkin @tip or @warning in the docco for
APR_BRIGADE_FOREACH.  I'll go add one.  =-)

--Cliff


--------------------------------------------------------------
   Cliff Woolley
   cliffwoolley@yahoo.com
   Charlottesville, VA



Mime
View raw message