]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiSelfSocket.pm
lei: start implementing inotify Maildir support
[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 EPOLLET);
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|EPOLLET);
24 }
25
26 sub event_step {
27         my ($self) = @_;
28         while (1) {
29                 my (@fds) = $recv_cmd->($self->{sock}, my $buf, 4096 * 33);
30                 if (scalar(@fds) == 1 && !defined($fds[0])) {
31                         return if $!{EAGAIN};
32                         next if $!{EINTR};
33                         die "recvmsg: $!";
34                 }
35                 # open so perl can auto-close them:
36                 for my $fd (@fds) {
37                         open(my $newfh, '+<&=', $fd) or die "open +<&=$fd: $!";
38                 }
39                 return $self->close if $buf eq '';
40                 warn Dumper({ 'unexpected self msg' => $buf, fds => \@fds });
41                 # TODO: figure out what to do with these messages...
42         }
43 }
44
45 1;