]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Qspawn.pm
Merge remote-tracking branch 'origin/nntp-tls'
[public-inbox.git] / lib / PublicInbox / Qspawn.pm
index 79cdae711410d769f07c6e21c491a2c9495952c6..f2630a0f0109a624690edf38b849423b9b0af8dd 100644 (file)
@@ -12,9 +12,9 @@
 # operate in.  This can be useful to ensure smaller inboxes can
 # be cloned while cloning of large inboxes is maxed out.
 #
-# This does not depend on Danga::Socket or any other external
+# This does not depend on PublicInbox::DS or any other external
 # scheduling mechanism, you just need to call start() and finish()
-# appropriately. However, public-inbox-httpd (which uses Danga::Socket)
+# appropriately. However, public-inbox-httpd (which uses PublicInbox::DS)
 # will be able to schedule this based on readability of stdout from
 # the spawned process.  See GitHTTPBackend.pm and SolverGit.pm for
 # usage examples.  It does not depend on any form of threading.
@@ -29,6 +29,9 @@ use warnings;
 use PublicInbox::Spawn qw(popen_rd);
 require Plack::Util;
 
+# n.b.: we get EAGAIN with public-inbox-httpd, and EINTR on other PSGI servers
+use Errno qw(EAGAIN EINTR);
+
 my $def_limiter;
 
 # declares a command to spawn (but does not spawn it).
@@ -122,7 +125,7 @@ sub psgi_qx {
                eval { $qx_cb->($qx) };
                $qx = undef;
        };
-       my $rpipe;
+       my $rpipe; # comes from popen_rd
        my $async = $env->{'pi-httpd.async'};
        my $cb = sub {
                my $r = sysread($rpipe, my $buf, 8192);
@@ -131,13 +134,13 @@ sub psgi_qx {
                } elsif (defined $r) {
                        $r ? $qx->write($buf) : $end->();
                } else {
-                       return if $!{EAGAIN} || $!{EINTR}; # loop again
+                       return if $! == EAGAIN || $! == EINTR; # loop again
                        $end->();
                }
        };
        $limiter ||= $def_limiter ||= PublicInbox::Qspawn::Limiter->new(32);
        $self->start($limiter, sub { # may run later, much later...
-               ($rpipe) = @_;
+               ($rpipe) = @_; # popen_rd result
                if ($async) {
                # PublicInbox::HTTPD::Async->new($rpipe, $cb, $end)
                        $async = $async->($rpipe, $cb, $end);
@@ -193,7 +196,7 @@ sub psgi_return {
        my $buf = '';
        my $rd_hdr = sub {
                my $r = sysread($rpipe, $buf, 1024, length($buf));
-               return if !defined($r) && ($!{EINTR} || $!{EAGAIN});
+               return if !defined($r) && $! == EAGAIN || $! == EINTR;
                $parse_hdr->($r, \$buf);
        };