]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiSelfSocket.pm
dd64b6cfd491f4b4517a18a321c2cd0cf826a38d
[public-inbox.git] / lib / PublicInbox / LeiSelfSocket.pm
1 # Copyright all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # dummy placeholder socket for internal lei commands.
5 # This receives what script/lei receives, but isn't connected
6 # to an interactive terminal so I'm not sure what to do with it...
7 package PublicInbox::LeiSelfSocket;
8 use strict;
9 use v5.10.1;
10 use parent qw(PublicInbox::DS);
11 use Data::Dumper;
12 $Data::Dumper::Useqq = 1; # should've been the Perl default :P
13 use PublicInbox::Syscall qw(EPOLLIN);
14 use PublicInbox::Spawn;
15 my $recv_cmd;
16
17 sub new {
18         my ($cls, $r) = @_;
19         my $self = bless { sock => $r }, $cls;
20         $r->blocking(0);
21         no warnings 'once';
22         $recv_cmd = $PublicInbox::LEI::recv_cmd;
23         $self->SUPER::new($r, EPOLLIN);
24 }
25
26 sub event_step {
27         my ($self) = @_;
28         my (@fds) = $recv_cmd->($self->{sock}, my $buf, 4096 * 33);
29         if (scalar(@fds) == 1 && !defined($fds[0])) {
30                 return if $!{EAGAIN};
31                 die "recvmsg: $!" unless $!{ECONNRESET};
32         } else { # just in case open so perl can auto-close them:
33                 for (@fds) { open my $fh, '+<&=', $_ };
34         }
35         return $self->close if $buf eq '';
36         warn Dumper({ 'unexpected self msg' => $buf, fds => \@fds });
37         # TODO: figure out what to do with these messages...
38 }
39
40 1;