Skip to content

Instantly share code, notes, and snippets.

@qsimpleq
Last active August 29, 2015 13:57
Show Gist options
  • Save qsimpleq/9705093 to your computer and use it in GitHub Desktop.
Save qsimpleq/9705093 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/lib" }
use AnyEvent;
use AnyEvent::Ping;
my @a = ('127.0.0.1');
for my $iter (1 .. 10) {
my @copy = @a;
my $cv = AnyEvent->condvar;
my $ping = AnyEvent::Ping->new;
$ping->timeout(0.1);
while (@copy) {
my $url = shift @copy;
$cv->begin;
$ping->ping(
$url, 1,
sub {
$cv->end;
$ping->end if scalar @copy == 0; # comment this line and it's broken with
# Unable to create icmp socket : Too many open files
}
);
}
print $iter . '|';
$cv->recv;
undef $ping;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment