]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Qspawn.pm
qspawn: remove unused WNOHANG import
[public-inbox.git] / lib / PublicInbox / Qspawn.pm
index f2e91ab6ab671e67c72806d3da6ac7ee7b01bb6b..73fd3225f7f2e7d2f2d1579af3ed4ae9c6f3444c 100644 (file)
@@ -27,7 +27,6 @@ package PublicInbox::Qspawn;
 use strict;
 use warnings;
 use PublicInbox::Spawn qw(popen_rd);
-use POSIX qw(WNOHANG);
 require Plack::Util;
 
 # n.b.: we get EAGAIN with public-inbox-httpd, and EINTR on other PSGI servers
@@ -153,11 +152,12 @@ sub start {
 # and safe to slurp.
 sub psgi_qx {
        my ($self, $env, $limiter, $qx_cb) = @_;
-       my $qx = PublicInbox::Qspawn::Qx->new;
+       my $scalar = '';
+       open(my $qx, '+>', \$scalar) or die; # PerlIO::scalar
        my $end = sub {
                finish($self, $env);
-               eval { $qx_cb->($qx) };
-               $qx = undef;
+               eval { $qx_cb->(\$scalar) };
+               $qx = $scalar = undef;
        };
        my $rpipe; # comes from popen_rd
        my $async = $env->{'pi-httpd.async'};
@@ -229,6 +229,7 @@ sub psgi_return {
 
        my $buf = '';
        my $rd_hdr = sub {
+               # typically used for reading CGI headers
                # we must loop until EAGAIN for EPOLLET in HTTPD/Async.pm
                # We also need to check EINTR for generic PSGI servers.
                my $ret;
@@ -249,7 +250,7 @@ sub psgi_return {
 
        my $cb = sub {
                my $r = $rd_hdr->() or return;
-               $rd_hdr = undef;
+               $rd_hdr = undef; # done reading headers
                my $filter = delete $env->{'qspawn.filter'};
                if (scalar(@$r) == 3) { # error
                        if ($async) {
@@ -260,6 +261,7 @@ sub psgi_return {
                        }
                        $wcb->($r);
                } elsif ($async) {
+                       # done reading headers, handoff to read body
                        $fh = $wcb->($r); # scalar @$r == 2
                        $fh = filter_fh($fh, $filter) if $filter;
                        $async->async_pass($env->{'psgix.io'}, $fh, \$buf);
@@ -338,21 +340,4 @@ sub setup_rlimit {
        }
 }
 
-# captures everything into a buffer and executes a callback when done
-package PublicInbox::Qspawn::Qx;
-use strict;
-use warnings;
-
-sub new {
-       my ($class) = @_;
-       my $buf = '';
-       bless \$buf, $class;
-}
-
-# called by PublicInbox::HTTPD::Async ($fh->write)
-sub write {
-       ${$_[0]} .= $_[1];
-       undef;
-}
-
 1;