I am running ActiveState Perl 5.8.8 on Windows XP, SP3.
I am trying to find a way to timeout an IO::Socket::INET request, but am having difficulty.
The problem is that the Timeout parameter is not implemented for some reason (though it does exist), and on Windows it seems that alarms don't work either.
I've tried various things, but all to no avail. The code I'm testing looks much like this:
#!d:/perl/bin/perl.exe use warnings; use strict; use IO::Socket; $SIG{ALRM} = sub { die "timeout" }; eval { alarm(3); my $socket=new IO::Socket::INET( PeerAddr=> 'www.somedomain.com', PeerPort=> 80, Proto => 'tcp', Timeout => '3') || die "Could not Connect $!\n"; print $socket "GET / HTTP/1.0\n\n"; while(<$socket>) { # .... } alarm(0); };
All I'm really doing is needing to get headers back from a number of sites, but some of the domains will be dead (and don't timeout for ages), or may take a while longer than the couple of seconds which I want to allow. However, although I know that I could use alarms and signals etc on Linux, it seems very difficult to find any solution - elegant or not - for Windows.
I've searched high and low for a solution, and found similar queries going back years, but as yet cannot find any way around the problem, yet I cannot believe that there isn't a way to do this.
Any assistance appreciated!
In reply to use IO::Socket / Windows Timeout by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |