From 2f946a02bc324612febdfe31604b79e0196a215f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 4 Oct 2023 03:49:14 +0000 Subject: ds: hoist out close_non_busy It's shared by both by lei and public-facing daemons in using the ->busy callback. --- lib/PublicInbox/DS.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/PublicInbox/DS.pm') diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index c476311b..ecfb581d 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -233,6 +233,16 @@ sub enqueue_reap () { $reap_armed //= requeue(\&reap_pids) } sub in_loop () { $in_loop } +# use inside @post_loop_do, returns number of busy clients +sub close_non_busy () { + my $n = 0; + for my $s (values %DescriptorMap) { + # close as much as possible, early as possible + ($s->busy ? ++$n : $s->close) if $s->can('busy'); + } + $n; +} + # Internal function: run the post-event callback, send read events # for pushed-back data, and close pending connections. returns 1 # if event loop should continue, or 0 to shut it all down. -- cgit v1.2.3-24-ge0c7