Subject: | Timeout not honored under Windows 7 Enterprise |
Date: | Fri, 22 Jan 2016 11:10:14 -0500 |
To: | bug-Net-Telnet [...] rt.cpan.org |
From: | John Simpson <john_simpson [...] swajime.com> |
I've posted this at http://perlmonks.org/?node_id=1153372 to see if I can
get a quick fix or workaround. The preliminary response by Corion is "On
Windows, alarm() doesn't interrupt system calls, so that's maybe why the
timeout isn't working properly."
-----
I'm having difficulty controlling the timeout when initializing a
Net::Telnet session. I set Timeout to 1, I've also set -timeout to 1.
However, the the constructor is taking between 20 and 30 seconds before it
times out and returns to the code. I need to bring this down to 2 seconds
or less. Is there any way to make this call abort if it is not successfull
within 1 or 2 seconds?
Note that I am only having this problem in Windows. On the mac, the timeout
works just fine.
OS: Windows 7 Enterprise Version 6.1 (Build 7601: Service Pack 1)
PERL: v5.16.3 built for MSWin32-x86-multi-thread
This is ActivePerl 5.16.3 Build 1604 according to Windows.
Here is the code to reproduce the problem:
#!/usr/bin/perl
#
use strict;
use warnings;
use Net::Telnet;
my $host = '192.168.130.112'; # valid host that is offline
my $port = 10001;
print "DEBUG 1\n";
my $t = new Net::Telnet (Host => $host,
Port => $port,
Timeout => 1,
# -timeout => 1,
Prompt => '/Escape character is.+\n/',
Rs => ' ',
Ors => '',
Binmode => 1,
Telnetmode => 1,
Errmode => 'return');
print "DEBUG 2\n";
if (!$t) {
die "Failed to create telnet session\n";
}