* [PATCH] getline_response
@ 2023-10-19 22:39 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-10-19 22:39 UTC (permalink / raw)
To: spew
---
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.
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-10-19 22:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-19 22:39 [PATCH] getline_response Eric Wong
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).