line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Async::Ping::TCP; |
2
|
|
|
|
|
|
|
$Net::Async::Ping::TCP::VERSION = '0.001001'; |
3
|
1
|
|
|
1
|
|
1203
|
use Moo; |
|
1
|
|
|
|
|
8649
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
1283
|
use warnings NONFATAL => 'all'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
585
|
use Future; |
|
1
|
|
|
|
|
6554
|
|
|
1
|
|
|
|
|
62
|
|
7
|
1
|
|
|
1
|
|
12
|
use POSIX 'ECONNREFUSED'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
8
|
1
|
|
|
1
|
|
91
|
use Time::HiRes; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
97
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has default_timeout => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
default => 5, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has service_check => ( is => 'rw' ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has bind => ( is => 'rw' ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has port_number => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
default => 7, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub ping { |
27
|
2
|
|
|
2
|
0
|
7557
|
my ($self, $loop, $host, $timeout) = @_; |
28
|
2
|
|
33
|
|
|
39
|
$timeout ||= $self->default_timeout; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
15
|
my $service_check = $self->service_check; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
15
|
my $t0 = [Time::HiRes::gettimeofday]; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return Future->wait_any( |
35
|
|
|
|
|
|
|
$loop->connect( |
36
|
|
|
|
|
|
|
host => $host, |
37
|
|
|
|
|
|
|
service => $self->port_number, |
38
|
|
|
|
|
|
|
socktype => 'stream', |
39
|
|
|
|
|
|
|
($self->bind ? ( |
40
|
|
|
|
|
|
|
local_host => $self->bind, |
41
|
|
|
|
|
|
|
) : ()), |
42
|
|
|
|
|
|
|
), |
43
|
|
|
|
|
|
|
$loop->timeout_future(after => $timeout) |
44
|
|
|
|
|
|
|
) |
45
|
|
|
|
|
|
|
->then( |
46
|
0
|
|
|
0
|
|
0
|
sub { Future->done(Time::HiRes::tv_interval($t0)) }, |
47
|
|
|
|
|
|
|
sub { |
48
|
2
|
|
|
2
|
|
1076609
|
my ($human, $layer) = @_; |
49
|
2
|
|
|
|
|
23
|
my $ex = pop; |
50
|
2
|
100
|
66
|
|
|
21
|
if ($layer && $layer eq 'connect') { |
51
|
1
|
50
|
33
|
|
|
15
|
return Future->done(Time::HiRes::tv_interval($t0)) |
52
|
|
|
|
|
|
|
if !$service_check && $ex == ECONNREFUSED; |
53
|
|
|
|
|
|
|
} |
54
|
1
|
|
|
|
|
7
|
Future->fail(Time::HiRes::tv_interval($t0)) |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
) |
57
|
2
|
50
|
|
|
|
39
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |