]> Sergey Matveev's repositories - public-inbox.git/blob - t/epoll.t
No ext_urls
[public-inbox.git] / t / epoll.t
1 #!perl -w
2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use Test::More;
7 use PublicInbox::Syscall qw(:epoll);
8 plan skip_all => 'not Linux' if $^O ne 'linux';
9 my $epfd = epoll_create();
10 ok($epfd >= 0, 'epoll_create');
11 open(my $hnd, '+<&=', $epfd); # for autoclose
12
13 pipe(my ($r, $w)) or die "pipe: $!";
14 is(epoll_ctl($epfd, EPOLL_CTL_ADD, fileno($w), EPOLLOUT), 0,
15     'epoll_ctl socket EPOLLOUT');
16
17 my @events;
18 epoll_wait($epfd, 100, 10000, \@events);
19 is(scalar(@events), 1, 'got one event');
20 is($events[0], fileno($w), 'got expected FD');
21 close $w;
22 epoll_wait($epfd, 100, 0, \@events);
23 is(scalar(@events), 0, 'epoll_wait timeout');
24
25 done_testing;