]> Sergey Matveev's repositories - public-inbox.git/commitdiff
qspawn: psgi_qx: do not call async_pass on errors
authorEric Wong <e@80x24.org>
Thu, 19 Jan 2023 20:32:35 +0000 (20:32 +0000)
committerEric Wong <e@80x24.org>
Thu, 19 Jan 2023 20:54:22 +0000 (20:54 +0000)
This makes control flow slightly less confusing.

lib/PublicInbox/Qspawn.pm

index c4708c0fe035088aa7de392d7244aabf1d370d2e..de74b1747f6651f41495974347263745dca814f2 100644 (file)
@@ -142,20 +142,20 @@ sub start ($$$) {
 
 sub psgi_qx_init_cb { # this may be PublicInbox::HTTPD::Async {cb}
        my ($self) = @_;
-       my $async = delete $self->{async}; # PublicInbox::HTTPD::Async
        my ($r, $buf);
-       my $qx_fh = $self->{qx_fh};
 reread:
        $r = sysread($self->{rpipe}, $buf, 65536);
-       if ($async) {
-               $async->async_pass($self->{psgi_env}->{'psgix.io'},
-                                       $qx_fh, \$buf);
-       } elsif (defined $r) {
-               $r ? (print $qx_fh $buf) : event_step($self, undef);
-       } else {
+       if (!defined($r)) {
                return if $! == EAGAIN; # try again when notified
                goto reread if $! == EINTR;
                event_step($self, $!);
+       } elsif (my $as = delete $self->{async}) { # PublicInbox::HTTPD::Async
+               $as->async_pass($self->{psgi_env}->{'psgix.io'},
+                               $self->{qx_fh}, \$buf);
+       } elsif ($r) { # generic PSGI:
+               print { $self->{qx_fh} } $buf;
+       } else { # EOF
+               event_step($self, undef);
        }
 }