From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 69B6F1F406 for ; Thu, 19 Oct 2023 22:39:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1697755184; bh=QYPEY4I1N+Kba+dwfutXf/TIVa8Viz1qnqB0zt67Ekw=; h=From:To:Subject:Date:From; b=LPFlX2XOonFWiOK2rfcGZm7x5R0OdwexGnwkSwaMT68WIaWRgCF7DWjf6Os8vocrM oOXSkgiYcGY5i9PPrQgdUlSsT+BbilCb8Wcd3W7QCK39StZVFybVmSd24O1NLzkBcB afQGF0usJSHS4RUg4H/t0ieaLXlgFdzYx9eG4fww= From: Eric Wong To: spew@80x24.org Subject: [PATCH] getline_response Date: Thu, 19 Oct 2023 22:39:44 +0000 Message-ID: <20231019223944.2160899-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- 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 +# License: AGPL-3.0+ +# +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.