]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/EOFpipe.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / EOFpipe.pm
1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 package PublicInbox::EOFpipe;
5 use v5.12;
6 use parent qw(PublicInbox::DS);
7 use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
8
9 sub new {
10         my (undef, $rd, $cb) = @_;
11         my $self = bless { cb => $cb }, __PACKAGE__;
12         # 1031: F_SETPIPE_SZ, 4096: page size
13         fcntl($rd, 1031, 4096) if $^O eq 'linux';
14         $self->SUPER::new($rd, EPOLLIN|EPOLLONESHOT);
15 }
16
17 sub event_step {
18         my ($self) = @_;
19         if ($self->do_read(my $buf, 1) == 0) { # auto-closed
20                 $self->{cb}->();
21         }
22 }
23
24 1;