perl-modperl-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject cvs commit: modperl-2.0 Changes
Date Tue, 29 Jun 2004 22:56:17 GMT
stas        2004/06/29 15:56:17

  Modified:    t/api    sendfile.t
               t/response/TestAPI sendfile.pm
               xs/Apache/RequestIO Apache__RequestIO.h
               xs/tables/current/ModPerl FunctionTable.pm
               .        Changes
  Log:
  APR::RequestIO::sendfile() now flushes any buffered output before
  sending the file contents out
  
  Revision  Changes    Path
  1.7       +35 -13    modperl-2.0/t/api/sendfile.t
  
  Index: sendfile.t
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/api/sendfile.t,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -u -r1.6 -r1.7
  --- sendfile.t	30 Jan 2004 00:24:44 -0000	1.6
  +++ sendfile.t	29 Jun 2004 22:56:16 -0000	1.7
  @@ -2,25 +2,47 @@
   use warnings FATAL => 'all';
   
   use Apache::Test;
  +use Apache::TestUtil;
   use Apache::TestRequest;
   
   use File::Spec::Functions qw(catfile);
   
  -plan tests => 3;
  -
  -my $config = Apache::Test::config();
  -
   my $url = '/TestAPI__sendfile';
   
  -my $data = GET_BODY($url);
  -
  -ok $data;
  -
  -my $module = catfile Apache::Test::vars('serverroot'),
  +my $file = catfile Apache::Test::vars('serverroot'),
       'response/TestAPI/sendfile.pm';
   
  -ok length($data) == -s $module;
  -
  -$data = GET_BODY("$url?noexist.txt");
  +plan tests => 5;
   
  -ok $data =~ /Not Found/;
  +{
  +    my $header = "This is a header\n";
  +    my $footer = "This is a footer\n";
  +
  +    open my $fh, $file or die "can't open $file: $!";
  +    local $/;
  +    my $expected = join '', $header, <$fh>, $footer;
  +    close $fh;
  +
  +    my $received = GET_BODY($url);
  +
  +    t_debug($received);
  +    ok $received && $received eq $expected;
  +}
  +
  +{
  +    my $res = GET "$url?noexist.txt";
  +    # 200 even though it wasn't found (since an output was sent before
  +    # sendfile was done)
  +    ok t_cmp($res->code, 200, "output already sent");
  +    t_debug($res->content);
  +    ok $res->content =~ /an internal error/;
  +}
  +
  +{
  +    # this time no printed output but the attempt to read a
  +    # non-existing file
  +    my $res = GET "$url?noexist-n-noheader.txt";
  +    ok t_cmp($res->code, 404, "");
  +    t_debug($res->content);
  +    ok $res->content =~ /$url was not found/;
  +}
  
  
  
  1.3       +17 -2     modperl-2.0/t/response/TestAPI/sendfile.pm
  
  Index: sendfile.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/response/TestAPI/sendfile.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- sendfile.pm	11 Apr 2002 11:08:43 -0000	1.2
  +++ sendfile.pm	29 Jun 2004 22:56:17 -0000	1.3
  @@ -12,11 +12,26 @@
   sub handler {
       my $r = shift;
   
  +    $r->content_type('text/plain');
       my $file = $r->args || __FILE__;
   
  -    my $status = $r->sendfile($file);
  +    # buffer output up, so we can test that sendfile flushes any
  +    # buffered output before sending the file contents out
  +    local $|;
  +    $r->print("This is a header\n")
  +        unless $file eq 'noexist-n-noheader.txt';
   
  -    return $status == APR::SUCCESS ? Apache::OK : Apache::NOT_FOUND;
  +    my $rc = $r->sendfile($file);
  +    unless ($rc == APR::SUCCESS) {
  +        # warn APR::Error::strerror($rc);
  +        return $file eq 'noexist-n-noheader.txt'
  +            ? Apache::NOT_FOUND
  +            : $rc;
  +    }
  +
  +    $r->print("This is a footer\n");
  +
  +    return Apache::OK;
   }
   
   1;
  
  
  
  1.48      +17 -1     modperl-2.0/xs/Apache/RequestIO/Apache__RequestIO.h
  
  Index: Apache__RequestIO.h
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/xs/Apache/RequestIO/Apache__RequestIO.h,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -u -r1.47 -r1.48
  --- Apache__RequestIO.h	2 Jun 2004 21:35:58 -0000	1.47
  +++ Apache__RequestIO.h	29 Jun 2004 22:56:17 -0000	1.48
  @@ -308,7 +308,7 @@
   }
   
   static MP_INLINE
  -apr_status_t mpxs_Apache__RequestRec_sendfile(request_rec *r,
  +apr_status_t mpxs_Apache__RequestRec_sendfile(pTHX_ request_rec *r,
                                                 const char *filename,
                                                 apr_off_t offset,
                                                 apr_size_t len)
  @@ -330,6 +330,22 @@
           len = finfo.size;
       }
   
  +    /* flush any buffered modperl output */
  +    {
  +        modperl_config_req_t *rcfg = modperl_config_req_get(r);
  +        
  +        MP_CHECK_WBUCKET_INIT("$r->rflush");
  +        if (rcfg->wbucket->outcnt) {
  +            MP_TRACE_o(MP_FUNC, "flushing %d bytes [%s]",
  +                       rcfg->wbucket->outcnt,
  +                       apr_pstrmemdup(rcfg->wbucket->pool,
  +                                      rcfg->wbucket->outbuf,
  +                                      rcfg->wbucket->outcnt));
  +            MP_RUN_CROAK(modperl_wbucket_flush(rcfg->wbucket, TRUE),
  +                         "Apache::RequestIO::sendfile");
  +        }
  +    }
  +    
       status = ap_send_fd(fp, r, offset, len, &nbytes);
   
       /* apr_file_close(fp); */ /* do not do this */
  
  
  
  1.166     +4 -0      modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm
  
  Index: FunctionTable.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm,v
  retrieving revision 1.165
  retrieving revision 1.166
  diff -u -u -r1.165 -r1.166
  --- FunctionTable.pm	16 Jun 2004 03:55:48 -0000	1.165
  +++ FunctionTable.pm	29 Jun 2004 22:56:17 -0000	1.166
  @@ -6550,6 +6550,10 @@
       'name' => 'mpxs_Apache__RequestRec_sendfile',
       'args' => [
         {
  +        'type' => 'PerlInterpreter *',
  +        'name' => 'my_perl'
  +      },
  +      {
           'type' => 'request_rec *',
           'name' => 'r'
         },
  
  
  
  1.393     +3 -0      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.392
  retrieving revision 1.393
  diff -u -u -r1.392 -r1.393
  --- Changes	27 Jun 2004 21:26:45 -0000	1.392
  +++ Changes	29 Jun 2004 22:56:17 -0000	1.393
  @@ -12,6 +12,9 @@
   
   =item 1.99_15-dev
   
  +APR::RequestIO::sendfile() now flushes any buffered output before
  +sending the file contents out [Stas]
  +
   Registry: remove the misleading prefix "$$: $class:" in the logged
   error message, since not only registry errors will get logged if $@ is
   set [Stas]
  
  
  

Mime
View raw message