use fields qw(nntpd article rbuf ng long_res);
use PublicInbox::Search;
use PublicInbox::Msgmap;
+use PublicInbox::MID qw(mid_escape);
use PublicInbox::Git;
require PublicInbox::EvCleanup;
use Email::Simple;
use POSIX qw(strftime);
use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
-use URI::Escape qw(uri_escape_utf8);
+use Digest::SHA qw(sha1_hex);
+use Time::Local qw(timegm timelocal);
use constant {
r501 => '501 command syntax error',
r221 => '221 Header follows',
my $EXPMAP; # fd -> [ idle_time, $self ]
my $expt;
our $EXPTIME = 180; # 3 minutes
-my $WEAKEN = {}; # string(nntpd) -> nntpd
-my $weakt;
my $nextt;
my $nextq = [];
sub update_idle_time ($) {
my ($self) = @_;
- my $tmp = $self->{sock} or return;
- $tmp = fileno($tmp);
- defined $tmp and $EXPMAP->{$tmp} = [ now(), $self ];
-}
-
-# reduce FD pressure by closing some "git cat-file --batch" processes
-# and unused FDs for msgmap and Xapian indices
-sub weaken_groups () {
- $weakt = undef;
- foreach my $nntpd (values %$WEAKEN) {
- $_->weaken_all foreach (@{$nntpd->{grouplist}});
- }
- $WEAKEN = {};
+ my $fd = $self->{fd};
+ defined $fd and $EXPMAP->{$fd} = [ now(), $self ];
}
sub expire_old () {
$EXPMAP = \%new;
if ($nr) {
$expt = PublicInbox::EvCleanup::later(*expire_old);
- weaken_groups();
} else {
$expt = undef;
# noop to kick outselves out of the loop ASAP so descriptors
# really get closed
PublicInbox::EvCleanup::asap(sub {});
-
- # grace period for reaping resources
- $weakt ||= PublicInbox::EvCleanup::later(*weaken_groups);
}
}
$self->{rbuf} = '';
$self->watch_read(1);
update_idle_time($self);
- $WEAKEN->{"$nntpd"} = $nntpd;
$expt ||= PublicInbox::EvCleanup::later(*expire_old);
$self;
}
my $res = eval { $req->($self, @args) };
my $err = $@;
if ($err && !$self->{closed}) {
+ local $/ = "\n";
chomp($l);
err($self, 'error from: %s (%s)', $l, $err);
$res = '503 program fault - command not performed';
sub parse_time ($$;$) {
my ($date, $time, $gmt) = @_;
- use Time::Local qw();
my ($hh, $mm, $ss) = unpack('A2A2A2', $time);
if (defined $gmt) {
$gmt =~ /\A(?:UTC|GMT)\z/i or die "GM invalid: $gmt";
($YYYY, $MM, $DD) = unpack('A4A2A2', $date);
} else { # legacy clients send YYMMDD
($YYYY, $MM, $DD) = unpack('A2A2A2', $date);
- if ($YYYY > strftime('%y', @now)) {
- my $cur_year = $now[5] + 1900;
+ my $cur_year = $now[5] + 1900;
+ if ($YYYY > $cur_year) {
$YYYY += int($cur_year / 1000) * 1000 - 100;
}
}
if ($gmt) {
- Time::Local::timegm($ss, $mm, $hh, $DD, $MM - 1, $YYYY);
+ timegm($ss, $mm, $hh, $DD, $MM - 1, $YYYY);
} else {
- Time::Local::timelocal($ss, $mm, $hh, $DD, $MM - 1, $YYYY);
+ timelocal($ss, $mm, $hh, $DD, $MM - 1, $YYYY);
}
}
return $_[0] = qr/.*/ if (!defined $_[0] || $_[0] eq '*');
my %keep;
my $salt = rand;
- use Digest::SHA qw(sha1_hex);
my $tmp = $_[0];
$tmp =~ s#(?<!\\)\[(.+)(?<!\\)\]#
$hdr->header_set('Xref', xref($ng, $n));
header_append($hdr, 'List-Post', "<mailto:$ng->{-primary_address}>");
if (my $url = $ng->base_url) {
- $mid = uri_escape_utf8($mid);
+ $mid = mid_escape($mid);
header_append($hdr, 'Archived-At', "<$url$mid/>");
header_append($hdr, 'List-Archive', "<$url>");
}
sub do_write ($$) {
my ($self, $data) = @_;
my $done = $self->write($data);
- die if $self->{closed};
+ return if $self->{closed};
# Do not watch for readability if we have data in the queue,
# instead re-enable watching for readability when we can
$rv;
}
+sub not_idle_long ($$) {
+ my ($self, $now) = @_;
+ defined(my $fd = $self->{fd}) or return;
+ my $ary = $EXPMAP->{$fd} or return;
+ my $exp_at = $ary->[0] + $EXPTIME;
+ $exp_at > $now;
+}
+
# for graceful shutdown in PublicInbox::Daemon:
-sub busy () {
- my ($self) = @_;
- ($self->{rbuf} ne '' || $self->{long_res} || $self->{write_buf_size});
+sub busy {
+ my ($self, $now) = @_;
+ ($self->{rbuf} ne '' || $self->{long_res} || $self->{write_buf_size} ||
+ not_idle_long($self, $now));
}
1;