]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
input_stream: only rely on events for pipes+sockets
authorEric Wong <e@80x24.org>
Tue, 29 Apr 2025 17:16:47 +0000 (17:16 +0000)
committerEric Wong <e@80x24.org>
Thu, 1 May 2025 21:29:43 +0000 (21:29 +0000)
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.

lib/PublicInbox/InputStream.pm

index e2b5a9b8e03bf05fa9ab8f7ac147d4bdaeaf8287..8f82ccb7d2575f8e19b07e40420cc31439285d86 100644 (file)
@@ -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;
 }