* [PATCH 00/30] autodie-ification and code simplifications
@ 2023-10-17 23:37 7% Eric Wong
2023-10-17 23:38 7% ` [PATCH 15/30] ds: get rid of SetLoopTimeout Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-10-17 23:37 UTC (permalink / raw)
To: meta
Noisy code is less pleasant to work on, so use autodie more and
a few more simplifications. There's a couple of small bugfixes
discovered along the way, too.
Eric Wong (30):
lei_mirror: start converting to autodie
lei_mirror: autodie most `close' calls
lei_mirror: use autodie for most `open' calls
git: introduce read_all function
import: use read_all to detect short reads
lei_mirror: use read_all
use read_all in more places to improve safety
xap_helper*: use autodie in more places
xap_helper: die more easily in both implementations
xap_helper: simplify SIGTERM exit checks
xap_helper: autodie for getsockopt
xap_client: autodie for pipe and socketpair
xt/git-http-backend: remove Net::HTTP usage
ds: introduce and use do_fork helper
ds: get rid of SetLoopTimeout
cindex: drop some unused functions
syscall: common $F_SETPIPE_SZ definition
t/lei-up: additional diagnostics for match failures
test_common: use autodie and read_all where possible
test_common: only hide TCP port in messages
test_common: use $cwdfh for every run_script command
init: drop extraneous `+'
init: use autodie to reduce distractions
xt/mem-imapd-tls: remove unused/broken epoll imports
xt/mem-imapd-tls: reduce FDs for lsof use
lei: use autodie where appropriate
lei_auth: update comments and use v5.12
lei_config: drop redundant open check
convert: use read_all to simplify error checks
idx_stack: use autodie + read_all
lib/PublicInbox/CidxLogP.pm | 4 +-
lib/PublicInbox/CodeSearchIdx.pm | 5 --
lib/PublicInbox/DS.pm | 36 ++++----
lib/PublicInbox/Daemon.pm | 16 ++--
lib/PublicInbox/EOFpipe.pm | 6 +-
lib/PublicInbox/Gcf2.pm | 7 +-
lib/PublicInbox/Git.pm | 19 +++--
lib/PublicInbox/IPC.pm | 12 +--
lib/PublicInbox/IdxStack.pm | 20 ++---
lib/PublicInbox/Import.pm | 8 +-
lib/PublicInbox/InboxWritable.pm | 6 +-
lib/PublicInbox/LEI.pm | 48 +++++------
lib/PublicInbox/LeiALE.pm | 11 +--
lib/PublicInbox/LeiAuth.pm | 7 +-
lib/PublicInbox/LeiBlob.pm | 6 +-
lib/PublicInbox/LeiConfig.pm | 4 +-
lib/PublicInbox/LeiMailSync.pm | 5 +-
lib/PublicInbox/LeiMirror.pm | 131 ++++++++++++++----------------
lib/PublicInbox/LeiSucks.pm | 5 +-
lib/PublicInbox/LeiXSearch.pm | 2 +-
lib/PublicInbox/MultiGit.pm | 3 +-
lib/PublicInbox/SearchIdxShard.pm | 14 ++--
lib/PublicInbox/Syscall.pm | 16 ++--
lib/PublicInbox/TestCommon.pm | 85 +++++++++----------
lib/PublicInbox/ViewVCS.pm | 12 ++-
lib/PublicInbox/WWW.pm | 4 +-
lib/PublicInbox/Watch.pm | 11 +--
lib/PublicInbox/XapClient.pm | 11 +--
lib/PublicInbox/XapHelper.pm | 24 ++----
lib/PublicInbox/XapHelperCxx.pm | 11 +--
lib/PublicInbox/Xapcmd.pm | 5 +-
lib/PublicInbox/xap_helper.h | 60 ++++++--------
script/public-inbox-convert | 8 +-
script/public-inbox-edit | 4 +-
script/public-inbox-init | 30 +++----
t/dir_idle.t | 2 +-
t/ds-leak.t | 4 +-
t/gcf2.t | 5 +-
t/init.t | 7 ++
t/lei-sigpipe.t | 7 +-
t/lei-up.t | 4 +-
xt/git-http-backend.t | 30 +++----
xt/mem-imapd-tls.t | 21 ++---
xt/mem-nntpd-tls.t | 8 +-
44 files changed, 335 insertions(+), 409 deletions(-)
^ permalink raw reply [relevance 7%]
* [PATCH 15/30] ds: get rid of SetLoopTimeout
2023-10-17 23:37 7% [PATCH 00/30] autodie-ification and code simplifications Eric Wong
@ 2023-10-17 23:38 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-10-17 23:38 UTC (permalink / raw)
To: meta
It's not worth the code and memory to have a setter method we
never use outside of tests.
---
lib/PublicInbox/DS.pm | 24 +++++++-----------------
t/dir_idle.t | 2 +-
t/ds-leak.t | 4 ++--
xt/mem-imapd-tls.t | 8 ++++----
xt/mem-nntpd-tls.t | 8 ++++----
5 files changed, 18 insertions(+), 28 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 9960937d..6041c6b5 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -47,7 +47,7 @@ our (%AWAIT_PIDS, # pid => [ $callback, @args ]
@post_loop_do, # subref + args to call at the end of each loop
- $LoopTimeout, # timeout of event loop in milliseconds
+ $loop_timeout, # timeout of event loop in milliseconds
@Timers, # timers
%UniqTimer,
$in_loop,
@@ -89,20 +89,10 @@ sub Reset {
scalar(@{$cur_runq // []})); # do not vivify cur_runq
$reap_armed = undef;
- $LoopTimeout = -1; # no timeout by default
+ $loop_timeout = -1; # no timeout by default
$Poller = PublicInbox::Select->new;
}
-=head2 C<< CLASS->SetLoopTimeout( $timeout ) >>
-
-Set the loop timeout for the event loop to some value in milliseconds.
-
-A timeout of 0 (zero) means poll forever. A timeout of -1 means poll and return
-immediately.
-
-=cut
-sub SetLoopTimeout { $LoopTimeout = $_[1] + 0 }
-
sub _add_named_timer {
my ($name, $secs, $coderef, @args) = @_;
my $fire_time = now() + $secs;
@@ -163,7 +153,7 @@ sub next_tick () {
sub RunTimers {
next_tick();
- return (($nextq || $ToClose) ? 0 : $LoopTimeout) unless @Timers;
+ return (($nextq || $ToClose) ? 0 : $loop_timeout) unless @Timers;
my $now = now();
@@ -177,16 +167,16 @@ sub RunTimers {
# timers may enqueue into nextq:
return 0 if ($nextq || $ToClose);
- return $LoopTimeout unless @Timers;
+ return $loop_timeout unless @Timers;
# convert time to an even number of milliseconds, adding 1
# extra, otherwise floating point fun can occur and we'll
# call RunTimers like 20-30 times, each returning a timeout
# of 0.0000212 seconds
- my $timeout = int(($Timers[0][0] - $now) * 1000) + 1;
+ my $t = int(($Timers[0][0] - $now) * 1000) + 1;
# -1 is an infinite timeout, so prefer a real timeout
- ($LoopTimeout < 0 || $LoopTimeout >= $timeout) ? $timeout : $LoopTimeout
+ ($loop_timeout < 0 || $loop_timeout >= $t) ? $t : $loop_timeout
}
sub sig_setmask { sigprocmask(SIG_SETMASK, @_) or die "sigprocmask: $!" }
@@ -305,7 +295,7 @@ sub event_loop (;$$) {
sig_setmask($oldset) if $oldset;
sigprocmask(SIG_UNBLOCK, unblockset($sig)) or
die "SIG_UNBLOCK: $!";
- PublicInbox::DS->SetLoopTimeout(1000);
+ $loop_timeout = 1000;
}
$_[0] = $sigfd = $sig = undef; # $_[0] == sig
local $in_loop = 1;
diff --git a/t/dir_idle.t b/t/dir_idle.t
index 02759b54..35c800f9 100644
--- a/t/dir_idle.t
+++ b/t/dir_idle.t
@@ -11,7 +11,7 @@ my @x;
my $cb = sub { push @x, \@_ };
my $di = PublicInbox::DirIdle->new($cb);
$di->add_watches(["$tmpdir/a", "$tmpdir/c"], 1);
-PublicInbox::DS->SetLoopTimeout(1000);
+$PublicInbox::DS::loop_timeout = 1000;
my $end = 3 + now;
local @PublicInbox::DS::post_loop_do = (sub { scalar(@x) == 0 && now < $end });
rmdir("$tmpdir/a/b") or xbail "rmdir $!";
diff --git a/t/ds-leak.t b/t/ds-leak.t
index eaca05b8..179997eb 100644
--- a/t/ds-leak.t
+++ b/t/ds-leak.t
@@ -11,7 +11,7 @@ if ('close-on-exec for epoll and kqueue') {
my $pid;
my $evfd_re = qr/(?:kqueue|eventpoll)/i;
- PublicInbox::DS->SetLoopTimeout(0);
+ $PublicInbox::DS::loop_timeout = 0;
local @PublicInbox::DS::post_loop_do = (sub { 0 });
# make sure execve closes if we're using fork()
@@ -54,7 +54,7 @@ SKIP: {
}
my $cb = sub {};
for my $i (0..$n) {
- PublicInbox::DS->SetLoopTimeout(0);
+ $PublicInbox::DS::loop_timeout = 0;
local @PublicInbox::DS::post_loop_do = ($cb);
PublicInbox::DS::event_loop();
PublicInbox::DS->Reset;
diff --git a/xt/mem-imapd-tls.t b/xt/mem-imapd-tls.t
index 00199a9b..58581017 100644
--- a/xt/mem-imapd-tls.t
+++ b/xt/mem-imapd-tls.t
@@ -81,7 +81,7 @@ sub once { 0 }; # stops event loop
# setup the event loop so that it exits at every step
# while we're still doing connect(2)
-PublicInbox::DS->SetLoopTimeout(0);
+$PublicInbox::DS::loop_timeout = 0;
local @PublicInbox::DS::post_loop_do = (\&once);
my $pid = $td->{pid};
if ($^O eq 'linux' && open(my $f, '<', "/proc/$pid/status")) {
@@ -100,21 +100,21 @@ foreach my $n (1..$nfd) {
# try not to overflow the listen() backlog:
if (!($n % 128) && $DONE != $n) {
diag("nr: ($n) $DONE/$nfd");
- PublicInbox::DS->SetLoopTimeout(-1);
+ $PublicInbox::DS::loop_timeout = -1;
local @PublicInbox::DS::post_loop_do = (sub { $DONE != $n });
# clear the backlog:
PublicInbox::DS::event_loop();
# resume looping
- PublicInbox::DS->SetLoopTimeout(0);
+ $PublicInbox::DS::loop_timeout = 0;
}
}
# run the event loop normally, now:
diag "done?: @".time." $DONE/$nfd";
if ($DONE != $nfd) {
- PublicInbox::DS->SetLoopTimeout(-1);
+ $PublicInbox::DS::loop_timeout = -1;
local @PublicInbox::DS::post_loop_do = (sub { $DONE != $nfd });
PublicInbox::DS::event_loop();
}
diff --git a/xt/mem-nntpd-tls.t b/xt/mem-nntpd-tls.t
index f9b98a6b..ec639a8b 100644
--- a/xt/mem-nntpd-tls.t
+++ b/xt/mem-nntpd-tls.t
@@ -104,7 +104,7 @@ sub once { 0 }; # stops event loop
# setup the event loop so that it exits at every step
# while we're still doing connect(2)
-PublicInbox::DS->SetLoopTimeout(0);
+$PublicInbox::DS::loop_timeout = 0;
local @PublicInbox::DS::post_loop_do = (\&once);
foreach my $n (1..$nfd) {
@@ -119,14 +119,14 @@ foreach my $n (1..$nfd) {
# try not to overflow the listen() backlog:
if (!($n % 128) && $n != $DONE) {
diag("nr: ($n) $DONE/$nfd");
- PublicInbox::DS->SetLoopTimeout(-1);
+ $PublicInbox::DS::loop_timeout = -1;
@PublicInbox::DS::post_loop_do = (sub { $DONE != $n });
# clear the backlog:
PublicInbox::DS::event_loop();
# resume looping
- PublicInbox::DS->SetLoopTimeout(0);
+ $PublicInbox::DS::loop_timeout = 0;
@PublicInbox::DS::post_loop_do = (\&once);
}
}
@@ -140,7 +140,7 @@ $dump_rss->();
# run the event loop normally, now:
if ($DONE != $nfd) {
- PublicInbox::DS->SetLoopTimeout(-1);
+ $PublicInbox::DS::loop_timeout = -1;
@PublicInbox::DS::post_loop_do = (sub {
diag "done: ".time." $DONE";
$DONE != $nfd;
^ permalink raw reply related [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-10-17 23:37 7% [PATCH 00/30] autodie-ification and code simplifications Eric Wong
2023-10-17 23:38 7% ` [PATCH 15/30] ds: get rid of SetLoopTimeout 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).