stas        2004/07/24 00:27:03

  Modified:    lib/Apache compat.pm
               t/conf   modperl_extra.pl
  Log:
  improve the POST reading code (now handles file buckets correctly)
  
  Revision  Changes    Path
  1.114     +11 -12    modperl-2.0/lib/Apache/compat.pm
  
  Index: compat.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v
  retrieving revision 1.113
  retrieving revision 1.114
  diff -u -u -r1.113 -r1.114
  --- compat.pm 16 Jul 2004 01:10:45 -0000      1.113
  +++ compat.pm 24 Jul 2004 07:27:03 -0000      1.114
  @@ -43,6 +43,7 @@
   use Apache::RequestUtil ();
   use Apache::Response ();
   use Apache::SubRequest ();
  +use Apache::Filter ();
   use Apache::Util ();
   use Apache::Log ();
   use Apache::URI ();
  @@ -473,28 +474,26 @@
   sub content {
       my $r = shift;
   
  -    my $ba = $r->connection->bucket_alloc;
  -    my $bb = APR::Brigade->new($r->pool, $ba);
  +    my $bb = APR::Brigade->new($r->pool,
  +                               $r->connection->bucket_alloc);
   
       my $data = '';
       my $seen_eos = 0;
  -    my $count = 0;
       do {
  -        $r->input_filters->get_brigade($bb,
  -            Apache::MODE_READBYTES, APR::BLOCK_READ, IOBUFSIZE);
  -
  -        while (!$bb->is_empty) {
  -            my $b = $bb->first;
  -
  -            $b->remove;
  +        $r->input_filters->get_brigade($bb, Apache::MODE_READBYTES,
  +                                       APR::BLOCK_READ, IOBUFSIZE);
   
  +        for (my $b = $bb->first; $b; $b = $bb->next($b)) {
               if ($b->is_eos) {
                   $seen_eos++;
                   last;
               }
   
  -            $b->read(my $buf);
  -            $data .= $buf;
  +            if ($b->read(my $buf)) {
  +                $data .= $buf;
  +            }
  +
  +            $b->remove; # optimization to reuse memory
           }
       } while (!$seen_eos);
   
  
  
  
  1.59      +12 -15    modperl-2.0/t/conf/modperl_extra.pl
  
  Index: modperl_extra.pl
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/conf/modperl_extra.pl,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -u -r1.58 -r1.59
  --- modperl_extra.pl  16 Jul 2004 01:10:46 -0000      1.58
  +++ modperl_extra.pl  24 Jul 2004 07:27:03 -0000      1.59
  @@ -150,6 +150,7 @@
   
   use APR::Brigade ();
   use APR::Bucket ();
  +use Apache::Filter ();
   
   use Apache::Const -compile => qw(MODE_READBYTES);
   use APR::Const    -compile => qw(SUCCESS BLOCK_READ);
  @@ -162,37 +163,33 @@
       my $r = shift;
       my $debug = shift || 0;
   
  -    my $ba = $r->connection->bucket_alloc;
  -    my $bb = APR::Brigade->new($r->pool, $ba);
  +    my $bb = APR::Brigade->new($r->pool,
  +                               $r->connection->bucket_alloc);
   
       my $data = '';
       my $seen_eos = 0;
       my $count = 0;
       do {
  -        my $rv = $r->input_filters->get_brigade($bb,
  -            Apache::MODE_READBYTES, APR::BLOCK_READ, IOBUFSIZE);
  -        if ($rv != APR::SUCCESS) {
  -            return $rv;
  -        }
  +        $r->input_filters->get_brigade($bb, Apache::MODE_READBYTES,
  +                                       APR::BLOCK_READ, IOBUFSIZE);
   
           $count++;
   
           warn "read_post: bb $count\n" if $debug;
   
  -        while (!$bb->is_empty) {
  -            my $b = $bb->first;
  -
  -            $b->remove;
  -
  +        for (my $b = $bb->first; $b; $b = $bb->next($b)) {
               if ($b->is_eos) {
                   warn "read_post: EOS bucket:\n" if $debug;
                   $seen_eos++;
                   last;
               }
   
  -            $b->read(my $buf);
  -            warn "read_post: DATA bucket: [$buf]\n" if $debug;
  -            $data .= $buf;
  +            if ($b->read(my $buf)) {
  +                warn "read_post: DATA bucket: [$buf]\n" if $debug;
  +                $data .= $buf;
  +            }
  +
  +            $b->remove; # optimization to reuse memory
           }
   
       } while (!$seen_eos);
  
  
  

Reply via email to