line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Async::Ping::TCP; |
2
|
|
|
|
|
|
|
$Net::Async::Ping::TCP::VERSION = '0.002000'; |
3
|
1
|
|
|
1
|
|
1788
|
use Moo; |
|
1
|
|
|
|
|
8156
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
1112
|
use warnings NONFATAL => 'all'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
7
|
1
|
|
|
1
|
|
611
|
use Future; |
|
1
|
|
|
|
|
6037
|
|
|
1
|
|
|
|
|
32
|
|
8
|
1
|
|
|
1
|
|
8
|
use POSIX 'ECONNREFUSED'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
9
|
1
|
|
|
1
|
|
90
|
use Time::HiRes; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'IO::Async::Notifier'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
96
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has default_timeout => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
default => 5, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has service_check => ( is => 'rw' ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has bind => ( is => 'rw' ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has port_number => ( |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
default => 7, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Overrides method in IO::Async::Notifier to allow specific options in this class |
30
|
|
|
|
|
|
|
sub configure_unknown |
31
|
2
|
|
|
2
|
1
|
1471
|
{ my $self = shift; |
32
|
2
|
|
|
|
|
7
|
my %params = @_; |
33
|
2
|
|
|
|
|
8
|
delete $params{$_} foreach qw/default_timeout service_check bind/; |
34
|
2
|
50
|
|
|
|
22
|
return unless keys %params; |
35
|
0
|
|
|
|
|
0
|
my $class = ref $self; |
36
|
0
|
|
|
|
|
0
|
croak "Unrecognised configuration keys for $class - " . join( " ", keys %params ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub ping { |
41
|
6
|
|
|
6
|
0
|
18706
|
my $self = shift; |
42
|
|
|
|
|
|
|
# Maintain compat with old API |
43
|
6
|
|
|
|
|
25
|
my $legacy = ref $_[0] eq 'IO::Async::Loop::Poll'; |
44
|
6
|
100
|
|
|
|
34
|
my $loop = $legacy ? shift : $self->loop; |
45
|
|
|
|
|
|
|
|
46
|
6
|
|
|
|
|
51
|
my ($host, $timeout) = @_; |
47
|
6
|
|
33
|
|
|
63
|
$timeout ||= $self->default_timeout; |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
26
|
my $service_check = $self->service_check; |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
32
|
my $t0 = [Time::HiRes::gettimeofday]; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return Future->wait_any( |
54
|
|
|
|
|
|
|
$loop->connect( |
55
|
|
|
|
|
|
|
host => $host, |
56
|
|
|
|
|
|
|
service => $self->port_number, |
57
|
|
|
|
|
|
|
socktype => 'stream', |
58
|
|
|
|
|
|
|
($self->bind ? ( |
59
|
|
|
|
|
|
|
local_host => $self->bind, |
60
|
|
|
|
|
|
|
) : ()), |
61
|
|
|
|
|
|
|
), |
62
|
|
|
|
|
|
|
$loop->timeout_future(after => $timeout) |
63
|
|
|
|
|
|
|
) |
64
|
|
|
|
|
|
|
->then( |
65
|
0
|
|
|
0
|
|
0
|
sub { Future->done(Time::HiRes::tv_interval($t0)) }, |
66
|
|
|
|
|
|
|
sub { |
67
|
6
|
|
|
6
|
|
2121829
|
my ($human, $layer) = @_; |
68
|
6
|
|
|
|
|
13
|
my $ex = pop; |
69
|
6
|
100
|
100
|
|
|
61
|
if ($layer && $layer eq 'connect') { |
70
|
2
|
50
|
33
|
|
|
43
|
return Future->done(Time::HiRes::tv_interval($t0)) |
71
|
|
|
|
|
|
|
if !$service_check && $ex == ECONNREFUSED; |
72
|
|
|
|
|
|
|
} |
73
|
4
|
|
|
|
|
29
|
Future->fail(Time::HiRes::tv_interval($t0)) |
74
|
|
|
|
|
|
|
}, |
75
|
|
|
|
|
|
|
) |
76
|
6
|
50
|
|
|
|
66
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |