Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use IO::Socket / Windows Timeout
by zentara (Cardinal) on Aug 06, 2010 at 20:02 UTC | |
|
Re: use IO::Socket / Windows Timeout
by BrowserUk (Patriarch) on Aug 06, 2010 at 21:13 UTC | |
by bonzi (Acolyte) on Apr 29, 2024 at 09:51 UTC | |
by marto (Cardinal) on Apr 29, 2024 at 09:55 UTC | |
by DanielSpaniel (Scribe) on Aug 07, 2010 at 01:17 UTC | |
by zentara (Cardinal) on Aug 07, 2010 at 13:33 UTC |