]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Qspawn.pm
http: use bigger, but shorter-lived buffers for pipes
[public-inbox.git] / lib / PublicInbox / Qspawn.pm
index 943ee8017908b657b7e441f11755b7abb18f5d56..8f0b9fe240ebc378a81ce86a7207f73d71ec4f63 100644 (file)
@@ -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).
@@ -125,13 +128,13 @@ sub psgi_qx {
        my $rpipe; # comes from popen_rd
        my $async = $env->{'pi-httpd.async'};
        my $cb = sub {
-               my $r = sysread($rpipe, my $buf, 8192);
+               my $r = sysread($rpipe, my $buf, 65536);
                if ($async) {
                        $async->async_pass($env->{'psgix.io'}, $qx, \$buf);
                } elsif (defined $r) {
                        $r ? $qx->write($buf) : $end->();
                } else {
-                       return if $!{EAGAIN} || $!{EINTR}; # loop again
+                       return if $! == EAGAIN || $! == EINTR; # loop again
                        $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);
        };