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.
# drop idle connections and try to quit gracefully
@PublicInbox::DS::post_loop_do = (sub {
my ($dmap, undef) = @_;
- my $n = 0;
my $now = now();
- for my $s (values %$dmap) {
- $s->can('busy') or next;
- if ($s->busy) {
- ++$n;
- } else { # close as much as possible, early as possible
- $s->close;
- }
- }
+ my $n = PublicInbox::DS::close_non_busy();
if ($n) {
if (($warn + 5) < now()) {
warn "$$ quitting, $n client(s) left\n";
$quit->();
}
return 1 if defined($path);
- my $n = 0;
- for my $s (values %$dmap) {
- $s->can('busy') or next;
- if ($s->busy) {
- ++$n;
- } else {
- $s->close;
- }
- }
- drop_all_stores() if !$n; # drop stores only if no clients
+ my $n = PublicInbox::DS::close_non_busy() or
+ drop_all_stores(); # drop stores only if no clients
# returns true: continue, false: stop
$n + scalar(keys(%$PublicInbox::DS::AWAIT_PIDS));
});