odd you should say that. I use almost exactly the same code and I have never been troubled with lengthy delays. Are you sure you don't have a problem with DNS name resolution (even though your example shows the use of numeric IP addresses)?
Here is the code I use. It is part of a CGI script, so there is a $q CGI object hanging around, and a few constant values for pretty colors, such as use constant PAINT_OK => '#008000' and so on.
sub test_socket {
my $s = IO::Socket::INET->new( @_, Timeout=>2, Proto => 'tcp' );
if( $s ) {
close $s;
$q->font( {-color=>PAINT_OK}, 'ok' );
}
else {
$q->font( {-color=>PAINT_NOK}, $! )
}
}
my %tcp_probe = (
'foo<br>Apache' => test_socket( PeerHost => '172.17.0.2', Pe
+erPort => 80, ),
'foo<br>Lotus' => test_socket( PeerHost => '172.17.0.2', Pe
+erPort => 1352, ),
'bar<br>Apache' => test_socket( PeerHost => '172.17.0.3', Pe
+erPort => 80, ),
'bar<br>Lotus' => test_socket( PeerHost => '172.17.0.3', Pe
+erPort => 1352, ),
'example<br>Apache' => test_socket( PeerHost => 'www.example.com',
+ PeerPort => 80, ),
'example<br>Domino' => test_socket( PeerHost => 'www.example.com',
+ PeerPort => 8000, ),
'example<br>Lotus' => test_socket( PeerHost => 'www.example.com',
+ PeerPort => 1352, ),
'Web<br>Proxy' => test_socket( PeerHost => '172.17.0.9',
+ PeerPort => 8080, ),
'baz<br>Sybase' => test_socket( PeerHost => '172.17.0.1', Peer
+Port => 4100, ),
'baz<br>Samba' => test_socket( PeerHost => '172.17.0.1', Peer
+Port => 139, ),
);
print $q->h3('Mission Critical'), $q->table(
$q->TR(
$q->th( {-width=>60, -valign=>'bottom', -bgcolor=>'#fff0e0'},
[ sort keys %tcp_probe ]
)
)
. $q->TR(
$q->td( {-width=>60, -align=>'center'},
[ map { $tcp_probe{$_} } sort keys %tcp_probe ]
)
)
);
The only other thing I could suggest would be to set an alarm of a second or two, an alarm handler and eval the code, in order to forcibly cancel the code. But if it's blocking at a low enough level, alarm won't necessarily work either, I've had that happen in the past.
print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u' |