# Copyright (C) 2021 all contributors # License: AGPL-3.0+ # for PublicInbox::IPC wq_* (work queue) workers package PublicInbox::WQWorker; use strict; use v5.10.1; use parent qw(PublicInbox::DS); use PublicInbox::Syscall qw(EPOLLIN EPOLLEXCLUSIVE EPOLLET); use Errno qw(EAGAIN ECONNRESET); use IO::Handle (); # blocking sub new { my ($cls, $wq, $field) = @_; my $s2 = $wq->{$field // '-wq_s2'} // die "BUG: no {$field}"; $s2->blocking(0); my $self = bless { sock => $s2, wq => $wq }, $cls; $self->SUPER::new($s2, EPOLLEXCLUSIVE|EPOLLIN|EPOLLET); $self; } sub event_step { my ($self) = @_; my $n; do { $n = $self->{wq}->recv_and_run($self->{sock}); } while ($n); return if !defined($n) && $! == EAGAIN; # likely warn "wq worker error: $!\n" if !defined($n) && $! != ECONNRESET; $self->{wq}->wq_atexit_child if $self->{sock} == $self->{wq}->{-wq_s2}; $self->close; # PublicInbox::DS::close } 1;