X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FNNTP.pm;h=e41e3f64d71e1cab5e8322e3c0bbc1c8ac514b5b;hb=c4e57273ce3a7d305ceb21225dae32ece935740f;hp=c04968529854067ef4152f62f38588bd82314b1a;hpb=16d96f80e55d3f40338101ee8641e03f3b4f2d64;p=public-inbox.git diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index c0496852..e41e3f64 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -7,11 +7,7 @@ use strict; use warnings; use base qw(PublicInbox::DS); use fields qw(nntpd article ng); -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 PublicInbox::DS qw(now); @@ -44,35 +40,6 @@ HDR\r OVER\r my $have_deflate; -my $EXPMAP; # fd -> [ idle_time, $self ] -my $expt; -our $EXPTIME = 180; # 3 minutes - -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 %new; - while (my ($fd, $v) = each %$EXPMAP) { - my ($idle_time, $nntp) = @$v; - if ($idle_time < $old) { - if (!$nntp->shutdn) { - $new{$fd} = $v; - } - } else { - $new{$fd} = $v; - } - } - $EXPMAP = \%new; - $expt = scalar(keys %new) ? PublicInbox::EvCleanup::later(*expire_old) - : undef; -} sub greet ($) { $_[0]->write($_[0]->{nntpd}->{greet}) }; @@ -93,8 +60,7 @@ sub new ($$$) { } else { greet($self); } - update_idle_time($self); - $expt ||= PublicInbox::EvCleanup::later(*expire_old); + $self->update_idle_time; $self; } @@ -112,10 +78,7 @@ sub process_line ($$) { my ($self, $l) = @_; my ($req, @args) = split(/[ \t]/, $l); return 1 unless defined($req); # skip blank line - $req = eval { - no strict 'refs'; - *{'cmd_'.lc($req)}{CODE}; - }; + $req = $self->can('cmd_'.lc($req)); return res($self, '500 command not recognized') unless $req; return res($self, r501) unless args_ok($req, scalar @args); @@ -204,11 +167,7 @@ sub cmd_list ($;$$) { my $arg = shift @args; $arg =~ tr/A-Z./a-z_/; $arg = "list_$arg"; - - $arg = eval { - no strict 'refs'; - *{$arg}{CODE}; - }; + $arg = $self->can($arg); return r501 unless $arg && args_ok($arg, scalar @args); more($self, '215 information follows'); $arg->($self, @args); @@ -651,7 +610,7 @@ sub long_response ($$) { out($self, " deferred[$fd] aborted - %0.6f", $diff); $self->close; } elsif ($more) { # $self->{wbuf}: - update_idle_time($self); + $self->update_idle_time; # COMPRESS users all share the same DEFLATE context. # Flush it here to ensure clients don't see @@ -984,7 +943,7 @@ sub event_step { return unless $self->flush_write && $self->{sock}; - update_idle_time($self); + $self->update_idle_time; # only read more requests if we've drained the write buffer, # otherwise we can be buffering infinitely w/o backpressure @@ -1009,25 +968,17 @@ sub event_step { my $len = bytes::length($$rbuf); return $self->close if ($len >= LINE_MAX); $self->rbuf_idle($rbuf); - update_idle_time($self); + $self->update_idle_time; # maybe there's more pipelined data, or we'll have # to register it for socket-readiness notifications $self->requeue unless $self->{wbuf}; } -sub not_idle_long ($$) { - my ($self, $now) = @_; - my $sock = $self->{sock} or return; - my $ary = $EXPMAP->{fileno($sock)} or return; - my $exp_at = $ary->[0] + $EXPTIME; - $exp_at > $now; -} - # for graceful shutdown in PublicInbox::Daemon: sub busy { my ($self, $now) = @_; - ($self->{rbuf} || $self->{wbuf} || not_idle_long($self, $now)); + ($self->{rbuf} || $self->{wbuf} || $self->not_idle_long($now)); } # this is an import to prevent "perl -c" from complaining about fields