1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # for reading pipes and sockets off the DS event loop
5 package PublicInbox::InputPipe;
8 use parent qw(PublicInbox::DS);
9 use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
12 my ($in, $cb, @args) = @_;
13 my $self = bless { cb => $cb, sock => $in, args => \@args },__PACKAGE__;
14 if ($PublicInbox::DS::in_loop) {
15 eval { $self->SUPER::new($in, EPOLLIN|EPOLLET) };
16 return $in->blocking(0) unless $@; # regular file sets $@
18 event_step($self) while $self->{sock};
24 while (($r = sysread($self->{sock}, $rbuf, 65536))) {
25 $self->{cb}->(@{$self->{args} // []}, $rbuf);
27 if (defined($r)) { # EOF
28 $self->{cb}->(@{$self->{args} // []}, '');
29 } elsif ($!{EAGAIN}) {
32 $self->{cb}->(@{$self->{args} // []}, undef)
34 $self->{sock}->blocking ? delete($self->{sock}) : $self->close