From: Eric Wong Date: Tue, 29 Apr 2025 17:16:47 +0000 (+0000) Subject: input_stream: only rely on events for pipes+sockets X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9291ff1669cc3de58def072840945c1128ec1b5e;p=thirdparty%2Fpublic-inbox.git input_stream: only rely on events for pipes+sockets If using kevent(2) in the event loop, kevent actually accepts EVFILT_READ for regular files instead of triggering EPERM as epoll_ctl(2) does. This kevent-specific behavior doesn't work with our expected use with static files which don't see modifications. I noticed this on FreeBSD when trying to make lei use kevent for everything instead of select(2) for sockets and kevent for EVFILT_SIGNAL only. --- diff --git a/lib/PublicInbox/InputStream.pm b/lib/PublicInbox/InputStream.pm index e2b5a9b8e..8f82ccb7d 100644 --- a/lib/PublicInbox/InputStream.pm +++ b/lib/PublicInbox/InputStream.pm @@ -10,12 +10,13 @@ use PublicInbox::Syscall qw(EPOLLIN); sub consume { my ($in, $cb, @args) = @_; my $self = bless { cb => $cb, args => \@args }, __PACKAGE__; - eval { $self->SUPER::new($in, EPOLLIN) }; - if ($@) { # regular file (but not w/ select|IO::Poll backends) + if (-p $in || -S _) { + $in->blocking(0); + $self->SUPER::new($in, EPOLLIN); + } else { # regular file (but not w/ select|IO::Poll backends) + $self->{sock} = $in; $self->{-need_rq} = 1; $self->requeue; - } elsif (-p $in || -S _) { # O_NONBLOCK for sockets and pipes - $in->blocking(0); } $self; }