public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob 7e0aa6e7921d4d5ae7a05aad9a973fd82065ad9e 916 bytes (raw)
$ git show HEAD:lib/PublicInbox/Epoll.pm	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# OO API for epoll
package PublicInbox::Epoll;
use v5.12;
use PublicInbox::Syscall qw(epoll_create epoll_ctl epoll_wait
	EPOLL_CTL_ADD EPOLL_CTL_MOD EPOLL_CTL_DEL);
use Fcntl qw(F_SETFD FD_CLOEXEC);
use autodie qw(open fcntl);

sub new {
	open(my $fh, '+<&=', epoll_create());
	fcntl($fh, F_SETFD, FD_CLOEXEC);
	bless \$fh, __PACKAGE__;
}

sub ep_add { epoll_ctl(fileno(${$_[0]}), EPOLL_CTL_ADD, fileno($_[1]), $_[2]) }
sub ep_mod { epoll_ctl(fileno(${$_[0]}), EPOLL_CTL_MOD, fileno($_[1]), $_[2]) }
sub ep_del { epoll_ctl(fileno(${$_[0]}), EPOLL_CTL_DEL, fileno($_[1]), 0) }

# n.b. maxevents=1000 is the historical default.  maxevents=1 (yes, one)
# is more fair under load with multiple worker processes sharing one listener
sub ep_wait { epoll_wait(fileno(${$_[0]}), 1000, @_[1, 2]) }

1;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git