From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/6] qspawn: improve variable naming and commenting
Date: Tue, 17 Sep 2019 08:31:21 +0000 [thread overview]
Message-ID: <20190917083123.6468-5-e@80x24.org> (raw)
In-Reply-To: <20190917083123.6468-1-e@80x24.org>
Naming $start_cb consistently helps avoid confusing new readers,
and some comments will help with understanding flow
---
lib/PublicInbox/GitHTTPBackend.pm | 2 +-
lib/PublicInbox/Qspawn.pm | 16 +++++++++-------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index c9a7cff..ec8e651 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -204,7 +204,7 @@ sub serve_smart {
$env{PATH_TRANSLATED} = "$git->{git_dir}/$path";
my $rdr = input_prepare($env) or return r(500);
my $qsp = PublicInbox::Qspawn->new([qw(git http-backend)], \%env, $rdr);
- $qsp->psgi_return($env, $limiter, sub {
+ $qsp->psgi_return($env, $limiter, sub { # parse_hdr
my ($r, $bref) = @_;
my $res = parse_cgi_headers($r, $bref) or return; # incomplete
$res->[0] == 403 ? serve_dumb($env, $git, $path) : $res;
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index 10fe534..5a30064 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -44,7 +44,7 @@ sub new ($$$;) {
}
sub _do_spawn {
- my ($self, $cb, $limiter) = @_;
+ my ($self, $start_cb, $limiter) = @_;
my $err;
my ($cmd, $env, $opts) = @{$self->{args}};
my %opts = %{$opts || {}};
@@ -66,7 +66,7 @@ sub _do_spawn {
} else {
$self->{err} = $!;
}
- $cb->($self->{rpipe});
+ $start_cb->($self->{rpipe});
}
sub child_err ($) {
@@ -135,11 +135,11 @@ sub finish ($;$) {
}
sub start {
- my ($self, $limiter, $cb) = @_;
+ my ($self, $limiter, $start_cb) = @_;
if ($limiter->{running} < $limiter->{max}) {
- _do_spawn($self, $cb, $limiter);
+ _do_spawn($self, $start_cb, $limiter);
} else {
- push @{$limiter->{run_queue}}, [ $self, $cb ];
+ push @{$limiter->{run_queue}}, [ $self, $start_cb ];
}
}
@@ -175,11 +175,12 @@ reread:
}
};
$limiter ||= $def_limiter ||= PublicInbox::Qspawn::Limiter->new(32);
- $self->start($limiter, sub { # may run later, much later...
+ $self->start($limiter, sub { # start_cb, may run later, much later...
($rpipe) = @_; # popen_rd result
if ($async) {
# PublicInbox::HTTPD::Async->new($rpipe, $cb, $end)
$async = $async->($rpipe, $cb, $end);
+ # $cb will call ->async_pass or ->close
} else { # generic PSGI
$cb->() while $qx;
}
@@ -254,7 +255,7 @@ sub psgi_return {
$ret;
};
- my $wcb = delete $env->{'qspawn.wcb'};
+ my $wcb = delete $env->{'qspawn.wcb'}; # or PSGI server supplies it
my $async = $env->{'pi-httpd.async'};
my $cb = sub {
@@ -287,6 +288,7 @@ sub psgi_return {
if ($async) {
# PublicInbox::HTTPD::Async->new($rpipe, $cb, $end)
$async = $async->($rpipe, $cb, $end);
+ # $cb will call ->async_pass or ->close
} else { # generic PSGI
$cb->() while $rd_hdr;
}
--
EW
next prev parent reply other threads:[~2019-09-17 8:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-17 8:31 [PATCH 0/6] qspawn-related cleanups, comments, and minor fix Eric Wong
2019-09-17 8:31 ` [PATCH 1/6] qspawn: remove return value from ->finish Eric Wong
2019-09-17 8:31 ` [PATCH 2/6] qspawn: log errors for generic PSGI server users Eric Wong
2019-09-17 8:31 ` [PATCH 3/6] qspawn: shorten lifetime of circular references Eric Wong
2019-09-17 8:31 ` Eric Wong [this message]
2019-09-17 8:31 ` [PATCH 5/6] http: drop unused `$env' variable after delete Eric Wong
2019-09-17 8:31 ` [PATCH 6/6] http: remove unnecessary delete Eric Wong
2019-09-17 9:19 ` [MAYBE] kill rpipe early Eric Wong
2019-09-17 9:40 ` Eric Wong
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
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190917083123.6468-5-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.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).