stas 2004/06/03 21:12:54
Modified: xs/maps apr_functions.map . Changes Added: t/protocol echo_bbs2.t t/protocol/TestProtocol echo_bbs2.pm Log: - APR::Brigade: add the method cleanup() - test the new method in conjunction with flatten, by reusing the same brigade and cleaning all of its buckets at once, rather than one by one Revision Changes Path 1.1 modperl-2.0/t/protocol/echo_bbs2.t Index: echo_bbs2.t =================================================================== use strict; use warnings FATAL => 'all'; use Test; use Apache::TestUtil; use Apache::TestRequest (); my @test_strings = qw(hello world); plan tests => 1 + @test_strings; my $socket = Apache::TestRequest::vhost_socket('TestProtocol::echo_bbs2'); ok $socket; for (@test_strings) { print $socket "$_\n"; chomp(my $reply = <$socket>||''); ok t_cmp(uc($_), $reply); } 1.1 modperl-2.0/t/protocol/TestProtocol/echo_bbs2.pm Index: echo_bbs2.pm =================================================================== package TestProtocol::echo_bbs2; # similar to TestProtocol::echo_bbs but here re-using one bucket # brigade for input and output, using flatten to slurp all the data in # the bucket brigade, and cleanup to get rid of the old buckets use strict; use warnings FATAL => 'all'; use Apache::Connection (); use APR::Socket (); use APR::Bucket (); use APR::Brigade (); use APR::Error (); use Apache::Const -compile => qw(OK MODE_GETLINE); use APR::Const -compile => qw(SUCCESS EOF SO_NONBLOCK); sub handler { my $c = shift; # starting from Apache 2.0.49 several platforms require you to set # the socket to a blocking IO mode $c->client_socket->opt_set(APR::SO_NONBLOCK => 0); my $bb = APR::Brigade->new($c->pool, $c->bucket_alloc); my $last = 0; while (1) { my $bb_in = APR::Brigade->new($c->pool, $c->bucket_alloc); my $rc = $c->input_filters->get_brigade($bb_in, Apache::MODE_GETLINE); if ($rc != APR::SUCCESS && $rc != APR::EOF) { my $error = APR::Error::strerror($rc); warn __PACKAGE__ . ": get_brigade: $error\n"; last; } my $data = $bb_in->flatten; $bb->cleanup; #warn "read: [$data]\n"; last if $data =~ /^[\r\n]+$/; # transform data here my $bucket = APR::Bucket->new(uc $data); $bb->insert_tail($bucket); $c->output_filters->fflush($bb); } $bb->destroy; Apache::OK; } 1; 1.81 +1 -1 modperl-2.0/xs/maps/apr_functions.map Index: apr_functions.map =================================================================== RCS file: /home/cvs/modperl-2.0/xs/maps/apr_functions.map,v retrieving revision 1.80 retrieving revision 1.81 diff -u -u -r1.80 -r1.81 --- apr_functions.map 4 Jun 2004 03:20:46 -0000 1.80 +++ apr_functions.map 4 Jun 2004 04:12:54 -0000 1.81 @@ -93,7 +93,7 @@ !apr_brigade_write !apr_brigade_puts -apr_brigade_putc -!apr_brigade_cleanup + apr_brigade_cleanup ~apr_brigade_flatten ~apr_brigade_pflatten ?apr_brigade_split_line 1.387 +1 -0 modperl-2.0/Changes Index: Changes =================================================================== RCS file: /home/cvs/modperl-2.0/Changes,v retrieving revision 1.386 retrieving revision 1.387 diff -u -u -r1.386 -r1.387 --- Changes 2 Jun 2004 22:47:24 -0000 1.386 +++ Changes 4 Jun 2004 04:12:54 -0000 1.387 @@ -69,6 +69,7 @@ APR::Brigade [Stas] - destroy() now throws APR::Error exception (not returning rc) - rename empty => is_empty + - added the method cleanup() APR::Bucket: [Stas] - read() now returns read data and throws APR::Error exception (not