| 1 | package Net::EmptyPort; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use base qw/Exporter/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use Errno qw/ECONNREFUSED/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use Fcntl; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use IO::Socket::IP; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 19 | our @EXPORT = qw/ can_bind empty_port check_port wait_port /; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 19 | our @EXPORT_OK = qw/ listen_socket /; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | sub can_bind { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_bind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | my ($host, $port, $proto) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | # The following must be split across two statements, due to | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # https://rt.perl.org/Public/Bug/Display.html?id=124248 | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | my $s = _listen_socket($host, $port, $proto); | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | return defined $s; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 30 | ▶ | sub _listen_socket { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_listen_socket: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 30 | my ($host, $port, $proto) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 30 | ▶ | $port ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$port ||= 0
MC/DC100%1/1
$port ||= 0
$port
Truth table100%2/2
A
A= $port
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 30 | ▶ | $proto ||= 'tcp'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$proto ||= "tcp"
MC/DC100%1/1
$proto ||= "tcp"
$proto
Truth table100%2/2
A
A= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 30 | ▶ | IO::Socket::IP->new( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | (($proto eq 'udp') ? () : (Listen => 5)), | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | LocalAddr => $host, | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | LocalPort => $port, | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | Proto => $proto, | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | V6Only => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)), | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | sub listen_socket { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listen_socket: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my ($host, $proto) = @{$_[0]}{qw(host proto)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | $host = '127.0.0.1' unless defined $host; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | return _listen_socket($host, undef, $proto); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # get a empty port on 49152 .. 65535 | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # http://www.iana.org/assignments/port-numbers | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 25 | ▶ | sub empty_port { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
empty_port: called CC=15 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 25 | ▶ | my ($host, $port, $proto) = @_ && ref $_[0] eq 'HASH' ? ($_[0]->{host}, $_[0]->{port}, $_[0]->{proto}) : (undef, @_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and ref $_[0] eq "HASH"
MC/DC100%2/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 25 | ▶ | $host = '127.0.0.1' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | unless defined $host; | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 25 | ▶ | $proto = $proto ? lc($proto) : 'tcp'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 25 | ▶ | if (defined $port) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # to ensure lower bound, check one by one in order | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | ▶ | $port = 49152 unless $port =~ /^[0-9]+$/ && $port < 49152; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$port =~ /^[0-9]+$/ and $port < 49152
MC/DC100%2/2
$port =~ /^[0-9]+$/ and $port < 49152
$port =~ /^[0-9]+$/
$port < 49152
Truth table100%3/3
A and B
A= $port =~ /^[0-9]+$/B= $port < 49152
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | while ( $port++ < 65000 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # Remote checks don't work on UDP, and Local checks would be redundant here... | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | ▶ | next if ($proto eq 'tcp' && check_port({ host => $host, port => $port })); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$proto eq "tcp" and check_port({"host", $host, "port", $port})
MC/DC0%0/2
$proto eq "tcp" and check_port({"host", $host, "port", $port})
$proto eq "tcp"
check_port({"host", $host, "port", $port})
Truth table66%2/3
A and B
A= $proto eq "tcp"B= check_port({"host", $host, "port", $port})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | return $port if can_bind($host, $port, $proto); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # kernel will select an unused port | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 21 | ▶ | while ( my $sock = _listen_socket($host, undef, $proto) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 21 | $port = $sock->sockport; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 21 | $sock->close; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 21 | ▶ | next if ($proto eq 'tcp' && check_port({ host => $host, port => $port })); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$proto eq "tcp" and check_port({"host", $host, "port", $port})
MC/DC0%0/2
$proto eq "tcp" and check_port({"host", $host, "port", $port})
$proto eq "tcp"
check_port({"host", $host, "port", $port})
Truth table66%2/3
A and B
A= $proto eq "tcp"B= check_port({"host", $host, "port", $port})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 21 | return $port; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | die "empty port not found"; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 96 | ▶ | sub check_port { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_port: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 96 | ▶ | my ($host, $port, $proto) = @_ && ref $_[0] eq 'HASH' ? ($_[0]->{host}, $_[0]->{port}, $_[0]->{proto}) : (undef, @_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and ref $_[0] eq "HASH"
MC/DC100%2/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 96 | ▶ | $host = '127.0.0.1' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | unless defined $host; | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 96 | ▶ | return _check_port_udp($host, $port) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$proto and lc $proto eq "udp"
MC/DC100%2/2
$proto and lc $proto eq "udp"
$proto
lc $proto eq "udp"
Truth table100%3/3
A and B
A= $protoB= lc $proto eq "udp"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | if $proto && lc($proto) eq 'udp'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # TCP, check if possible to connect | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 94 | my $sock = IO::Socket::IP->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | Proto => 'tcp', | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | PeerAddr => $host, | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | V6Only => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 92 | ▶ | if ($sock) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 14 | close $sock; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 14 | return 1; # The port is used. | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 78 | return 0; # The port is not used. | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | sub _check_port_udp { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_port_udp: called CC=6 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | my ($host, $port) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # send some UDP data and see if ICMP error is being sent back (i.e. ECONNREFUSED) | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | my $sock = IO::Socket::IP->new( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | Proto => 'udp', | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | PeerAddr => $host, | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | V6Only => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | Blocking => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ) or die "failed to create bound UDP socket:$!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | ▶ | $sock->send("0", 0) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | or die "failed to send a UDP packet:$!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | my ($rfds, $efds) = ('', ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | vec($rfds, fileno($sock), 1) = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | vec($efds, fileno($sock), 1) = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | select $rfds, undef, $efds, 0.1; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # after 0.1 second of silence, we assume that the server is up | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | my $up = defined($sock->recv(my $data, 1000)) || ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $sock->recv(my $data, 1000) || ($^O eq 'MSWin32' ? $^E != Errno::WSAECONNRESET() && $^E != Errno::WSAECONNREFUSED() : $! != 111)
$^E != Errno::WSAECONNRESET() and $^E != Errno::WSAECONNREFUSED()
MC/DC50%1/2
defined $sock->recv(my $data, 1000) || ($^O eq 'MSWin32' ? $^E != Errno::WSAECONNRESET() && $^E != Errno::WSAECONNREFUSED() : $! != 111)
defined $sock->recv(my $data, 1000)
($^O eq 'MSWin32' ? $^E != Errno::WSAECONNRESET() && $^E != Errno::WSAECONNREFUSED() : $! != 111)
MC/DC0%0/2
$^E != Errno::WSAECONNRESET() and $^E != Errno::WSAECONNREFUSED()
$^E != Errno::WSAECONNRESET()
$^E != Errno::WSAECONNREFUSED()
Truth table66%2/3
A || B
A= defined $sock->recv(my $data, 1000)B= ($^O eq 'MSWin32' ? $^E != Errno::WSAECONNRESET() && $^E != Errno::WSAECONNREFUSED() : $! != 111)
Truth table0%0/3
A and B
A= $^E != Errno::WSAECONNRESET()B= $^E != Errno::WSAECONNREFUSED()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ($^O eq 'MSWin32') | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | ? ($^E != Errno::WSAECONNRESET() && $^E != Errno::WSAECONNREFUSED()) | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | : ($! != ECONNREFUSED) | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | close $sock; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | $up; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 19 | ▶ | sub _make_waiter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_waiter: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 19 | my $max_wait = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 19 | my $waited = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 19 | my $sleep = 0.001; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 73 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 73 | ▶ | return 0 if $max_wait >= 0 && $waited > $max_wait; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$max_wait >= 0 and $waited > $max_wait
MC/DC100%2/2
$max_wait >= 0 and $waited > $max_wait
$max_wait >= 0
$waited > $max_wait
Truth table100%3/3
A and B
A= $max_wait >= 0B= $waited > $max_wait
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 69 | Time::HiRes::sleep($sleep); | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 69 | $waited += $sleep; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 69 | $sleep *= 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 69 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 19 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 19 | ▶ | sub wait_port { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wait_port: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 19 | my ($host, $port, $max_wait, $proto); | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | 19 | ▶ | if (@_ && ref $_[0] eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
@_ and ref $_[0] eq "HASH"
MC/DC100%2/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 15 | ($host, $port, $max_wait, $proto) = ($_[0]->{host}, $_[0]->{port}, $_[0]->{max_wait}, $_[0]->{proto}); | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | } elsif (@_==4) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # backward compat. | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ($port, (my $sleep), (my $retry), $proto) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $max_wait = $sleep * $retry; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | ($port, $max_wait, $proto) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 19 | ▶ | $host = '127.0.0.1' unless defined $host; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 19 | ▶ | $max_wait ||= 10; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$max_wait ||= 10
MC/DC100%1/1
$max_wait ||= 10
$max_wait
Truth table100%2/2
A
A= $max_wait
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 19 | ▶ | $proto = $proto ? lc($proto) : 'tcp'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 19 | my $waiter = _make_waiter($max_wait); | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 19 | ▶ | while ( $waiter->() ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 69 | ▶ | if ($^O eq 'MSWin32' && defined($port) ? `$^X -MTest::TCP::CheckPort -echeck_port $host $port $proto` : check_port({ host => $host, port => $port, proto => $proto })) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$^O eq "MSWin32" and defined $port
MC/DC0%0/2
$^O eq "MSWin32" and defined $port
$^O eq "MSWin32"
defined $port
Truth table33%1/3
A and B
A= $^O eq "MSWin32"B= defined $port
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 14 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 19 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||