From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] getline_response
Date: Thu, 19 Oct 2023 22:39:44 +0000 [thread overview]
Message-ID: <20231019223944.2160899-1-e@80x24.org> (raw)
---
lib/PublicInbox/GetlineResponse.pm | 20 ++++++++++++++++++++
lib/PublicInbox/Qspawn.pm | 14 ++++++--------
2 files changed, 26 insertions(+), 8 deletions(-)
create mode 100644 lib/PublicInbox/GetlineResponse.pm
diff --git a/lib/PublicInbox/GetlineResponse.pm b/lib/PublicInbox/GetlineResponse.pm
new file mode 100644
index 00000000..44b557fa
--- /dev/null
+++ b/lib/PublicInbox/GetlineResponse.pm
@@ -0,0 +1,20 @@
+# Copyright (C) all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+#
+package PublicInbox::GetlineResponse;
+use parent qw(PublicInbox::InputPipe);
+use v5.12;
+
+sub loop {
+ my ($rpipe, $qsp) = @_;
+ my $self = bless {
+ sock => $rpipe,
+ cb => $qsp->can('ipipe_cb'),
+ args => [ $qsp ]
+ }, __PACKAGE__;
+ $self->event_step while $self->{sock};
+}
+
+sub close { CORE::close(delete($_[0]->{sock})) } # can call waitpid_err
+
+1;
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index 9ac9aec1..c3258338 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -302,7 +302,7 @@ sub psgi_return_start { # may run later, much later...
}
}
-sub _ipipe_cb { # InputPipe callback
+sub ipipe_cb { # InputPipe callback
my ($ipipe, $self) = @_; # $_[-1] rbuf
return yield_chunk($self, $ipipe, $_[-1]) if $self->{qfh}; # stream body
@@ -334,17 +334,15 @@ EOM
sub _yield_start { # may run later, much later...
my ($self) = @_;
- my $async = !!$self->{psgi_env}->{'pi-httpd.async'};
my $rpipe = $self->{rpipe};
- if ($async) {
+ if ($self->{psgi_env}->{'pi-httpd.async'}) {
require PublicInbox::ProcessIONBF;
PublicInbox::ProcessIONBF->replace($rpipe);
+ PublicInbox::InputPipe::consume($rpipe, \&ipipe_cb, $self);
+ } else {
+ require PublicInbox::GetlineResponse;
+ PublicInbox::GetlineResponse::loop($rpipe, $self);
}
- my $ipipe = PublicInbox::InputPipe::consume($rpipe, \&_ipipe_cb, $self);
- return if $async;
- $ipipe->event_step while $ipipe->{sock};
- delete $self->{rpipe};
- close $rpipe; # triggers waitpid_err ASAP
}
# Used for streaming the stdout of one process as a PSGI response.
reply other threads:[~2023-10-19 22:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231019223944.2160899-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).