Hi,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.