in reply to Timeout parameter for Net::Telnet under Windows

A quick bit of debugging with the Net::Telnet module shows you're getting hung up on line 1563:

connect $self, $remote_addr or die "problem connecting to \"$host\", port $port: $!\n";

I looked at 'perldoc Socket' and found the connect() routing but nothing glaring about 'blocking' or 'timeout' or something to that effect. Not sure why the alarm() around the connect() in Net::Telnet isn't having the proper affect.

Sorry no solution, but hopefully that points you (or someone smarter than me) in the right direction?

Replies are listed 'Best First'.
Re^2: Timeout parameter for Net::Telnet under Windows
by Corion (Patriarch) on Jan 22, 2016 at 15:38 UTC

    On Windows, alarm() doesn't interrupt system calls, so that's maybe why the timeout isn't working properly.

      I've logged a bug for this at https://rt.cpan.org/Public/Bug/Display.html?id=111370 with this info. Hopefully somebody can come up with a fix or a workaround. I'm having to write some ugly code to get around this in the meantime.

      As I said above "someone smarter than me" - thanks for coming to the rescue Corion!

      I just found and tried this code, still no luck. It still takes 20 to 30 seconds to regain control. From Chapter 18. The UDP Protocol, in "Network Programming with Perl".

      eval { local $SIG{ALRM} = sub { die "timeout\n" }; alarm(2); $t = new Net::Telnet (Host => $host, Port => $port, Timeout => 1, Prompt => '/Escape character is.+\n/', Rs => ' ', Ors => '', Binmode => 1, Telnetmode => 1, Errmode => 'return'); alarm(0); }; if ($@) { die $@ unless $@ eq "timeout\n"; warn "Timed out!\n"; }

        I also tried ualarm() from Time::HiRes;

        For that it's even worse. I get "Time::HiRes::ualarm(): unimplemented in this platform"

        *sigh*