-# disable commands with easy DoS potential:
-my %DISABLED; # = map { $_ => 1 } qw(xover list_overview_fmt newnews xhdr);
-
-my $EXPMAP; # fd -> [ idle_time, $self ]
-my $expt;
-our $EXPTIME = 180; # 3 minutes
-my $nextt;
-
-my $nextq = [];
-sub next_tick () {
- $nextt = undef;
- my $q = $nextq;
- $nextq = [];
- event_step($_) for @$q;
-}
-
-sub requeue ($) {
- push @$nextq, $_[0];
- $nextt ||= PublicInbox::EvCleanup::asap(*next_tick);
-}
-
-sub update_idle_time ($) {
- my ($self) = @_;
- my $sock = $self->{sock} or return;
- $EXPMAP->{fileno($sock)} = [ now(), $self ];
-}
-
-sub expire_old () {
- my $now = now();
- my $exp = $EXPTIME;
- my $old = $now - $exp;
- my $nr = 0;
- my $closed = 0;
- my %new;
- while (my ($fd, $v) = each %$EXPMAP) {
- my ($idle_time, $nntp) = @$v;
- if ($idle_time < $old) {
- if ($nntp->shutdn) {
- $closed++;
- } else {
- ++$nr;
- $new{$fd} = $v;
- }
- } else {
- ++$nr;
- $new{$fd} = $v;
- }
- }
- $EXPMAP = \%new;
- if ($nr) {
- $expt = PublicInbox::EvCleanup::later(*expire_old);
- } else {
- $expt = undef;
- # noop to kick outselves out of the loop ASAP so descriptors
- # really get closed
- PublicInbox::EvCleanup::asap(sub {}) if $closed;
- }
-}