diff options
author | Eric Wong <e@80x24.org> | 2023-09-11 09:41:28 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-09-11 18:51:14 +0000 |
commit | 3005c1bc5d053222892553f14334d86febb72797 (patch) | |
tree | c90aa738a5eb383b11b5eebf9a694d8725e3475f /lib/PublicInbox/Epoll.pm | |
parent | d98a23c63ae1da65b8521fdd6faa9e9fb5f898e9 (diff) | |
download | public-inbox-3005c1bc5d053222892553f14334d86febb72797.tar.gz |
This allows us to cut down on imports and reduce code. This also makes it easier (in the next commit) to provide an option to disable epoll/kqueue when saving an FD is valued over scalability.
Diffstat (limited to 'lib/PublicInbox/Epoll.pm')
-rw-r--r-- | lib/PublicInbox/Epoll.pm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/PublicInbox/Epoll.pm b/lib/PublicInbox/Epoll.pm new file mode 100644 index 00000000..d55c8535 --- /dev/null +++ b/lib/PublicInbox/Epoll.pm @@ -0,0 +1,23 @@ +# 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) } +sub ep_wait { epoll_wait(fileno(${$_[0]}), @_[1, 2, 3]) } + +1; |