AxKit2
view release on metacpan or search on metacpan
lib/AxKit2/Console.pm view on Meta::CPAN
my $descriptors = Danga::Socket->DescriptorMap;
my $current_connections = 0;
my $current_dns = 0;
foreach my $fd (keys %$descriptors) {
my $pob = $descriptors->{$fd};
if ($pob->isa("AxKit2::Connection")) {
$current_connections++;
}
}
$output .= "Current Connections: $current_connections\n";
$self->write($output);
}
sub cmd_shutdown {
my $self = shift;
Danga::Socket->SetPostLoopCallback(sub { 0 });
$self->close("shutdown");
}
# Cleanup routine to get rid of timed out sockets
sub _do_cleanup {
my $now = time;
# AxKit2::Client->log(LOGDEBUG, "do cleanup");
Danga::Socket->AddTimer(CLEANUP_TIME, \&_do_cleanup);
my $sf = __PACKAGE__->get_sock_ref;
my $conns = 0;
my %max_age; # classname -> max age (0 means forever)
my %max_connect; # classname -> max connect time
my @to_close;
while (my $k = each %$sf) {
my AxKit2::Connection $v = $sf->{$k};
my $ref = ref $v;
next unless $v->isa('AxKit2::Console');
$conns++;
unless (defined $max_age{$ref}) {
$max_age{$ref} = $ref->max_idle_time || 0;
$max_connect{$ref} = $ref->max_connect_time || 0;
}
if (my $t = $max_connect{$ref}) {
if ($v->{create_time} < $now - $t) {
push @to_close, $v;
next;
}
}
if (my $t = $max_age{$ref}) {
if ($v->{alive_time} < $now - $t) {
push @to_close, $v;
}
}
}
$_->close("Timeout") foreach @to_close;
}
1;
( run in 0.872 second using v1.01-cache-2.11-cpan-437f7b0c052 )