On Thu Jan 16 07:33:02 2014, PEVANS wrote:
Show quoted text> On Sun Jan 12 10:40:20 2014, DAGOLDEN wrote:
> > The INCOMPATIBILITIES section lists the Timeout as an unsupported
> > parameter. Can it be added? If so, that would help the "drop-in"
> > support. If not, could the rationale for why not be added to the
> > documentation for clarity?
>
> Turns out that all the Timeout functionallity itself is implemented by
> the base IO::Socket class, and thus actually applies to /any/
> IO::Socket subclass. It is however not documented there, and instead
> mentioned briefly in passing in IO::Socket::INET, which doesn't do
> anything special to help implement it.
>
> There's therefore no need for IO::Socket::IP to document or mention it
> as it's simply some behaviour inherited from its superclass. I've just
> removed all mention of it instead.
This is not totally correct. IO::Socket handles timeout inside connect() using IO::Select:
https://metacpan.org/source/GBARR/IO-1.25/lib/IO/Socket.pm#L115
But IO::Socket::IP overloads this method. So, there is no timeout handling here
Here is a test:
use strict;
use Test::More;
use IO::Socket::INET;
use IO::Socket::IP;
use Time::HiRes;
use constant {
SLOW_HOST => '173.194.32.142', # google.com
SLOW_PORT => 81
};
$SIG{ALRM} = sub {
die "Alarmed\n";
};
for my $impl ('INET', 'IP') {
eval {
my $start = Time::HiRes::time;
alarm(10);
my $sock = "IO::Socket::$impl"->new(PeerHost => SLOW_HOST, PeerPort => SLOW_PORT, Timeout => 3);
alarm(0);
my $end = Time::HiRes::time;
my $err = $@;
ok(!$sock, "$impl: socket not created");
like($err, qr/timeout/i, "$impl: proper error") or diag $err;
my $duration = $end - $start;
ok($duration > 2 && $duration < 5, "$impl: timed out");
diag $duration;
};
ok(!$@, "$impl: no exceptions") or diag $@;
}
done_testing();
__END__
which outputs:
ok 1 - INET: socket not created
ok 2 - INET: proper error
ok 3 - INET: timed out
ok 4 - INET: no exceptions
# 3.00477385520935
not ok 5 - IP: no exceptions
1..5
# Failed test 'IP: no exceptions'
# at timeout.pl line 32.
# Alarmed
# Looks like you failed 1 test of 5.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/5 subtests
Test Summary Report
-------------------
timeout.pl (Wstat: 256 Tests: 5 Failed: 1)
Failed test: 5
Non-zero exit status: 1
Files=1, Tests=5, 13 wallclock secs ( 0.04 usr 0.00 sys + 0.08 cusr 0.02 csys = 0.14 CPU)
Result: FAIL