Closed p5pRT closed 20 years ago
The LWP library I'm using had problems with defined timeouts so I traced it back to IO::Socket::connect:
sub connect { @_ == 2 || @_ == 3 or croak 'usage: $fh->connect(NAME) or $fh->connect(PORT\, ADDR)'; my $fh = shift; my $addr = @_ == 1 ? shift : sockaddr_in(@_); my $timeout = ${*$fh}{'io_socket_timeout'}; local($SIG{ALRM}) = $timeout ? sub { undef $fh; } : $SIG{ALRM} || 'DEFAULT';
eval { croak 'connect: Bad address' if(@_ == 2 && !defined $_[1]);
if($timeout) { defined $Config{d_alarm} && defined alarm($timeout) or $timeout = 0; }
my $ok = connect($fh\, $addr);
alarm(0) if($timeout);
croak "connect: timeout" unless defined $fh;
undef $fh unless $ok; };
$fh; }
Shouldn't the line were the signal handler is defined read:
local($SIG{ALRM}) = $timeout ? sub { undef $fh; die; } : $SIG{ALRM} || 'DEFAULT';
otherwise it will 'never' timeout on the connect() call.
Regards\,
Wilfred.
Wilfred Mollenvanger \wilfredm@​inet\.kpn\.com writes:
----------------------------------------------------------------- [Please enter your report here] The LWP library I'm using had problems with defined timeouts so I traced it back to IO::Socket::connect:
sub connect { @_ == 2 || @_ == 3 or croak 'usage: $fh->connect(NAME) or $fh->connect(PORT\, ADDR)'; my $fh = shift; my $addr = @_ == 1 ? shift : sockaddr_in(@_); my $timeout = ${*$fh}{'io_socket_timeout'}; local($SIG{ALRM}) = $timeout ? sub { undef $fh; } : $SIG{ALRM} || 'DEFAULT';
eval \{ croak 'connect​: Bad address' if\(@​\_ == 2 && \!defined $\_\[1\]\); if\($timeout\) \{ defined $Config\{d\_alarm\} && defined alarm\($timeout\) or $timeout = 0; \} my $ok = connect\($fh\, $addr\); alarm\(0\) if\($timeout\); croak "connect​: timeout" unless defined $fh; undef $fh unless $ok; \}; $fh;
}
Shouldn't the line were the signal handler is defined read:
local($SIG{ALRM}) = $timeout ? sub { undef $fh; die; } : $SIG{ALRM} || 'DEFAULT';
otherwise it will 'never' timeout on the connect() call.
The latest version of IO::Socket\, which is bundled with perl5.5.650 (perl's latest development release) will use non-blocking connect instead of alarm. You can can achieve the same with perl5.005_03 by installing IO-1.20 from CPAN.
I don't know if perl5.005_04 if/when it comes out will try to upgrade the IO modules\, but I doubt it.
Regards\, Gisle
Migrated from rt.perl.org#2167 (status was 'resolved')
Searchable as RT2167$