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
# 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'};
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;
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) {
}
$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);
}
}
-# 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;