* [PATCH 04/12] httpd: move pipeline logic into event_step
2021-10-16 1:00 6% [PATCH 00/16] some yak-shaving and annoyance fixes Eric Wong
@ 2021-10-16 1:00 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-10-16 1:00 UTC (permalink / raw)
To: meta
Most of the HTTP server code was written for Danga::Socket and
not fully-transitioned to take advantage of PublicInbox::DS.
This change brings it up-to-date with the style of pipeline
handling used for -imapd and -nntpd.
---
lib/PublicInbox/HTTP.pm | 59 +++++++++++------------------------------
1 file changed, 15 insertions(+), 44 deletions(-)
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 8057481d1ce5..0f4b5047784a 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -37,16 +37,6 @@ use constant {
};
use Errno qw(EAGAIN);
-my $pipelineq = [];
-sub process_pipelineq () {
- my $q = $pipelineq;
- $pipelineq = [];
- foreach (@$q) {
- next unless $_->{sock};
- rbuf_process($_);
- }
-}
-
# Use the same configuration parameter as git since this is primarily
# a slow-client sponge for git-http-backend
# TODO: support per-respository http.maxRequestBuffer somehow...
@@ -86,32 +76,24 @@ sub event_step { # called by PublicInbox::DS
# otherwise we can be buffering infinitely w/o backpressure
return read_input($self) if ref($self->{env});
- my $rbuf = $self->{rbuf} // (\(my $x = ''));
- $self->do_read($rbuf, 8192, length($$rbuf)) or return;
- rbuf_process($self, $rbuf);
-}
-
-sub rbuf_process {
- my ($self, $rbuf) = @_;
- $rbuf //= $self->{rbuf} // (\(my $x = ''));
+ my $rbuf = $self->{rbuf} // (\(my $x = ''));
my %env = %{$self->{httpd}->{env}}; # full hash copy
- my $r = parse_http_request($$rbuf, \%env);
-
- # We do not support Trailers in chunked requests, for now
- # (they are rarely-used and git (as of 2.7.2) does not use them)
- if ($r == -1 || $env{HTTP_TRAILER} ||
- # this length-check is necessary for PURE_PERL=1:
- ($r == -2 && length($$rbuf) > 0x4000)) {
- return quit($self, 400);
- }
- if ($r < 0) { # incomplete
- $self->rbuf_idle($rbuf);
- return $self->requeue;
+ my $r;
+ while (($r = parse_http_request($$rbuf, \%env)) < 0) {
+ # We do not support Trailers in chunked requests, for
+ # now (they are rarely-used and git (as of 2.7.2) does
+ # not use them).
+ # this length-check is necessary for PURE_PERL=1:
+ if ($r == -1 || $env{HTTP_TRAILER} ||
+ ($r == -2 && length($$rbuf) > 0x4000)) {
+ return quit($self, 400);
+ }
+ $self->do_read($rbuf, 8192, length($$rbuf)) or return;
}
$$rbuf = substr($$rbuf, $r);
- my $len = input_prepare($self, \%env);
- defined $len or return write_err($self, undef); # EMFILE/ENFILE
+ my $len = input_prepare($self, \%env) //
+ return write_err($self, undef); # EMFILE/ENFILE
$len ? read_input($self, $rbuf) : app_dispatch($self, undef, $rbuf);
}
@@ -238,22 +220,11 @@ sub identity_write ($$) {
$self->write(\($_[1])) if $_[1] ne '';
}
-sub next_request ($) {
- my ($self) = @_;
- if ($self->{rbuf}) {
- # avoid recursion for pipelined requests
- PublicInbox::DS::requeue(\&process_pipelineq) if !@$pipelineq;
- push @$pipelineq, $self;
- } else { # wait for next request
- $self->requeue;
- }
-}
-
sub response_done {
my ($self, $alive) = @_;
delete $self->{env}; # we're no longer busy
$self->write(\"0\r\n\r\n") if $alive == 2;
- $self->write($alive ? \&next_request : \&close);
+ $self->write($alive ? $self->can('requeue') : \&close);
}
sub getline_pull {
^ permalink raw reply related [relevance 7%]
* [PATCH 00/16] some yak-shaving and annoyance fixes
@ 2021-10-16 1:00 6% Eric Wong
2021-10-16 1:00 7% ` [PATCH 04/12] httpd: move pipeline logic into event_step Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-10-16 1:00 UTC (permalink / raw)
To: meta
Hopefully having less code will make bug-hunting easier and
and more robust in the future at handling failures and
unexpected interrupts (e.g. Ctrl-C).
There's a lot of YAGNI elimination and more to come.
Eric Wong (12):
smsg: add ->oidbin method
dir_idle: do not add watches in ->new
imapd+nntpd: drop timer-based expiration
httpd: move pipeline logic into event_step
lei: golf PATH2CFG cleanup
lei: always keep cwd fd {3} for ->fchdir
lei: more eval guards for die on failure
extindex: prune invalid alternate entries on --gc
lei_overview: die rather than lei->fail
lei_to_mail: quiet down abort messages
inbox + search: use 5.10.1 and do some golfing
httpd/async: switch to level-triggered epoll
Documentation/technical/ds.txt | 3 +-
lib/PublicInbox/DS.pm | 37 +------------------
lib/PublicInbox/Daemon.pm | 8 ++---
lib/PublicInbox/DirIdle.pm | 8 +----
lib/PublicInbox/ExtSearch.pm | 2 +-
lib/PublicInbox/ExtSearchIdx.pm | 19 +++++-----
lib/PublicInbox/HTTP.pm | 64 +++++++++------------------------
lib/PublicInbox/HTTPD/Async.pm | 16 +++------
lib/PublicInbox/IMAP.pm | 17 +++------
lib/PublicInbox/Import.pm | 2 +-
lib/PublicInbox/Inbox.pm | 11 +++---
lib/PublicInbox/LEI.pm | 29 +++++++--------
lib/PublicInbox/LeiLcat.pm | 21 +++++------
lib/PublicInbox/LeiOverview.pm | 24 ++++++-------
lib/PublicInbox/LeiQuery.pm | 24 ++++++-------
lib/PublicInbox/LeiToMail.pm | 1 +
lib/PublicInbox/LeiXSearch.pm | 9 ++---
lib/PublicInbox/MultiGit.pm | 6 +++-
lib/PublicInbox/NNTP.pm | 12 ++-----
lib/PublicInbox/OverIdx.pm | 3 +-
lib/PublicInbox/Qspawn.pm | 1 -
lib/PublicInbox/Search.pm | 7 ++--
lib/PublicInbox/Smsg.pm | 6 ++--
lib/PublicInbox/Watch.pm | 3 +-
t/dir_idle.t | 3 +-
25 files changed, 118 insertions(+), 218 deletions(-)
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-10-16 1:00 6% [PATCH 00/16] some yak-shaving and annoyance fixes Eric Wong
2021-10-16 1:00 7% ` [PATCH 04/12] httpd: move pipeline logic into event_step Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).