diff options
author | Eric Wong <e@80x24.org> | 2023-10-25 00:29:32 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-25 07:28:36 +0000 |
commit | 92fa0f29774642b848ff23fccda51c4e34342dbe (patch) | |
tree | b4835e8508da1949f41133f6ed3e8fb9e66f3d98 /lib/PublicInbox/InputPipe.pm | |
parent | 8ea09a53c691e2f2980bb09612f45d2a5946340a (diff) | |
download | public-inbox-92fa0f29774642b848ff23fccda51c4e34342dbe.tar.gz |
This is intended to replace psgi_return and HTTPD/Async entirely, hopefully making our code less convoluted while maintaining the ability to handle slow clients on memory-constrained systems This was made possible by the philosophy shift in commit 21a539a2df0c (httpd/async: switch to buffering-as-fast-as-possible, 2019-06-28). We'll still support generic PSGI via the `pull' model with a GetlineResponse class which is similar to the old GetlineBody.
Diffstat (limited to 'lib/PublicInbox/InputPipe.pm')
-rw-r--r-- | lib/PublicInbox/InputPipe.pm | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/PublicInbox/InputPipe.pm b/lib/PublicInbox/InputPipe.pm index b38d8270..f4d57e7d 100644 --- a/lib/PublicInbox/InputPipe.pm +++ b/lib/PublicInbox/InputPipe.pm @@ -39,14 +39,16 @@ sub consume { if ($@) { # regular file (but not w/ select|IO::Poll backends) $self->{-need_rq} = 1; $self->requeue; - } elsif (-p $in || -S _) { # O_NONBLOCK for sockets and pipes + } elsif (do { no warnings 'unopened'; !stat($in) }) { # ProcessIONBF + } elsif (-p _ || -S _) { # O_NONBLOCK for sockets and pipes $in->blocking(0); } elsif (-t $in) { # isatty(3) can't use `_' stat cache unblock_tty($self); } + $self; } -sub close { +sub close { # idempotent my ($self) = @_; if (my $t = delete($self->{restore_termios})) { my $fd = fileno($self->{sock} // return); @@ -60,16 +62,16 @@ sub event_step { my $r = sysread($self->{sock} // return, my $rbuf, 65536); eval { if ($r) { - $self->{cb}->(@{$self->{args}}, $rbuf); + $self->{cb}->($self, @{$self->{args}}, $rbuf); $self->requeue if $self->{-need_rq}; } elsif (defined($r)) { # EOF - $self->{cb}->(@{$self->{args}}, ''); + $self->{cb}->($self, @{$self->{args}}, ''); $self->close } elsif ($!{EAGAIN}) { # rely on EPOLLIN } elsif ($!{EINTR}) { # rely on EPOLLIN for sockets/pipes/tty $self->requeue if $self->{-need_rq}; } else { # another error - $self->{cb}->(@{$self->{args}}, undef); + $self->{cb}->($self, @{$self->{args}}, undef); $self->close; } }; |