You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by st...@apache.org on 2004/07/01 22:25:25 UTC

cvs commit: modperl-2.0/xs/Apache/RequestIO Apache__RequestIO.h

stas        2004/07/01 13:25:25

  Modified:    .        Changes
               t/api    sendfile.t
               t/response/TestAPI sendfile.pm
               xs/Apache/RequestIO Apache__RequestIO.h
  Log:
  sendfile: If the return status is not checked and an error happens throw
  an exception.
  
  Revision  Changes    Path
  1.395     +2 -1      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.394
  retrieving revision 1.395
  diff -u -u -r1.394 -r1.395
  --- Changes	1 Jul 2004 16:42:13 -0000	1.394
  +++ Changes	1 Jul 2004 20:25:25 -0000	1.395
  @@ -20,7 +20,8 @@
   then link into this library [Stas, Joe Schaefer, Randy Kobes]
   
   APR::RequestIO::sendfile() now flushes any buffered output before
  -sending the file contents out [Stas]
  +sending the file contents out. If the return status is not checked and
  +an error happens it'll throw an exception. [Stas]
   
   Registry: remove the misleading prefix "$$: $class:" in the logged
   error message, since not only registry errors will get logged if $@ is
  
  
  
  1.9       +10 -1     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.8
  retrieving revision 1.9
  diff -u -u -r1.8 -r1.9
  --- sendfile.t	1 Jul 2004 16:24:12 -0000	1.8
  +++ sendfile.t	1 Jul 2004 20:25:25 -0000	1.9
  @@ -12,7 +12,7 @@
   my $file = catfile Apache::Test::vars('serverroot'),
       'response/TestAPI/sendfile.pm';
   
  -plan tests => 5;
  +plan tests => 7;
   
   {
       my $header = "This is a header\n";
  @@ -34,6 +34,15 @@
   
   {
       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/;
  +}
  +
  +{
  +    my $res = GET "$url?noexist-n-nocheck.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");
  
  
  
  1.4       +12 -6     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.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- sendfile.pm	29 Jun 2004 22:56:17 -0000	1.3
  +++ sendfile.pm	1 Jul 2004 20:25:25 -0000	1.4
  @@ -21,12 +21,18 @@
       $r->print("This is a header\n")
           unless $file eq 'noexist-n-noheader.txt';
   
  -    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;
  +    if ($file eq 'noexist-n-nocheck.txt') {
  +        eval { $r->sendfile($file) };
  +        return int $@;
  +    }
  +    else {
  +        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");
  
  
  
  1.49      +16 -7     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.48
  retrieving revision 1.49
  diff -u -u -r1.48 -r1.49
  --- Apache__RequestIO.h	29 Jun 2004 22:56:17 -0000	1.48
  +++ Apache__RequestIO.h	1 Jul 2004 20:25:25 -0000	1.49
  @@ -314,14 +314,19 @@
                                                 apr_size_t len)
   {
       apr_size_t nbytes;
  -    apr_status_t status;
  +    apr_status_t rc;
       apr_file_t *fp;
   
  -    status = apr_file_open(&fp, filename, APR_READ|APR_BINARY,
  -                           APR_OS_DEFAULT, r->pool);
  +    rc = apr_file_open(&fp, filename, APR_READ|APR_BINARY,
  +                       APR_OS_DEFAULT, r->pool);
   
  -    if (status != APR_SUCCESS) {
  -        return status;
  +    if (rc != APR_SUCCESS) {
  +        if (GIMME_V == G_VOID) {
  +            modperl_croak(aTHX_ rc, "Apache::RequestIO::sendfile");
  +        }
  +        else {
  +            return rc;
  +        }
       }
   
       if (!len) {
  @@ -346,9 +351,13 @@
           }
       }
       
  -    status = ap_send_fd(fp, r, offset, len, &nbytes);
  +    rc = ap_send_fd(fp, r, offset, len, &nbytes);
   
       /* apr_file_close(fp); */ /* do not do this */
   
  -    return status;
  +    if (GIMME_V == G_VOID && rc != APR_SUCCESS) {
  +        modperl_croak(aTHX_ rc, "Apache::RequestIO::sendfile");
  +    }
  +
  +    return rc;
   }