diff options
author | Eric Wong <e@80x24.org> | 2023-09-11 09:41:27 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-09-11 18:51:14 +0000 |
commit | d98a23c63ae1da65b8521fdd6faa9e9fb5f898e9 (patch) | |
tree | c46505bddfb7990c50be65176dd280c814d5bcc1 /lib/PublicInbox/DSKQXS.pm | |
parent | 9231d2e7b93f2739c215c51164569347c90c646a (diff) | |
download | public-inbox-d98a23c63ae1da65b8521fdd6faa9e9fb5f898e9.tar.gz |
The awaitpid API turns out to be quite handy for managing long-lived worker processes. This allows us to ensure all our uses of signalfd (and kevent emulation) are non-blocking.
Diffstat (limited to 'lib/PublicInbox/DSKQXS.pm')
-rw-r--r-- | lib/PublicInbox/DSKQXS.pm | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/PublicInbox/DSKQXS.pm b/lib/PublicInbox/DSKQXS.pm index 3fcb4e40..b6e5c4e9 100644 --- a/lib/PublicInbox/DSKQXS.pm +++ b/lib/PublicInbox/DSKQXS.pm @@ -47,16 +47,15 @@ sub new { # It's wasteful in that it uses another FD, but it simplifies # our epoll-oriented code. sub signalfd { - my ($class, $signo, $nonblock) = @_; + my ($class, $signo) = @_; my $sym = gensym; - tie *$sym, $class, $signo, $nonblock; # calls TIEHANDLE + tie *$sym, $class, $signo; # calls TIEHANDLE $sym } sub TIEHANDLE { # similar to signalfd() - my ($class, $signo, $nonblock) = @_; + my ($class, $signo) = @_; my $self = $class->new; - $self->{timeout} = $nonblock ? 0 : -1; my $kq = $self->{kq}; $kq->EV_SET($_, EVFILT_SIGNAL, EV_ADD) for @$signo; $self; @@ -65,7 +64,6 @@ sub TIEHANDLE { # similar to signalfd() sub READ { # called by sysread() for signalfd compatibility my ($self, undef, $len, $off) = @_; # $_[1] = buf die "bad args for signalfd read" if ($len % 128) // defined($off); - my $timeout = $self->{timeout}; my $sigbuf = $self->{sigbuf} //= []; my $nr = $len / 128; my $r = 0; @@ -78,13 +76,13 @@ sub READ { # called by sysread() for signalfd compatibility $r += 128; } return $r if $r; - my @events = eval { $self->{kq}->kevent($timeout) }; + my @events = eval { $self->{kq}->kevent(0) }; # workaround https://rt.cpan.org/Ticket/Display.html?id=116615 if ($@) { next if $@ =~ /Interrupted system call/; die; } - if (!scalar(@events) && $timeout == 0) { + if (!scalar(@events)) { $! = EAGAIN; return; } |