Created
June 18, 2012 09:32
-
-
Save wakaba/2947640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require Parse::Netstat; | |
my $timer; $timer = AnyEvent->timer( | |
interval => 0.6, | |
cb => sub { | |
my $netstat; | |
AnyEvent::Util::run_cmd( | |
'LANG=C netstat --inet --inet6 -n -p -l', | |
'>' => \$netstat, | |
'2>' => \(my $dummy), | |
)->cb(sub { | |
my $stat = Parse::Netstat::parse_netstat(output => $netstat); | |
for (@{$stat->[2]->{active_conns} or []}) { | |
next unless defined $_->{pid}; | |
if ($_->{pid} == $pid and | |
$_->{local_port} == $port and | |
$_->{state} eq 'LISTEN') { | |
$cv_start->send; | |
undef $timer; | |
last; | |
} | |
} | |
}); | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment