* Re: [PATCH 5/7] dspoll: switch to the documented IO::Poll API
2023-09-11 9:41 6% ` [PATCH 5/7] dspoll: switch to the documented IO::Poll API Eric Wong
@ 2023-09-12 2:34 7% ` Eric Wong
0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2023-09-12 2:34 UTC (permalink / raw)
To: meta
Eric Wong <e@80x24.org> wrote:
> So switch to the documented API and just learn to live with some
> redundant object references and awkwardness in the API.
Unfortunately, this introduces unintended consequences with
object destruction order and some explicit calls to DS->Reset
(and modifications to destruction order) becomes necessary.
I noticed this testing t/gcf2_client.t (and also realized
libgit2 isn't in the CI deps, gotta add that along with
a few other tweaks brewing...)
So I guess we'll just have to keep an eye on IO::Poll::_poll
changes or replace it with select(2) since it should all
be low-numbered FDs anyways.
^ permalink raw reply [relevance 7%]
* [PATCH 5/7] dspoll: switch to the documented IO::Poll API
2023-09-11 9:41 5% [PATCH 0/7] system-related updates and cleanups Eric Wong
@ 2023-09-11 9:41 6% ` Eric Wong
2023-09-12 2:34 7% ` Eric Wong
0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2023-09-11 9:41 UTC (permalink / raw)
To: meta
IO::Poll::_poll has always been an undocumented API. While it's
remained working so far (since the early 2000s with Danga::Socket),
I'm uncomfortable continuing with it moving forward since it's
not documented (the leading underscore typically means it's
not meant to be used by 3rd-parties).
So switch to the documented API and just learn to live with some
redundant object references and awkwardness in the API.
---
lib/PublicInbox/DSPoll.pm | 43 +++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 22 deletions(-)
diff --git a/lib/PublicInbox/DSPoll.pm b/lib/PublicInbox/DSPoll.pm
index fc282de0..8ab5d19f 100644
--- a/lib/PublicInbox/DSPoll.pm
+++ b/lib/PublicInbox/DSPoll.pm
@@ -13,34 +13,33 @@ use v5.12;
use IO::Poll;
use PublicInbox::Syscall qw(EPOLLONESHOT EPOLLIN EPOLLOUT);
-sub new { bless {}, __PACKAGE__ } # fd => events
+sub new { bless { poll => IO::Poll->new }, __PACKAGE__ } # fd => events
sub ep_wait {
my ($self, $maxevents, $timeout_msec, $events) = @_;
- my @pset;
- while (my ($fd, $events) = each %$self) {
- my $pevents = $events & EPOLLIN ? POLLIN : 0;
- $pevents |= $events & EPOLLOUT ? POLLOUT : 0;
- push(@pset, $fd, $pevents);
- }
- @$events = ();
- my $n = IO::Poll::_poll($timeout_msec, @pset);
- if ($n >= 0) {
- for (my $i = 0; $i < @pset; ) {
- my $fd = $pset[$i++];
- my $revents = $pset[$i++] or next;
- delete($self->{$fd}) if $self->{$fd} & EPOLLONESHOT;
- push @$events, $fd;
- }
- my $nevents = scalar @$events;
- if ($n != $nevents) {
- warn "BUG? poll() returned $n, but got $nevents";
- }
+ $self->{poll}->poll($timeout_msec/1000) > 0 or return (@$events = ());
+ my @io = $self->{poll}->handles(POLLIN|POLLOUT);
+ @$events = map { fileno($_) } @io;
+ for (@$events) {
+ my $io = shift @io;
+ $self->{poll}->remove($io) if delete($self->{oneshot}->{$_});
}
}
-sub ep_del { delete($_[0]->{fileno($_[1])}); 0 }
-sub ep_add { $_[0]->{fileno($_[1])} = $_[2]; 0 }
+sub ep_del {
+ my ($self, $io) = @_;
+ delete $self->{oneshot}->{fileno($io)};
+ $self->{poll}->remove($io);
+ 0;
+}
+
+sub ep_add {
+ my ($self, $io, $ev) = @_;
+ $self->{oneshot}->{fileno($io)} = 1 if $ev & EPOLLONESHOT;
+ $self->{poll}->mask($io, ($ev & EPOLLIN ? POLLIN : 0) |
+ ($ev & EPOLLOUT ? POLLOUT : 0));
+ 0;
+}
no warnings 'once';
*ep_mod = \&ep_add;
^ permalink raw reply related [relevance 6%]
* [PATCH 0/7] system-related updates and cleanups
@ 2023-09-11 9:41 5% Eric Wong
2023-09-11 9:41 6% ` [PATCH 5/7] dspoll: switch to the documented IO::Poll API Eric Wong
0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2023-09-11 9:41 UTC (permalink / raw)
To: meta
2/7 is a very welcome cleanup... I'm liking the `awaitpid' API
quite a bit :> I noticed the bug fixed by 1/7 while working
on 2/7.
3/7 is a welcome cleanup, though 4/7 is debatable...
IMHO epoll is total overkill for processes which will never
see many FDs and can't benefit from EPOLLEXCLUSIVE.
5/7 helps me sleep better at night since I'm uncomfortable
with using undocumented APIs
And a couple of further signal blocking cleanups.
Eric Wong (7):
tests: map CLOFORK->FD_CLOEXEC temporarily for `tail -f'
daemon: depend on DS event_loop in master process, too
ds: use object-oriented API for epoll
favor poll(2) for most daemons
dspoll: switch to the documented IO::Poll API
ds: use constants for @UNBLOCKABLE list
spawn: do not block ABRT/BUS/ILL/SEGV signals
MANIFEST | 1 +
lib/PublicInbox/DS.pm | 60 ++++----
lib/PublicInbox/DSKQXS.pm | 58 ++++----
lib/PublicInbox/DSPoll.pm | 64 ++++-----
lib/PublicInbox/Daemon.pm | 254 ++++++++++++++++------------------
lib/PublicInbox/Epoll.pm | 23 +++
lib/PublicInbox/Sigfd.pm | 12 +-
lib/PublicInbox/Spawn.pm | 11 +-
lib/PublicInbox/SpawnPP.pm | 4 +
lib/PublicInbox/Syscall.pm | 12 +-
lib/PublicInbox/TestCommon.pm | 43 +++++-
t/ds-kqxs.t | 4 +-
t/ds-poll.t | 29 ++--
t/epoll.t | 23 ++-
t/httpd-unix.t | 21 ++-
t/lei-daemon.t | 1 +
t/sigfd.t | 4 +-
t/watch_maildir.t | 1 +
t/xap_helper.t | 7 +-
19 files changed, 323 insertions(+), 309 deletions(-)
create mode 100644 lib/PublicInbox/Epoll.pm
^ permalink raw reply [relevance 5%]
Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-09-11 9:41 5% [PATCH 0/7] system-related updates and cleanups Eric Wong
2023-09-11 9:41 6% ` [PATCH 5/7] dspoll: switch to the documented IO::Poll API Eric Wong
2023-09-12 2:34 7% ` Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).