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 # callers should use PublicInbox::CmdIPC1->can('send_cmd1') (or recv_cmd1)
5 # 2nd choice for lei(1) front-end and 3rd choice for lei internals
6 package PublicInbox::CmdIPC1;
10 require IO::FDPass; # XS, available in all major distros
13 *send_cmd1 = sub ($$$$$$) { # (sock, in, out, err, buf, flags) = @_;
15 IO::FDPass::send(fileno($_[0]), $_[$_]) or
16 die "IO::FDPass::send: $!";
18 send($_[0], $_[4], $_[5]) or die "send $!";
21 *recv_cmd1 = sub ($$$) {
22 my ($s, undef, $len) = @_;
23 my @fds = map { IO::FDPass::recv(fileno($s)) } (0..2);
24 recv($s, $_[1], $len, 0) // die "recv: $!";
25 length($_[1]) == 0 ? () : @fds;