# Generic PSGI server for convenience. It aims to provide
# a consistent experience for public-inbox admins so they don't have
# to learn different ways to admin both NNTP and HTTP components.
-# There's nothing public-inbox-specific, here.
+# There's nothing which depends on public-inbox, here.
# Each instance of this class represents a HTTP client socket
package PublicInbox::HTTP;
CHUNK_MAX_HDR => 256,
};
-# FIXME: duplicated code with NNTP.pm
+# FIXME: duplicated code with NNTP.pm, layering violation
my $WEAKEN = {}; # string(inbox) -> inbox
my $weakt;
sub weaken_task () {
$self->{env} = undef;
$self->write("0\r\n\r\n") if $alive == 2;
$self->write(sub { $alive ? next_request($self) : $self->close });
+
+ # FIXME: layering violation
if (my $obj = $env->{'pi-httpd.inbox'}) {
# grace period for reaping resources
$WEAKEN->{"$obj"} = $obj;
my $pull = $self->{pull} = sub {
local $/ = \8192;
my $forward = $self->{forward};
+ # limit our own running time for fairness with other
+ # clients and to avoid buffering too much:
while ($forward && defined(my $buf = $forward->getline)) {
$write->($buf);
last if $self->{closed};
if ($self->{write_buf_size}) {
$self->write($self->{pull});
- return;
+ } else {
+ PublicInbox::EvCleanup::asap($self->{pull});
}
+ return;
}
$self->{forward} = $self->{pull} = undef;
$forward->close if $forward; # avoid recursion