about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-10-16 09:29:52 +0000
committerEric Wong <e@80x24.org>2021-10-16 10:37:08 +0000
commit932fea644c612d55d9a5299794c381bb7155f18b (patch)
tree3b2aeca5099a8512327299334865d000a5aade72
parentd5a668f3e30a195336dc5b86ecf2b339e6d1fcad (diff)
downloadpublic-inbox-932fea644c612d55d9a5299794c381bb7155f18b.tar.gz
input_pipe: do not loop in ->event_step for fairness
Sigfd->event_step needs priority over InputPipe (and everything
else).  We keep Edge Triggering here but use ->requeue instead
of looping inside event_step.  This was necessary because
InputPipe can be used with regular files which can't be
monitored with epoll.

We'll also rid of the vestigial lei-oneshot support while we're
at it.
-rw-r--r--lib/PublicInbox/InputPipe.pm17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/PublicInbox/InputPipe.pm b/lib/PublicInbox/InputPipe.pm
index a8bdf031..00813a07 100644
--- a/lib/PublicInbox/InputPipe.pm
+++ b/lib/PublicInbox/InputPipe.pm
@@ -10,25 +10,24 @@ use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
 
 sub consume {
         my ($in, $cb, @args) = @_;
-        my $self = bless { cb => $cb, sock => $in, args => \@args },__PACKAGE__;
-        if ($PublicInbox::DS::in_loop) {
-                eval { $self->SUPER::new($in, EPOLLIN|EPOLLET) };
-                return $in->blocking(0) unless $@; # regular file sets $@
-        }
-        event_step($self) while $self->{sock};
+        my $self = bless { cb => $cb, args => \@args }, __PACKAGE__;
+        eval { $self->SUPER::new($in, EPOLLIN|EPOLLET) };
+        return $self->requeue if $@; # regular file
+        $in->blocking(0); # pipe or socket
 }
 
 sub event_step {
         my ($self) = @_;
-        my ($r, $rbuf);
-        while (($r = sysread($self->{sock}, $rbuf, 65536))) {
+        my $r = sysread($self->{sock}, my $rbuf, 65536);
+        if ($r) {
                 $self->{cb}->(@{$self->{args} // []}, $rbuf);
+                return $self->requeue; # may be regular file or pipe
         }
         if (defined($r)) { # EOF
                 $self->{cb}->(@{$self->{args} // []}, '');
         } elsif ($!{EAGAIN}) {
                 return;
-        } else {
+        } else { # another error
                 $self->{cb}->(@{$self->{args} // []}, undef)
         }
         $self->{sock}->blocking ? delete($self->{sock}) : $self->close