Commit ca0e746d authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Bug #44530 mtr v2 startup very slow on Windows.

MTR is stuck for about 20 seconds checking for free ports.
The reason is that perl's connect()  takes 1 second on windows
if port is not opened.

This patch fixes the mtr_ping_port implementation on Windows
to use Net::Ping for the port checking with small (0.1sec) timeout.

This patch also removes pointless second call to check_ports_free() 
in case of auto build thread.
parent 2943d2b7
......@@ -21,6 +21,9 @@
use strict;
use Socket;
use Errno;
use My::Platform;
use if IS_WINDOWS, "Net::Ping";
sub sleep_until_file_created ($$$);
sub mtr_ping_port ($);
......@@ -30,6 +33,25 @@ sub mtr_ping_port ($) {
mtr_verbose("mtr_ping_port: $port");
if (IS_WINDOWS)
{
# Under Windows, connect to a port that is not open is slow
# It takes ~1sec. Net::Ping with small timeout is much faster.
my $ping = Net::Ping->new();
$ping->port_number($port);
if ($ping->ping("localhost",0.1))
{
mtr_verbose("USED");
return 1;
}
else
{
mtr_verbose("FREE");
return 0;
}
}
my $remote= "localhost";
my $iaddr= inet_aton($remote);
if ( ! $iaddr )
......
......@@ -1344,14 +1344,13 @@ sub set_build_thread_ports($) {
else
{
$build_thread = $opt_build_thread + $thread - 1;
if (! check_ports_free($build_thread)) {
# Some port was not free(which one has already been printed)
mtr_error("Some port(s) was not free")
}
}
$ENV{MTR_BUILD_THREAD}= $build_thread;
if (! check_ports_free($build_thread)) {
# Some port was not free(which one has already been printed)
mtr_error("Some port(s) was not free")
}
# Calculate baseport
$baseport= $build_thread * 10 + 10000;
if ( $baseport < 5001 or $baseport + 9 >= 32767 )
......
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