X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FIPC.pm;h=7486267322b082f6d326a20bb03b3a02189e8726;hb=23af251dd607c4e75ab1e68063f2c885c48cc035;hp=3e299448b334629fb6427e7df02976381ec19242;hpb=a1733d3406dfbde52d1468e671edd1d76893f546;p=public-inbox.git
diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm
index 3e299448..74862673 100644
--- a/lib/PublicInbox/IPC.pm
+++ b/lib/PublicInbox/IPC.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2020-2021 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
# base class for remote IPC calls and workqueues, requires Storable or Sereal
@@ -43,10 +43,14 @@ if ($enc && $dec) { # should be custom ops
}
my $recv_cmd = PublicInbox::Spawn->can('recv_cmd4');
-my $send_cmd = PublicInbox::Spawn->can('send_cmd4') // do {
+our $send_cmd = PublicInbox::Spawn->can('send_cmd4') // do {
require PublicInbox::CmdIPC4;
$recv_cmd //= PublicInbox::CmdIPC4->can('recv_cmd4');
PublicInbox::CmdIPC4->can('send_cmd4');
+} // do {
+ require PublicInbox::Syscall;
+ $recv_cmd //= PublicInbox::Syscall->can('recv_cmd4');
+ PublicInbox::Syscall->can('send_cmd4');
};
sub _get_rec ($) {
@@ -247,7 +251,7 @@ sub recv_and_run {
undef $buf;
my $sub = shift @$args;
eval { $self->$sub(@$args) };
- warn "$$ $0 wq_worker: $@" if $@;
+ warn "$$ $0 wq_worker: $sub: $@" if $@;
delete @$self{0..($nfd-1)};
$n;
}
@@ -344,6 +348,24 @@ sub wq_do {
}
}
+sub prepare_nonblock {
+ ($_[0]->{-wq_s1} // die 'BUG: no {-wq_s1}')->blocking(0);
+ $_[0]->{-reap_async} or die 'BUG: {-reap_async} needed for nonblock';
+ require PublicInbox::WQBlocked;
+}
+
+sub wq_nonblock_do { # always async
+ my ($self, $sub, @args) = @_;
+ my $buf = ipc_freeze([$sub, @args]);
+ if ($self->{wqb}) { # saturated once, assume saturated forever
+ $self->{wqb}->flush_send($buf);
+ } else {
+ $send_cmd->($self->{-wq_s1}, [], $buf, MSG_EOR) //
+ ($!{EAGAIN} ? PublicInbox::WQBlocked->new($self, $buf)
+ : croak("sendmsg: $!"));
+ }
+}
+
sub _wq_worker_start ($$$$) {
my ($self, $oldset, $fields, $one) = @_;
my ($bcast1, $bcast2);
@@ -401,6 +423,10 @@ sub wq_workers_start {
sub wq_close {
my ($self) = @_;
+ if (my $wqb = delete $self->{wqb}) {
+ $self->{-reap_async} or die 'BUG: {-reap_async} unset';
+ $wqb->enq_close;
+ }
delete @$self{qw(-wq_s1 -wq_s2)} or return;
return if $self->{-reap_async};
my @pids = keys %{$self->{-wq_workers}};