]> Sergey Matveev's repositories - public-inbox.git/blob - t/epoll.t
f2a68904a5b3ceb221746c18f7c180c84805f267
[public-inbox.git] / t / epoll.t
1 use strict;
2 use Test::More;
3 use IO::Handle;
4 use PublicInbox::Syscall qw(:epoll);
5 plan skip_all => 'not Linux' if $^O ne 'linux';
6 my $epfd = epoll_create();
7 ok($epfd >= 0, 'epoll_create');
8 my $hnd = IO::Handle->new_from_fd($epfd, 'r+'); # close on exit
9
10 pipe(my ($r, $w)) or die "pipe: $!";
11 is(epoll_ctl($epfd, EPOLL_CTL_ADD, fileno($w), EPOLLOUT), 0,
12     'epoll_ctl socket EPOLLOUT');
13
14 my @events;
15 epoll_wait($epfd, 100, 10000, \@events);
16 is(scalar(@events), 1, 'got one event');
17 is($events[0], fileno($w), 'got expected FD');
18 close $w;
19 epoll_wait($epfd, 100, 0, \@events);
20 is(scalar(@events), 0, 'epoll_wait timeout');
21
22 done_testing;