1 # Copyright (C) 2019-2021 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 = $ENV{TEST_IOPOLLER} // 'PublicInbox::DSPoll';
17 is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($r), EPOLLIN), 0, 'add EPOLLIN');
19 $p->epoll_wait(9, 0, $events);
20 is_deeply($events, [], 'no events set');
21 is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($w), EPOLLOUT|EPOLLONESHOT), 0,
22 'add EPOLLOUT|EPOLLONESHOT');
23 $p->epoll_wait(9, -1, $events);
24 is(scalar(@$events), 1, 'got POLLOUT event');
25 is($events->[0], fileno($w), '$w ready');
27 $p->epoll_wait(9, 0, $events);
28 is(scalar(@$events), 0, 'nothing ready after oneshot');
29 is_deeply($events, [], 'no events set after oneshot');
31 syswrite($w, '1') == 1 or die;
33 $p->epoll_wait(9, $t, $events);
34 is($events->[0], fileno($r), "level-trigger POLLIN ready #$t");
35 is(scalar(@$events), 1, "only event ready #$t");
37 syswrite($y, '1') == 1 or die;
38 is($p->epoll_ctl(EPOLL_CTL_ADD, fileno($x), EPOLLIN|EPOLLONESHOT), 0,
39 'EPOLLIN|EPOLLONESHOT add');
40 $p->epoll_wait(9, -1, $events);
41 is(scalar @$events, 2, 'epoll_wait has 2 ready');
42 my @fds = sort @$events;
43 my @exp = sort((fileno($r), fileno($x)));
44 is_deeply(\@fds, \@exp, 'got both ready FDs');
46 is($p->epoll_ctl(EPOLL_CTL_DEL, fileno($r), 0), 0, 'EPOLL_CTL_DEL OK');
47 $p->epoll_wait(9, 0, $events);
48 is(scalar @$events, 0, 'nothing ready after EPOLL_CTL_DEL');