Return-Path: Delivered-To: apmail-perl-modperl-cvs-archive@www.apache.org Received: (qmail 74078 invoked from network); 1 Jul 2004 20:25:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 1 Jul 2004 20:25:28 -0000 Received: (qmail 15156 invoked by uid 500); 1 Jul 2004 20:25:45 -0000 Delivered-To: apmail-perl-modperl-cvs-archive@perl.apache.org Received: (qmail 15103 invoked by uid 500); 1 Jul 2004 20:25:44 -0000 Mailing-List: contact modperl-cvs-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@perl.apache.org Delivered-To: mailing list modperl-cvs@perl.apache.org Received: (qmail 15085 invoked by uid 500); 1 Jul 2004 20:25:43 -0000 Delivered-To: apmail-modperl-2.0-cvs@apache.org X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Date: 1 Jul 2004 20:25:25 -0000 Message-ID: <20040701202525.74053.qmail@minotaur.apache.org> From: stas@apache.org To: modperl-2.0-cvs@apache.org Subject: cvs commit: modperl-2.0/xs/Apache/RequestIO Apache__RequestIO.h X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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; }