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/DSPoll.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/DSPoll.pm')
-rw-r--r-- | lib/PublicInbox/DSPoll.pm | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/lib/PublicInbox/DSPoll.pm b/lib/PublicInbox/DSPoll.pm index 56a400c2..fc282de0 100644 --- a/lib/PublicInbox/DSPoll.pm +++ b/lib/PublicInbox/DSPoll.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org> +# Copyright (C) all contributors <meta@public-inbox.org> # Licensed the same as Danga::Socket (and Perl5) # License: GPL-1.0+ or Artistic-1.0-Perl # <https://www.gnu.org/licenses/gpl-1.0.txt> @@ -9,28 +9,13 @@ # an all encompassing emulation of epoll via IO::Poll, but just to # support cases public-inbox-nntpd/httpd care about. package PublicInbox::DSPoll; -use strict; -use warnings; -use parent qw(Exporter); +use v5.12; use IO::Poll; -use PublicInbox::Syscall qw(EPOLLONESHOT EPOLLIN EPOLLOUT EPOLL_CTL_DEL); -our @EXPORT_OK = qw(epoll_ctl epoll_wait); +use PublicInbox::Syscall qw(EPOLLONESHOT EPOLLIN EPOLLOUT); -sub new { bless {}, $_[0] } # fd => events +sub new { bless {}, __PACKAGE__ } # fd => events -sub epoll_ctl { - my ($self, $op, $fd, $ev) = @_; - - # not wasting time on error checking - if ($op != EPOLL_CTL_DEL) { - $self->{$fd} = $ev; - } else { - delete $self->{$fd}; - } - 0; -} - -sub epoll_wait { +sub ep_wait { my ($self, $maxevents, $timeout_msec, $events) = @_; my @pset; while (my ($fd, $events) = each %$self) { @@ -54,4 +39,10 @@ sub epoll_wait { } } +sub ep_del { delete($_[0]->{fileno($_[1])}); 0 } +sub ep_add { $_[0]->{fileno($_[1])} = $_[2]; 0 } + +no warnings 'once'; +*ep_mod = \&ep_add; + 1; |