stas 2004/08/15 00:55:53
Modified: t/filter/TestFilter in_bbs_body.pm in_bbs_msg.pm out_bbs_ctx.pm out_bbs_filebucket.pm t/protocol/TestProtocol echo_bbs.pm todo release Log: - make sure that $b->remove is not called before $r->read. since if it does, and there is a filebucket, it'll get split into more than bucket and all but the first bucket will be lost. after read() it's safe to unlink the old bucket - while fixing the above issue, simplified several filter/protocol tests Revision Changes Path 1.8 +6 -16 modperl-2.0/t/filter/TestFilter/in_bbs_body.pm Index: in_bbs_body.pm =================================================================== RCS file: /home/cvs/modperl-2.0/t/filter/TestFilter/in_bbs_body.pm,v retrieving revision 1.7 retrieving revision 1.8 diff -u -u -r1.7 -r1.8 --- in_bbs_body.pm 15 Aug 2004 06:30:51 -0000 1.7 +++ in_bbs_body.pm 15 Aug 2004 07:55:52 -0000 1.8 @@ -19,27 +19,17 @@ #warn "Called!"; my $ba = $filter->r->connection->bucket_alloc; - my $ctx_bb = APR::Brigade->new($filter->r->pool, $ba); + $filter->next->get_brigade($bb, $mode, $block, $readbytes); + for (my $b = $bb->first; $b; $b = $bb->next($b)) { - $filter->next->get_brigade($ctx_bb, $mode, $block, $readbytes); - - while (!$ctx_bb->is_empty) { - my $b = $ctx_bb->first; - - $b->remove; - - if ($b->is_eos) { - #warn "EOS!!!!"; - $bb->insert_tail($b); - last; - } + last if $b->is_eos; if ($b->read(my $data)) { #warn"[$data]\n"; - $b = APR::Bucket->new(scalar reverse $data); + my $nb = APR::Bucket->new(scalar reverse $data); + $b->insert_before($nb); + $b->remove; } - - $bb->insert_tail($b); } Apache::OK; 1.12 +9 -20 modperl-2.0/t/filter/TestFilter/in_bbs_msg.pm Index: in_bbs_msg.pm =================================================================== RCS file: /home/cvs/modperl-2.0/t/filter/TestFilter/in_bbs_msg.pm,v retrieving revision 1.11 retrieving revision 1.12 diff -u -u -r1.11 -r1.12 --- in_bbs_msg.pm 15 Aug 2004 06:30:50 -0000 1.11 +++ in_bbs_msg.pm 15 Aug 2004 07:55:52 -0000 1.12 @@ -23,35 +23,24 @@ debug "FILTER CALLED"; my $c = $filter->c; - my $ctx_bb = APR::Brigade->new($c->pool, $c->bucket_alloc); - $filter->next->get_brigade($ctx_bb, $mode, $block, $readbytes); + $filter->next->get_brigade($bb, $mode, $block, $readbytes); + for (my $b = $bb->first; $b; $b = $bb->next($b)) { - while (!$ctx_bb->is_empty) { - my $b = $ctx_bb->first; + last if $b->is_eos; - $b->remove; - - if ($b->is_eos) { - debug "EOS!!!"; - $bb->insert_tail($b); - last; - } - - $b->read(my $data); - debug "FILTER READ:\n$data"; - - if ($data and $data =~ s,GET $from_url,GET $to_url,) { - debug "GET line rewritten to be:\n$data"; - $b = APR::Bucket->new($data); + if ($b->read(my $data)) { + next unless $data =~ s|GET $from_url|GET $to_url|; + debug "new GET line:\n$data"; + my $nb = APR::Bucket->new($data); + $b->insert_before($nb); + $b->remove; # XXX: currently a bug in httpd doesn't allow to remove # the first connection filter. once it's fixed adjust the test # to test that it was invoked only once. # debug "removing the filter"; # $filter->remove; # this filter is no longer needed } - - $bb->insert_tail($b); } Apache::OK; 1.8 +7 -1 modperl-2.0/t/filter/TestFilter/out_bbs_ctx.pm Index: out_bbs_ctx.pm =================================================================== RCS file: /home/cvs/modperl-2.0/t/filter/TestFilter/out_bbs_ctx.pm,v retrieving revision 1.7 retrieving revision 1.8 diff -u -u -r1.7 -r1.8 --- out_bbs_ctx.pm 15 Aug 2004 06:30:50 -0000 1.7 +++ out_bbs_ctx.pm 15 Aug 2004 07:55:52 -0000 1.8 @@ -31,7 +31,6 @@ my $data = exists $ctx->{data} ? $ctx->{data} : ''; while (my $b = $bb->first) { - $b->remove; if ($b->is_eos) { # flush the remainings and send a stats signature @@ -44,6 +43,7 @@ } if ($b->read(my $bdata)) { + $b->remove; $data .= $bdata; my $len = length $data; @@ -59,6 +59,12 @@ $bb_ctx->insert_tail($b); } } + else { + # insert META buckets as is + $b->remove; + $bb_ctx->insert_tail($b); + } + } $ctx->{data} = $data; 1.3 +4 -10 modperl-2.0/t/filter/TestFilter/out_bbs_filebucket.pm Index: out_bbs_filebucket.pm =================================================================== RCS file: /home/cvs/modperl-2.0/t/filter/TestFilter/out_bbs_filebucket.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -u -r1.2 -r1.3 --- out_bbs_filebucket.pm 14 Aug 2004 18:46:01 -0000 1.2 +++ out_bbs_filebucket.pm 15 Aug 2004 07:55:52 -0000 1.3 @@ -23,9 +23,6 @@ sub handler { my($filter, $bb) = @_; - my $c = $filter->c; - my $bb_ctx = APR::Brigade->new($c->pool, $c->bucket_alloc); - debug "FILTER INVOKED"; my $cnt = 0; @@ -34,19 +31,16 @@ $cnt++; debug "reading bucket #$cnt"; - if ($b->is_eos) { - $b->remove; - $bb_ctx->insert_tail($b); - last; - } + last if $b->is_eos; if (my $len = $b->read(my $data)) { my $nb = APR::Bucket->new(uc $data); - $bb_ctx->insert_tail($nb); + $b->insert_before($nb); + $b->remove; } } - my $rv = $filter->next->pass_brigade($bb_ctx); + my $rv = $filter->next->pass_brigade($bb); return $rv unless $rv == APR::SUCCESS; return Apache::OK; 1.6 +14 -18 modperl-2.0/t/protocol/TestProtocol/echo_bbs.pm Index: echo_bbs.pm =================================================================== RCS file: /home/cvs/modperl-2.0/t/protocol/TestProtocol/echo_bbs.pm,v retrieving revision 1.5 retrieving revision 1.6 diff -u -u -r1.5 -r1.6 --- echo_bbs.pm 1 Jul 2004 02:01:21 -0000 1.5 +++ echo_bbs.pm 15 Aug 2004 07:55:52 -0000 1.6 @@ -4,6 +4,9 @@ # manipulations on the buckets inside the connection handler, rather # then using filter +# it also demonstrates how to use a single bucket bridade to do all +# the manipulation + use strict; use warnings FATAL => 'all'; @@ -23,38 +26,31 @@ # the socket to a blocking IO mode $c->client_socket->opt_set(APR::SO_NONBLOCK, 0); - my $bb_in = APR::Brigade->new($c->pool, $c->bucket_alloc); - my $bb_out = APR::Brigade->new($c->pool, $c->bucket_alloc); + my $bb = APR::Brigade->new($c->pool, $c->bucket_alloc); while (1) { - my $rc = $c->input_filters->get_brigade($bb_in, + my $rc = $c->input_filters->get_brigade($bb, Apache::MODE_GETLINE); last if $rc == APR::EOF; die APR::Error::strerror($rc) unless $rc == APR::SUCCESS; - while (!$bb_in->is_empty) { - my $bucket = $bb_in->first; - - $bucket->remove; + for (my $b = $bb->first; $b; $b = $bb->next($b)) { - if ($bucket->is_eos) { - $bb_out->insert_tail($bucket); - last; - } + last if $b->is_eos; - if ($bucket->read(my $data)) { + if ($b->read(my $data)) { last if $data =~ /^[\r\n]+$/; - $bucket = APR::Bucket->new(uc $data); + my $nb = APR::Bucket->new(uc $data); + # head->...->$nb->$b ->...->tail + $b->insert_before($nb); + $b->remove; } - - $bb_out->insert_tail($bucket); } - $c->output_filters->fflush($bb_out); + $c->output_filters->fflush($bb); } - $bb_in->destroy; - $bb_out->destroy; + $bb->destroy; Apache::OK; } 1.46 +0 -3 modperl-2.0/todo/release Index: release =================================================================== RCS file: /home/cvs/modperl-2.0/todo/release,v retrieving revision 1.45 retrieving revision 1.46 diff -u -u -r1.45 -r1.46 --- release 15 Aug 2004 00:19:03 -0000 1.45 +++ release 15 Aug 2004 07:55:52 -0000 1.46 @@ -8,9 +8,6 @@ should be rewritten to clearly explain how to build static and dynamic mod_perl (each separately). -* rewrite the tests/docs not to remove the bucket until it was read - from - * APR::URI missing $uri->rpath (was in mp1) * Apache::RequestRec's $r->content_languages is missing (was in mp1)