From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] input_pipe: do not loop in ->event_step for fairness
Date: Sat, 16 Oct 2021 09:29:52 +0000 [thread overview]
Message-ID: <20211016092953.32649-4-e@80x24.org> (raw)
In-Reply-To: <20211016092953.32649-1-e@80x24.org>
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.
---
lib/PublicInbox/InputPipe.pm | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/lib/PublicInbox/InputPipe.pm b/lib/PublicInbox/InputPipe.pm
index a8bdf0318223..00813a0701b1 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
next prev parent reply other threads:[~2021-10-16 9:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-16 9:29 [PATCH 0/4] lei: prioritize signals Eric Wong
2021-10-16 9:29 ` [PATCH 1/4] wqworker: favor level-triggered epoll for fairness Eric Wong
2021-10-16 9:29 ` [PATCH 2/4] pkt_op: " Eric Wong
2021-10-16 9:29 ` Eric Wong [this message]
2021-10-16 9:29 ` [PATCH 4/4] lei sockets: " Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211016092953.32649-4-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).