about summary refs log tree commit homepage
path: root/lib/PublicInbox/Qspawn.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-07-04 10:02:06 +0000
committerEric Wong <e@80x24.org>2019-07-04 10:16:41 +0000
commit620b5e23dded54e0abf954752767bc9683a882e3 (patch)
tree49fb41ae4e6d7d8cbdf26f0b0422c874d369ed31 /lib/PublicInbox/Qspawn.pm
parent0f1da9d213e16946371b5c140b1c55b7231a8cd5 (diff)
downloadpublic-inbox-620b5e23dded54e0abf954752767bc9683a882e3.tar.gz
We need to ensure the BIN_DETECT (8000 byte) check in
ViewVCS can be handled properly when sending giant
files.  Otherwise, EPOLLET won't notify us, again,
and responses can get stuck.

While we're at it, bump up the read-size up to 4096
bytes so we make fewer trips to the kernel.
Diffstat (limited to 'lib/PublicInbox/Qspawn.pm')
-rw-r--r--lib/PublicInbox/Qspawn.pm16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index 8f0b9fe2..fb48585c 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -195,9 +195,19 @@ sub psgi_return {
 
         my $buf = '';
         my $rd_hdr = sub {
-                my $r = sysread($rpipe, $buf, 1024, length($buf));
-                return if !defined($r) && $! == EAGAIN || $! == EINTR;
-                $parse_hdr->($r, \$buf);
+                # we must loop until EAGAIN for EPOLLET in HTTPD/Async.pm
+                # We also need to check EINTR for generic PSGI servers.
+                my $ret;
+                my $n = 0;
+                do {
+                        my $r = sysread($rpipe, $buf, 4096, length($buf));
+                        return if !defined($r) && $! == EAGAIN || $! == EINTR;
+
+                        # $r may be undef, here:
+                        $n += $r if $r;
+                        $ret = $parse_hdr->($r ? $n : $r, \$buf);
+                } until (defined $ret);
+                $ret;
         };
 
         my $wcb = delete $env->{'qspawn.wcb'};