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, fds, buf, flags) = @_;
14 my ($sock, $fds, undef, $flags) = @_;
16 IO::FDPass::send(fileno($sock), $fd) or
17 die "IO::FDPass::send: $!";
19 send($sock, $_[2], $flags) or die "send $!";
22 *recv_cmd1 = sub ($$$;$) {
23 my ($s, undef, $len, $nfds) = @_;
25 my @fds = map { IO::FDPass::recv(fileno($s)) } (1..$nfds);
26 recv($s, $_[1], $len, 0) // die "recv: $!";
27 length($_[1]) == 0 ? () : @fds;