lib/PublicInbox/ConfigIter.pm | 2 +-
lib/PublicInbox/DS.pm | 60 ++++++++++++++++++++++++++++++-----------------------
lib/PublicInbox/DSKQXS.pm | 10 +++++-----
lib/PublicInbox/Daemon.pm | 14 ++------------
lib/PublicInbox/ExtMsg.pm | 2 +-
lib/PublicInbox/ExtSearchIdx.pm | 12 ++----------
lib/PublicInbox/Gcf2Client.pm | 4 ++--
lib/PublicInbox/IPC.pm | 3 +--
lib/PublicInbox/LEI.pm | 17 ++---------------
lib/PublicInbox/Qspawn.pm | 2 +-
lib/PublicInbox/Sigfd.pm | 10 +++++-----
lib/PublicInbox/Syscall.pm | 12 ++++++------
lib/PublicInbox/Watch.pm | 3 +--
script/public-inbox-watch | 9 ---------
t/dir_idle.t | 6 +++---
t/ds-leak.t | 4 ++--
t/imapd.t | 6 +++---
t/nntpd.t | 2 +-
t/sigfd.t | 7 +++----
t/watch_maildir.t | 2 +-
xt/mem-imapd-tls.t | 6 +++---
xt/net_writer-imap.t | 2 +-
diff --git a/lib/PublicInbox/ConfigIter.pm b/lib/PublicInbox/ConfigIter.pm
index 24cb09bfdc4441279fe7a8c6c7c3bcbbf915bf50..14fcef83f2293d85e3798bc47e43736052823209 100644
--- a/lib/PublicInbox/ConfigIter.pm
+++ b/lib/PublicInbox/ConfigIter.pm
@@ -1,7 +1,7 @@
# Copyright (C) 2020-2021 all contributors
# License: AGPL-3.0+
-# Intended for PublicInbox::DS->EventLoop in read-only daemons
+# Intended for PublicInbox::DS::event_loop in read-only daemons
# to avoid each_inbox() monopolizing the event loop when hundreds/thousands
# of inboxes are in play.
package PublicInbox::ConfigIter;
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 37cd6087cafb2bd8009921f86c27d7de741c6125..ba6c74d0ea97d51e069a85bdef6ad3123cc7e4d5 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -155,13 +155,6 @@ $cls->new;
}
}
-=head2 C<< CLASS->EventLoop() >>
-
-Start processing IO events. In most daemon programs this never exits. See
-C below for how to exit the loop.
-
-=cut
-
sub now () { clock_gettime(CLOCK_MONOTONIC) }
sub next_tick () {
@@ -277,26 +270,41 @@ # by default we keep running, unless a postloop callback cancels it
$PostLoopCallback ? $PostLoopCallback->(\%DescriptorMap) : 1;
}
-sub EventLoop {
- $Epoll //= _InitPoller();
- local $in_loop = 1;
- my @events;
- do {
- my $timeout = RunTimers();
+# Start processing IO events. In most daemon programs this never exits. See
+# C for how to exit the loop.
+sub event_loop (;$$) {
+ my ($sig, $oldset) = @_;
+ $Epoll //= _InitPoller();
+ require PublicInbox::Sigfd if $sig;
+ my $sigfd = PublicInbox::Sigfd->new($sig, 1) if $sig;
+ local @SIG{keys %$sig} = values(%$sig) if $sig && !$sigfd;
+ local $SIG{PIPE} = 'IGNORE';
+ if (!$sigfd && $sig) {
+ # wake up every second to accept signals if we don't
+ # have signalfd or IO::KQueue:
+ sig_setmask($oldset);
+ PublicInbox::DS->SetLoopTimeout(1000);
+ }
+ $_[0] = $sigfd = $sig = undef; # $_[0] == sig
+ local $in_loop = 1;
+ my @events;
+ do {
+ my $timeout = RunTimers();
- # get up to 1000 events
- epoll_wait($Epoll, 1000, $timeout, \@events);
- for my $fd (@events) {
- # it's possible epoll_wait returned many events, including some at the end
- # that ones in the front triggered unregister-interest actions. if we
- # can't find the %sock entry, it's because we're no longer interested
- # in that event.
+ # get up to 1000 events
+ epoll_wait($Epoll, 1000, $timeout, \@events);
+ for my $fd (@events) {
+ # it's possible epoll_wait returned many events,
+ # including some at the end that ones in the front
+ # triggered unregister-interest actions. if we can't
+ # find the %sock entry, it's because we're no longer
+ # interested in that event.
- # guard stack-not-refcounted w/ Carp + @DB::args
- my $obj = $DescriptorMap{$fd};
- $obj->event_step;
- }
- } while (PostEventLoop());
+ # guard stack-not-refcounted w/ Carp + @DB::args
+ my $obj = $DescriptorMap{$fd};
+ $obj->event_step;
+ }
+ } while (PostEventLoop());
}
=head2 C<< CLASS->SetPostLoopCallback( CODEREF ) >>
@@ -326,7 +334,7 @@
=head2 C<< CLASS->new( $socket ) >>
Create a new PublicInbox::DS subclass object for the given I which will
-react to events on it during the C.
+react to events on it during the C.
This is normally (always?) called from your subclass via:
diff --git a/lib/PublicInbox/DSKQXS.pm b/lib/PublicInbox/DSKQXS.pm
index acc31d9baa2242c75487510b87111574e1c98078..eccfa56d72cb5fc8d2151a6f2f1f4b19e9251ce9 100644
--- a/lib/PublicInbox/DSKQXS.pm
+++ b/lib/PublicInbox/DSKQXS.pm
@@ -18,7 +18,7 @@ use Symbol qw(gensym);
use IO::KQueue;
use Errno qw(EAGAIN);
use PublicInbox::Syscall qw(EPOLLONESHOT EPOLLIN EPOLLOUT EPOLLET
- EPOLL_CTL_ADD EPOLL_CTL_MOD EPOLL_CTL_DEL SFD_NONBLOCK);
+ EPOLL_CTL_ADD EPOLL_CTL_MOD EPOLL_CTL_DEL);
our @EXPORT_OK = qw(epoll_ctl epoll_wait);
sub EV_DISPATCH () { 0x0080 }
@@ -48,16 +48,16 @@ # returns a new instance which behaves like signalfd on Linux.
# It's wasteful in that it uses another FD, but it simplifies
# our epoll-oriented code.
sub signalfd {
- my ($class, $signo, $flags) = @_;
+ my ($class, $signo, $nonblock) = @_;
my $sym = gensym;
- tie *$sym, $class, $signo, $flags; # calls TIEHANDLE
+ tie *$sym, $class, $signo, $nonblock; # calls TIEHANDLE
$sym
}
sub TIEHANDLE { # similar to signalfd()
- my ($class, $signo, $flags) = @_;
+ my ($class, $signo, $nonblock) = @_;
my $self = $class->new;
- $self->{timeout} = ($flags & SFD_NONBLOCK) ? 0 : -1;
+ $self->{timeout} = $nonblock ? 0 : -1;
my $kq = $self->{kq};
$kq->EV_SET($_, EVFILT_SIGNAL, EV_ADD) for @$signo;
$self;
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 24dc7791b43de73eaa51e9984c1fc08c3dc92e2b..5be474fa8754f8a069b722968fff0a35de66c87a 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -15,7 +15,6 @@ use Socket qw(IPPROTO_TCP SOL_SOCKET);
STDOUT->autoflush(1);
STDERR->autoflush(1);
use PublicInbox::DS qw(now);
-use PublicInbox::Syscall qw(SFD_NONBLOCK);
require PublicInbox::Listener;
use PublicInbox::EOFpipe;
use PublicInbox::Sigfd;
@@ -513,7 +512,7 @@ $worker_processes = --$set_workers if $set_workers > 0;
},
CHLD => \&reap_children,
};
- my $sigfd = PublicInbox::Sigfd->new($sig, 0);
+ my $sigfd = PublicInbox::Sigfd->new($sig);
local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
PublicInbox::DS::sig_setmask($oldset) if !$sigfd;
while (1) { # main loop
@@ -630,20 +629,11 @@
# this calls epoll_create:
PublicInbox::Listener->new($_, $tls_cb || $post_accept)
} @listeners;
- my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
- local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
- if (!$sigfd) {
- # wake up every second to accept signals if we don't
- # have signalfd or IO::KQueue:
- PublicInbox::DS::sig_setmask($oldset);
- PublicInbox::DS->SetLoopTimeout(1000);
- }
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop($sig, $oldset);
}
sub run ($$$;$) {
my ($default, $refresh, $post_accept, $tlsd) = @_;
- local $SIG{PIPE} = 'IGNORE';
daemon_prepare($default);
my $af_default = $default =~ /:8080\z/ ? 'httpready' : undef;
my $for_destroy = daemonize();
diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index c134de55d16ce68bab3f01f65241a963fa416c87..72cae005da5ad85c950106bc0ec70daf1dbcd482 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -150,7 +150,7 @@ }
};
}
-# called via PublicInbox::DS->EventLoop
+# called via PublicInbox::DS::event_loop
sub event_step {
my ($ctx, $sync) = @_;
# can't find a partial match in current inbox, try the others:
diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index 6b29789a2ed89d33d12e654d6a95f9bbe65cc8fa..c34225b29d9a5249f89f5f7fc036b4d2666caf4a 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -1305,19 +1305,11 @@ TSTP => sub { kill('STOP', $$) },
};
my $quit = PublicInbox::SearchIdx::quit_cb($sync);
$sig->{QUIT} = $sig->{INT} = $sig->{TERM} = $quit;
- my $sigfd = PublicInbox::Sigfd->new($sig,
- $PublicInbox::Syscall::SFD_NONBLOCK);
- @SIG{keys %$sig} = values(%$sig) if !$sigfd;
local $self->{-watch_sync} = $sync; # for ->on_inbox_unlock
- if (!$sigfd) {
- # wake up every second to accept signals if we don't
- # have signalfd or IO::KQueue:
- PublicInbox::DS::sig_setmask($oldset);
- PublicInbox::DS->SetLoopTimeout(1000);
- }
PublicInbox::DS->SetPostLoopCallback(sub { !$sync->{quit} });
$pr->("initial scan complete, entering event loop\n") if $pr;
- PublicInbox::DS->EventLoop; # calls InboxIdle->event_step
+ # calls InboxIdle->event_step:
+ PublicInbox::DS::event_loop($sig, $oldset);
done($self);
}
diff --git a/lib/PublicInbox/Gcf2Client.pm b/lib/PublicInbox/Gcf2Client.pm
index 397774f90bf212f9c74351b8d80e0807636bff7a..c5695db140cd6cd6728e964c0ba2abaae5bb59ab 100644
--- a/lib/PublicInbox/Gcf2Client.pm
+++ b/lib/PublicInbox/Gcf2Client.pm
@@ -57,7 +57,7 @@
# ensure PublicInbox::Git::cat_async_step never calls cat_async_retry
sub alternates_changed {}
-# DS->EventLoop will call this
+# DS::event_loop will call this
sub event_step {
my ($self) = @_;
$self->flush_write;
@@ -74,7 +74,7 @@ }
sub DESTROY {
my ($self) = @_;
- delete $self->{sock}; # if outside EventLoop
+ delete $self->{sock}; # if outside event_loop
PublicInbox::Git::DESTROY($self);
}
diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm
index 205b5b92cf71d4b1755a93dc7635a12767c9ab95..6c189b6410aa3798a736a6071a96826815b651be 100644
--- a/lib/PublicInbox/IPC.pm
+++ b/lib/PublicInbox/IPC.pm
@@ -251,7 +251,7 @@ my ($self, $bcast2) = @_;
my $wqw = PublicInbox::WQWorker->new($self, $self->{-wq_s2});
PublicInbox::WQWorker->new($self, $bcast2) if $bcast2;
PublicInbox::DS->SetPostLoopCallback(sub { $wqw->{sock} });
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
PublicInbox::DS->Reset;
}
@@ -353,7 +353,6 @@ eval { PublicInbox::DS->Reset };
delete @$self{qw(-wq_s1 -wq_ppid)};
$self->{-wq_worker_nr} =
keys %{delete($self->{-wq_workers}) // {}};
- $SIG{$_} = 'IGNORE' for (qw(PIPE));
$SIG{$_} = 'DEFAULT' for (qw(TTOU TTIN TERM QUIT INT CHLD));
local $0 = $one ? $self->{-wq_ident} :
"$self->{-wq_ident} $self->{-wq_worker_nr}";
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index df0bfab6dfb75064f8917fece47aed7650eb189d..fd59235846ae889b5ffab63bb5e0da7a8816b23a 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -18,8 +18,7 @@ use POSIX qw(strftime);
use IO::Handle ();
use Fcntl qw(SEEK_SET);
use PublicInbox::Config;
-use PublicInbox::Syscall qw(SFD_NONBLOCK EPOLLIN EPOLLET);
-use PublicInbox::Sigfd;
+use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
use PublicInbox::DS qw(now dwaitpid);
use PublicInbox::Spawn qw(spawn popen_rd);
use PublicInbox::Lock;
@@ -1291,23 +1290,11 @@ HUP => \&noop,
USR1 => \&noop,
USR2 => \&noop,
};
- my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
- local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
- undef $sig;
- local $SIG{PIPE} = 'IGNORE';
require PublicInbox::DirIdle;
local $dir_idle = PublicInbox::DirIdle->new([$sock_dir], sub {
# just rely on wakeup to hit PostLoopCallback set below
dir_idle_handler($_[0]) if $_[0]->fullname ne $path;
}, 1);
- if ($sigfd) {
- undef $sigfd; # unref, already in DS::DescriptorMap
- } else {
- # wake up every second to accept signals if we don't
- # have signalfd or IO::KQueue:
- PublicInbox::DS::sig_setmask($oldset);
- PublicInbox::DS->SetLoopTimeout(1000);
- }
PublicInbox::DS->SetPostLoopCallback(sub {
my ($dmap, undef) = @_;
if (@st = defined($path) ? stat($path) : ()) {
@@ -1344,7 +1331,7 @@ };
open STDERR, '>&STDIN' or die "redirect stderr failed: $!";
open STDOUT, '>&STDIN' or die "redirect stdout failed: $!";
# $daemon pipe to `lei' closed, main loop begins:
- eval { PublicInbox::DS->EventLoop };
+ eval { PublicInbox::DS::event_loop($sig, $oldset) };
warn "event loop error: $@\n" if $@;
# exit() may trigger waitpid via various DESTROY, ensure interruptible
PublicInbox::DS::sig_setmask($oldset);
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index 7e50a59ae49e1e65a67b16bf34109288a17694c8..b1285eda4a83a8df5d140b166ffc279ad3da5286 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -12,7 +12,7 @@ # may be configured which give inboxes different channels to
# operate in. This can be useful to ensure smaller inboxes can
# be cloned while cloning of large inboxes is maxed out.
#
-# This does not depend on the PublicInbox::DS->EventLoop or any
+# This does not depend on the PublicInbox::DS::event_loop or any
# other external scheduling mechanism, you just need to call
# start() and finish() appropriately. However, public-inbox-httpd
# (which uses PublicInbox::DS) will be able to schedule this
diff --git a/lib/PublicInbox/Sigfd.pm b/lib/PublicInbox/Sigfd.pm
index d91ea0e7ac78ae541edabc7b647c78224a48e3cc..81e5a1b1dd88e99d25bf37aadbb1f520e8a6503f 100644
--- a/lib/PublicInbox/Sigfd.pm
+++ b/lib/PublicInbox/Sigfd.pm
@@ -6,13 +6,13 @@ # fields: (sig: hashref similar to %SIG, but signal numbers as keys)
package PublicInbox::Sigfd;
use strict;
use parent qw(PublicInbox::DS);
-use PublicInbox::Syscall qw(signalfd EPOLLIN EPOLLET SFD_NONBLOCK);
+use PublicInbox::Syscall qw(signalfd EPOLLIN EPOLLET);
use POSIX ();
# returns a coderef to unblock signals if neither signalfd or kqueue
# are available.
sub new {
- my ($class, $sig, $flags) = @_;
+ my ($class, $sig, $nonblock) = @_;
my %signo = map {;
my $cb = $sig->{$_};
# SIGWINCH is 28 on FreeBSD, NetBSD, OpenBSD
@@ -24,15 +24,15 @@ $num => $cb;
} keys %$sig;
my $self = bless { sig => \%signo }, $class;
my $io;
- my $fd = signalfd(-1, [keys %signo], $flags);
+ my $fd = signalfd([keys %signo], $nonblock);
if (defined $fd && $fd >= 0) {
open($io, '+<&=', $fd) or die "open: $!";
} elsif (eval { require PublicInbox::DSKQXS }) {
- $io = PublicInbox::DSKQXS->signalfd([keys %signo], $flags);
+ $io = PublicInbox::DSKQXS->signalfd([keys %signo], $nonblock);
} else {
return; # wake up every second to check for signals
}
- if ($flags & SFD_NONBLOCK) { # it can go into the event loop
+ if ($nonblock) { # it can go into the event loop
$self->SUPER::new($io, EPOLLIN | EPOLLET);
} else { # master main loop
$self->{sock} = $io;
diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm
index a8a6f42a2e2dcc447bf1e16a36e9f35efb4de1fb..7ab4291119ea4deb84a7fe31ec6ed9e144a84d3d 100644
--- a/lib/PublicInbox/Syscall.pm
+++ b/lib/PublicInbox/Syscall.pm
@@ -22,7 +22,7 @@ our @EXPORT_OK = qw(epoll_ctl epoll_create epoll_wait
EPOLLIN EPOLLOUT EPOLLET
EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
EPOLLONESHOT EPOLLEXCLUSIVE
- signalfd SFD_NONBLOCK);
+ signalfd);
our %EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait
EPOLLIN EPOLLOUT
EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
@@ -67,7 +67,6 @@ $SYS_signalfd4,
);
my $SFD_CLOEXEC = 02000000; # Perl does not expose O_CLOEXEC
-sub SFD_NONBLOCK () { O_NONBLOCK }
our $no_deprecated = 0;
if ($^O eq "linux") {
@@ -266,14 +265,15 @@ 16 * $_ + 8, 4));
}
}
-sub signalfd ($$$) {
- my ($fd, $signos, $flags) = @_;
+sub signalfd ($$) {
+ my ($signos, $nonblock) = @_;
if ($SYS_signalfd4) {
my $set = POSIX::SigSet->new(@$signos);
- syscall($SYS_signalfd4, $fd, "$$set",
+ syscall($SYS_signalfd4, -1, "$$set",
# $Config{sig_count} is NSIG, so this is NSIG/8:
int($Config{sig_count}/8),
- $flags|$SFD_CLOEXEC);
+ # SFD_NONBLOCK == O_NONBLOCK for every architecture
+ ($nonblock ? O_NONBLOCK : 0) |$SFD_CLOEXEC);
} else {
$! = ENOSYS;
undef;
diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm
index 0523ad03f8710257e60957d6ddddb23b7943689f..c6bebce32edb3ea3a919065d4cf0a8f72dbc2341 100644
--- a/lib/PublicInbox/Watch.pm
+++ b/lib/PublicInbox/Watch.pm
@@ -12,7 +12,6 @@ use PublicInbox::MdirReader;
use PublicInbox::NetReader;
use PublicInbox::Filter::Base qw(REJECT);
use PublicInbox::Spamcheck;
-use PublicInbox::Sigfd;
use PublicInbox::DS qw(now add_timer);
use PublicInbox::MID qw(mids);
use PublicInbox::ContentHash qw(content_hash);
@@ -570,7 +569,7 @@ add_timer(0, \&poll_fetch_fork, $self, $intvl, $uris);
}
watch_fs_init($self) if $self->{mdre};
PublicInbox::DS->SetPostLoopCallback(sub { !$self->quit_done });
- PublicInbox::DS->EventLoop; # calls ->event_step
+ PublicInbox::DS::event_loop($sig, $oldset); # calls ->event_step
_done_for_now($self);
}
diff --git a/script/public-inbox-watch b/script/public-inbox-watch
index 86349d71d415ba12314411f25e87b0c227018022..af02d8f358f7b84392744b68df49a4328fc69636 100755
--- a/script/public-inbox-watch
+++ b/script/public-inbox-watch
@@ -13,8 +13,6 @@ use IO::Handle; # ->autoflush
use PublicInbox::Watch;
use PublicInbox::Config;
use PublicInbox::DS;
-use PublicInbox::Sigfd;
-use PublicInbox::Syscall qw(SFD_NONBLOCK);
my $do_scan = 1;
GetOptions('scan!' => \$do_scan, # undocumented, testing only
'help|h' => \(my $show_help)) or do { print STDERR $help; exit 1 };
@@ -56,12 +54,5 @@ $sig->{QUIT} = $sig->{TERM} = $sig->{INT} = $quit;
# --no-scan is only intended for testing atm, undocumented.
PublicInbox::DS::requeue($scan) if $do_scan;
-
- my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
- local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
- if (!$sigfd) {
- PublicInbox::DS::sig_setmask($oldset);
- PublicInbox::DS->SetLoopTimeout(1000);
- }
$watch->watch($sig, $oldset) while ($watch);
}
diff --git a/t/dir_idle.t b/t/dir_idle.t
index 0bb3b7585328dc2308c315019b80320c53e4508c..8e7f3b70eec492c60db932cb807a1ce0a25c6b2b 100644
--- a/t/dir_idle.t
+++ b/t/dir_idle.t
@@ -15,7 +15,7 @@ my $end = 3 + now;
PublicInbox::DS->SetPostLoopCallback(sub { scalar(@x) == 0 && now < $end });
tick(0.011);
rmdir("$tmpdir/a/b") or xbail "rmdir $!";
-PublicInbox::DS->EventLoop;
+PublicInbox::DS::event_loop();
is(scalar(@x), 1, 'got an event') and
is($x[0]->[0]->fullname, "$tmpdir/a/b", 'got expected fullname') and
ok($x[0]->[0]->IN_DELETE, 'IN_DELETE set');
@@ -24,7 +24,7 @@ tick(0.011);
rmdir("$tmpdir/a") or xbail "rmdir $!";
@x = ();
$end = 3 + now;
-PublicInbox::DS->EventLoop;
+PublicInbox::DS::event_loop();
is(scalar(@x), 1, 'got an event') and
is($x[0]->[0]->fullname, "$tmpdir/a", 'got expected fullname') and
ok($x[0]->[0]->IN_DELETE_SELF, 'IN_DELETE_SELF set');
@@ -33,7 +33,7 @@ tick(0.011);
rename("$tmpdir/c", "$tmpdir/j") or xbail "rmdir $!";
@x = ();
$end = 3 + now;
-PublicInbox::DS->EventLoop;
+PublicInbox::DS::event_loop();
is(scalar(@x), 1, 'got an event') and
is($x[0]->[0]->fullname, "$tmpdir/c", 'got expected fullname') and
ok($x[0]->[0]->IN_DELETE_SELF || $x[0]->[0]->IN_MOVE_SELF,
diff --git a/t/ds-leak.t b/t/ds-leak.t
index 4c211639ed164b51d58ff147727804800cb2dee7..4e8d76cdf2eafdabbe4bce03e8ad7449a3ada3e2 100644
--- a/t/ds-leak.t
+++ b/t/ds-leak.t
@@ -19,7 +19,7 @@ my ($r, $w);
pipe($r, $w) or die "pipe: $!";
PublicInbox::DS::add_timer(0, sub { $pid = spawn([qw(sleep 10)]) });
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
ok($pid, 'subprocess spawned');
# wait for execve, we need to ensure lsof sees sleep(1)
@@ -56,7 +56,7 @@ my $cb = sub {};
for my $i (0..$n) {
PublicInbox::DS->SetLoopTimeout(0);
PublicInbox::DS->SetPostLoopCallback($cb);
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
PublicInbox::DS->Reset;
}
ok(1, "Reset works and doesn't hit RLIMIT_NOFILE ($n)");
diff --git a/t/imapd.t b/t/imapd.t
index bd8ad7e5162d90231f9c27bab1f7801a3c6f875a..80757a9d4071610ccb66ce924a2690de07055a33 100644
--- a/t/imapd.t
+++ b/t/imapd.t
@@ -466,7 +466,7 @@ open my $err, '<', $watcherr or BAIL_OUT $!;
my $w = start_script(['-watch'], undef, { 2 => $err_wr });
diag 'waiting for initial fetch...';
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
diag 'inbox unlocked on initial fetch, waiting for IDLE';
tick until (grep(/I: \S+ idling/, <$err>));
@@ -477,7 +477,7 @@ 'delivered a message for IDLE to kick -watch') or
diag "mda error \$?=$?";
diag 'waiting for IMAP IDLE wakeup';
PublicInbox::DS->SetPostLoopCallback(undef);
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
diag 'inbox unlocked on IDLE wakeup';
# try again with polling
@@ -494,7 +494,7 @@ 'delivered a message for -watch PollInterval');
diag 'waiting for PollInterval wakeup';
PublicInbox::DS->SetPostLoopCallback(undef);
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
diag 'inbox unlocked (poll)';
$w->kill;
$w->join;
diff --git a/t/nntpd.t b/t/nntpd.t
index 3c171a3b88b9fac5860ebfbac416eface8a8a0ee..cf1c44f80b23d83ed6f4521aebdf04e18aa5a036 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -439,7 +439,7 @@ open my $err, '<', $watcherr or BAIL_OUT $!;
my $w = start_script(['-watch'], undef, { 2 => $err_wr });
diag 'waiting for initial fetch...';
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
diag 'inbox unlocked on initial fetch';
$w->kill;
$w->join;
diff --git a/t/sigfd.t b/t/sigfd.t
index a1ab222c0c4daeaeb5ead02f8f2f35ad820782c9..a68b12a65f01d8f5b36f0592acb8cf1a128a38cc 100644
--- a/t/sigfd.t
+++ b/t/sigfd.t
@@ -4,7 +4,6 @@ use Test::More;
use IO::Handle;
use POSIX qw(:signal_h);
use Errno qw(ENOSYS);
-use PublicInbox::Syscall qw(SFD_NONBLOCK);
require_ok 'PublicInbox::Sigfd';
use PublicInbox::DS;
@@ -40,18 +39,18 @@ 'normal $SIG{$s} not fired');
}
$sigfd = undef;
- my $nbsig = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
+ my $nbsig = PublicInbox::Sigfd->new($sig, 1);
ok($nbsig, 'Sigfd->new SFD_NONBLOCK works');
is($nbsig->wait_once, undef, 'nonblocking ->wait_once');
ok($! == Errno::EAGAIN, 'got EAGAIN');
kill('HUP', $$) or die "kill $!";
PublicInbox::DS->SetPostLoopCallback(sub {}); # loop once
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
is($hit->{HUP}->{sigfd}, 2, 'HUP sigfd fired in event loop') or
diag explain($hit); # sometimes fails on FreeBSD 11.x
kill('TERM', $$) or die "kill $!";
kill('HUP', $$) or die "kill $!";
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
PublicInbox::DS->Reset;
is($hit->{TERM}->{sigfd}, 1, 'TERM sigfd fired in event loop');
is($hit->{HUP}->{sigfd}, 3, 'HUP sigfd fired in event loop');
diff --git a/t/watch_maildir.t b/t/watch_maildir.t
index e74b512f21929569c9b53b378334a94c6f7246e3..6399fb7cc15ff5793db8a3e9d83a2d091fa63902 100644
--- a/t/watch_maildir.t
+++ b/t/watch_maildir.t
@@ -199,7 +199,7 @@ }
$em->commit; # wake -watch up
diag 'waiting for -watch to import new message';
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
$wm->kill;
$wm->join;
$ii->close;
diff --git a/xt/mem-imapd-tls.t b/xt/mem-imapd-tls.t
index bd75ef452984248cfe0180d3579e68d8ba1f86d0..8992a6fc0d8dc96dfe835ad5d00bae179e0889be 100644
--- a/xt/mem-imapd-tls.t
+++ b/xt/mem-imapd-tls.t
@@ -95,7 +95,7 @@ IMAPC->new($io);
# one step through the event loop
# do a little work as we connect:
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
# try not to overflow the listen() backlog:
if (!($n % 128) && $DONE != $n) {
@@ -104,7 +104,7 @@ PublicInbox::DS->SetLoopTimeout(-1);
PublicInbox::DS->SetPostLoopCallback(sub { $DONE != $n });
# clear the backlog:
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
# resume looping
PublicInbox::DS->SetLoopTimeout(0);
@@ -117,7 +117,7 @@ diag "done?: @".time." $DONE/$nfd";
if ($DONE != $nfd) {
PublicInbox::DS->SetLoopTimeout(-1);
PublicInbox::DS->SetPostLoopCallback(sub { $DONE != $nfd });
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
}
is($nfd, $DONE, "$nfd/$DONE done");
if ($^O eq 'linux' && open(my $f, '<', "/proc/$pid/status")) {
diff --git a/xt/net_writer-imap.t b/xt/net_writer-imap.t
index 41438cf79b155032a8943a593faaa12d20fde48b..cb2ea61ff8e365d307360e4bbef854fa309e2a15 100644
--- a/xt/net_writer-imap.t
+++ b/xt/net_writer-imap.t
@@ -228,7 +228,7 @@ my $obj = bless \$cb, 'PublicInbox::TestCommon::InboxWakeup';
$pub_cfg->each_inbox(sub { $_[0]->subscribe_unlock('ident', $obj) });
my $w = start_script(['-watch'], undef, { 2 => $err_wr });
diag 'waiting for initial fetch...';
- PublicInbox::DS->EventLoop;
+ PublicInbox::DS::event_loop();
my $ibx = $pub_cfg->lookup_name('wtest');
my $mm = $ibx->mm;
ok(defined($mm->num_for('Seen@test.example.com')),