about summary refs log tree commit homepage
path: root/lib/PublicInbox/WwwStatic.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-12-31 10:30:09 +0000
committerEric Wong <e@80x24.org>2020-01-01 07:50:23 +0000
commit2262411eb4396b2627e131ce4cd402a2deebdbea (patch)
tree9e0252f132cf264ca0e5e76268549f818fe7bded /lib/PublicInbox/WwwStatic.pm
parent9004fa901b09d7c50be31e0f800474503ece3d5a (diff)
downloadpublic-inbox-2262411eb4396b2627e131ce4cd402a2deebdbea.tar.gz
"psgix." extensions aren't guaranteed, so make we should
try and support some theoretical generic PSGI servers
without "psgix.io" on errors by die-ing.

While we're at it, make the error handling path more obvious by
sharing more code between the EOF and errno ($!) cases.
Diffstat (limited to 'lib/PublicInbox/WwwStatic.pm')
-rw-r--r--lib/PublicInbox/WwwStatic.pm20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/PublicInbox/WwwStatic.pm b/lib/PublicInbox/WwwStatic.pm
index 76e50c78..58db58b4 100644
--- a/lib/PublicInbox/WwwStatic.pm
+++ b/lib/PublicInbox/WwwStatic.pm
@@ -77,25 +77,23 @@ sub response {
 # called by PSGI servers:
 sub getline {
         my ($self) = @_;
-        my $len = $self->{len};
-        return if $len == 0;
+        my $len = $self->{len} or return; # undef, tells server we're done
         my $n = delete($self->{initial_rd}) // 8192;
         $n = $len if $len < $n;
         my $r = sysread($self->{in}, my $buf, $n);
-        if (!defined $r) {
-                $self->{env}->{'psgi.errors'}->print(
-                        "$self->{path} read error: $!\n");
-        } elsif ($r > 0) { # success!
+        if (defined $r && $r > 0) { # success!
                 $self->{len} = $len - $r;
                 return $buf;
-        } else {
-                $self->{env}->{'psgi.errors'}->print(
-                        "$self->{path} EOF with $len bytes left\n");
         }
+        my $m = defined $r ? "EOF with $len bytes left" : "read error: $!";
+        my $env = $self->{env};
+        $env->{'psgi.errors'}->print("$self->{path} $m\n");
 
         # drop the client on error
-        if (my $io = $self->{env}->{'psgix.io'}) {
-                $io->close; # this is PublicInbox::DS::close
+        if (my $io = $env->{'psgix.io'}) {
+                $io->close; # this is likely PublicInbox::DS::close
+        } else { # for some PSGI servers w/o psgix.io
+                die "dropping client socket\n";
         }
         undef;
 }