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, args => \@args }, __PACKAGE__;
14 eval { $self->SUPER::new($in, EPOLLIN|EPOLLET) };
15 return $self->requeue if $@; # regular file
16 $in->blocking(0); # pipe or socket
21 my $r = sysread($self->{sock}, my $rbuf, 65536);
23 $self->{cb}->(@{$self->{args} // []}, $rbuf);
24 return $self->requeue; # may be regular file or pipe
26 if (defined($r)) { # EOF
27 $self->{cb}->(@{$self->{args} // []}, '');
28 } elsif ($!{EAGAIN}) {
30 } else { # another error
31 $self->{cb}->(@{$self->{args} // []}, undef)
33 $self->{sock}->blocking ? delete($self->{sock}) : $self->close