Commit 9e9d9bf9 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fix regression on pushbuild 1. The cygwin perl is ancient there, and Net::Ping...

Fix regression on pushbuild 1. The cygwin perl is ancient there, and Net::Ping does not have port_number method (port_number was introduced around 2007). The fix is to check if port_number is present. Otherwise, fallback to the slow connect().
parent cf1845f4
...@@ -24,7 +24,22 @@ use Errno; ...@@ -24,7 +24,22 @@ use Errno;
use My::Platform; use My::Platform;
use if IS_WINDOWS, "Net::Ping"; use if IS_WINDOWS, "Net::Ping";
# Ancient perl might not have port_number method for Net::Ping.
# Check it and use fallback to connect() if it is not present.
BEGIN
{
my $use_netping= 0;
if (IS_WINDOWS)
{
my $ping = Net::Ping->new();
if ($ping->can("port_number"))
{
$use_netping= 1;
}
}
eval 'sub USE_NETPING { $use_netping }';
}
sub sleep_until_file_created ($$$); sub sleep_until_file_created ($$$);
sub mtr_ping_port ($); sub mtr_ping_port ($);
...@@ -33,22 +48,21 @@ sub mtr_ping_port ($) { ...@@ -33,22 +48,21 @@ sub mtr_ping_port ($) {
mtr_verbose("mtr_ping_port: $port"); mtr_verbose("mtr_ping_port: $port");
if (IS_WINDOWS) if (IS_WINDOWS && USE_NETPING)
{ {
# Under Windows, connect to a port that is not open is slow # Under Windows, connect to a port that is not open is slow
# It takes ~1sec. Net::Ping with small timeout is much faster. # It takes ~1sec. Net::Ping with small timeout is much faster.
my $ping = Net::Ping->new(); my $ping = Net::Ping->new();
$ping->port_number($port); $ping->port_number($port);
if ($ping->ping("localhost",0.1)) if ($ping->ping("localhost",0.1))
{ {
mtr_verbose("USED"); mtr_verbose("USED");
return 1; return 1;
} }
else else
{ {
mtr_verbose("FREE"); mtr_verbose("FREE");
return 0; return 0;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment