Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
sub opensock { my $addr = $_[0]; my $port = $_[1]; my $sock; my $status = 0; $SIG{ALRM} = sub {die "$port timed out\n"}; eval { alarm(2); $sock = new IO::Socket::INET ( PeerAddr => $addr, PeerPort => $port, Proto => 'tcp', undef ); alarm (0); }; if ($sock) { $status=1; close($sock); } undef $sock; return $status; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket Connection Timeout lasts forever
by growlf (Pilgrim) on Mar 19, 2002 at 23:54 UTC |