connect + alarm
[email protected] (Axel Rose) Sun, 2 Dec 2001 19:24:10 +0100
| Newsgroups | perl.macperl.porters |
|---|---|
| Message-ID | <p05100301b8301b7d10ca@[172.16.22.38]> |
Hello Chris,
I'm a bit desperate because of the network related problems I still
have with beta 2.
An important download script I'm working on failes in 1 out of 10 cases.
In order to solve the issue faster I reported on SF a strange
behaviour I observed when using alarm() and connect().
I use the same alarm scheme in my downloader script.
With beta 1 there was a system error 2 with OTLookupName.
Under beta 2 if I interrupt my test script I see OTLookupName
running in MacsBug
It looks to me as if the first alarm() works as expected but a second
won't do if the first connection failed.
Is the problem description still understandable?
Can I hope the issue will be resolved?
Can please others verify this?
Here is the test script. Please change $port and @addr so that
the first host answers and the last two don't answer.
#!perl -w
use strict;
use IO::Socket;
my $timeout = 5;
my $port = 407; # timbuktu
my @addr = ("128.128.18.103", "128.128.18.104", "128.128.18.105", );
for ( @addr ) {
check( $_ )
}
## end of main
#
sub check {
my $ipaddr = shift;
my $paddr = ip2paddr( $ipaddr );
local *SOCKET;
socket( SOCKET, PF_INET, SOCK_STREAM, getprotobyname q(tcp) )
or die "socket creation failed\n$!";
eval {
local $SIG{'ALRM'} = sub { die "timeout\n" };
print "DEBUG: connect to $ipaddr at port $port with timeout $timeout\n";
alarm $timeout;
connect SOCKET, $paddr or die "cannot connect: $!\n";
};
alarm 0;
shutdown SOCKET, 1;
close SOCKET;
print "DEBUG: \$\@ = $@" if $@;
if( $@ ) { print "no connection to $ipaddr\n"; return }
print "OK: $ipaddr\n";
}
sub ip2paddr {
my $host = shift;
my $iaddr = inet_aton( $host )
or die "couldn't convert '$host' into an Internet address: $!\n";
my $paddr = sockaddr_in( $port, $iaddr );
}
__END__
If I run this the first connection is successful, the second
times out properly and the third waits, and waits, and waits ...
Thanks so much for your support
Axel
--
----------------------------------------------------------------------
Axel Rose, Springer & Jacoby Digital GmbH & Co. KG, mailto:[email protected]
pub PGP key 1024/A21CB825 E0E4 BC69 E001 96E9 2EFD 86CA 9CA1 AAC5
"... denn alles, was entsteht, ist wert, daß es zugrunde geht ..."