1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # Licensed the same as Danga::Socket (and Perl5)
3 # License: GPL-1.0+ or Artistic-1.0-Perl
4 # <https://www.gnu.org/licenses/gpl-1.0.txt>
5 # <https://dev.perl.org/licenses/artistic.html>
9 use PublicInbox::Syscall qw(:epoll);
10 my $cls = 'PublicInbox::DSPoll';
17 is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($r), EPOLLIN), 0, 'add EPOLLIN');
19 my $n = $p->epoll_wait(9, 0, $events);
20 is_deeply($events, [], 'no events set');
21 is($n, 0, 'nothing ready, yet');
22 is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($w), EPOLLOUT|EPOLLONESHOT), 0,
23 'add EPOLLOUT|EPOLLONESHOT');
24 $n = $p->epoll_wait(9, -1, $events);
25 is($n, 1, 'got POLLOUT event');
26 is($events->[0]->[0], fileno($w), '$w ready');
28 $n = $p->epoll_wait(9, 0, $events);
29 is($n, 0, 'nothing ready after oneshot');
30 is_deeply($events, [], 'no events set after oneshot');
32 syswrite($w, '1') == 1 or die;
34 $n = $p->epoll_wait(9, $t, $events);
35 is($events->[0]->[0], fileno($r), "level-trigger POLLIN ready #$t");
36 is($n, 1, "only event ready #$t");
38 syswrite($y, '1') == 1 or die;
39 is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($x), EPOLLIN|EPOLLONESHOT), 0,
40 'EPOLLIN|EPOLLONESHOT add');
41 is($p->epoll_wait(9, -1, $events), 2, 'epoll_wait has 2 ready');
42 my @fds = sort(map { $_->[0] } @$events);
43 my @exp = sort((fileno($r), fileno($x)));
44 is_deeply(\@fds, \@exp, 'got both ready FDs');
46 # EPOLL_CTL_DEL doesn't matter for kqueue, we do it in native epoll
47 # to avoid a kernel-wide lock; but its not needed for native kqueue
48 # paths so DSKQXS makes it a noop (as did Danga::Socket::close).
50 if ($cls ne 'PublicInbox::DSPoll') {
51 skip "$cls doesn't handle EPOLL_CTL_DEL", 2;
53 is($p->epoll_ctl(EPOLL_CTL_DEL, fileno($r), 0), 0, 'EPOLL_CTL_DEL OK');
54 $n = $p->epoll_wait(9, 0, $events);
55 is($n, 0, 'nothing ready after EPOLL_CTL_DEL');