1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # for PublicInbox::IPC wq_* (work queue) workers
5 package PublicInbox::WQWorker;
8 use parent qw(PublicInbox::DS);
9 use PublicInbox::Syscall qw(EPOLLIN EPOLLEXCLUSIVE EPOLLET);
10 use Errno qw(EAGAIN ECONNRESET);
11 use IO::Handle (); # blocking
14 my ($cls, $wq, $field) = @_;
15 my $s2 = $wq->{$field // '-wq_s2'} // die "BUG: no {$field}";
17 my $self = bless { sock => $s2, wq => $wq }, $cls;
18 $self->SUPER::new($s2, EPOLLEXCLUSIVE|EPOLLIN|EPOLLET);
26 $n = $self->{wq}->recv_and_run($self->{sock}, 4096 * 33);
28 return if !defined($n) && $! == EAGAIN; # likely
29 warn "wq worker error: $!\n" if !defined($n) && $! != ECONNRESET;
30 $self->{wq}->wq_atexit_child if $self->{sock} == $self->{wq}->{-wq_s2};
31 $self->close; # PublicInbox::DS::close