]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/EOFpipe.pm
489caf82018b1f077bd85e5366c167448a071a9d
[public-inbox.git] / lib / PublicInbox / EOFpipe.pm
1 # Copyright (C) 2020 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 strict;
6 use parent qw(PublicInbox::DS);
7 use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
8
9 sub new {
10         my (undef, $rd, $cb, $arg) = @_;
11         my $self = bless {  cb => $cb, arg => $arg }, __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}->($self->{arg});
21         }
22 }
23
24 1;