blib/lib/Linux/Event/_Socket/Connection.pm

filter: Statementstmt 83.4% 353 / 423 Branchbran 67.0% 165 / 246 Conditioncond 39.4% 77 / 195 MC/DCmcdc 14.1% 15 / 106 Subroutinesub 76.4% 39 / 51 Podpod 0.0% 0 / 14 totaltotal 62.7% 649 / 1035 CC 197 SCAR 42.1
CC
197
Cov
69%
new
205.5
_attempt_next
46.0
_happy_eyeballs_order
29.4
CRAP 67.7
« blib/lib/Linux/Event/_Socket/Dgram.pm ↑ Summary blib/lib/Linux/Event/Loop.pm »
1 package Linux::Event::_Socket::Connection;
2 120 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 120 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 120 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 120 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 120 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 120 ▶use POSIX qw(isfinite);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 120 ▶use Scalar::Util qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 120 ▶use Socket qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 AF_INET AF_INET6 AF_UNIX
13 SOCK_STREAM SOCK_NONBLOCK SOCK_CLOEXEC
14 SOL_SOCKET SO_ERROR
15 inet_pton
16 pack_sockaddr_in pack_sockaddr_in6 pack_sockaddr_un
17 120 );
18 120 ▶use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 120 ▶use Linux::Event::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 120 ▶use Linux::Event::_Resolver ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 120 ▶use Linux::Event::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 120 ▶use Linux::Event::_SocketConfig ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 120 require XSLoader;
26 120 XSLoader::load(__PACKAGE__);
27  
28 0 ▶sub _introspection_owner ($self) { $self->{stream} }
Subroutine _introspection_owner: not called CC=1 SCAR=6.9
29  
30 1117 ▶sub _timeout ($value) {
Subroutine _timeout: called CC=7 SCAR=19.7
31 1117 ▶ $value = 10 if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 17 1100 1117
32 1117 ▶ croak 'new(): timeout must be a non-negative number of seconds'
Branch: 1 branch
BranchTrueFalseTotal
if ref $value or not $value =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u or $value < 0 1 1116 1117
Condition66%4/6
ref $value or not $value =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u or $value < 0
l!l&&r!l&&!r
101116
ref $value or not $value =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u
l!l&&r!l&&!r
011116
MC/DC33%1/3
ref $value or not $value =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u or $value < 0
ref $value not $value =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u $value < 0
Truth table50%2/4
A or not(B) or C
A= ref $valueB= not $value =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/uC= $value < 0
ABCresult
1XX1
01X1
0011
0000
33 if ref($value)
34 || $value !~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/
35 || $value < 0;
36 1116 $value = 0 + $value;
37 1116 ▶ croak 'new(): timeout must be a finite number of seconds'
Branch: 1 branch
BranchTrueFalseTotal
unless isfinite($value) 0 1116 1116
38 if !isfinite($value);
39 1116 ▶ croak 'new(): timeout exceeds the supported timer range'
Branch: 1 branch
BranchTrueFalseTotal
if $value > 2147483647 1 1115 1116
40 if $value > 2_147_483_647;
41 1115 return $value;
42 }
43  
44 5 ▶sub _target_error_fields ($self) {
Subroutine _target_error_fields: called CC=1 SCAR=0.0
45 return (
46 host => $self->{host},
47 port => $self->{port},
48 path => $self->{unix},
49 family => $self->{family},
50 attempts => $self->{attempt_count},
51 5 );
52 }
53  
54 5 ▶sub _error ($self, %arg) {
Subroutine _error: called CC=1 SCAR=0.0
55 5 return Linux::Event::Error->new(
56 _target_error_fields($self),
57 %arg,
58 );
59 }
60  
61 3 ▶sub _system_message ($errno) {
Subroutine _system_message: called CC=1 SCAR=0.0
62 3 local $! = $errno;
63 3 return "$!";
64 }
65  
66 1117 ▶sub new ($class, %opt) {
Subroutine new: called CC=67 SCAR=53.3
Pod undocumented
67 1117 ▶ croak 'new(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1117 1117
68 1117 ▶ croak 'new(): internal connection must be created for a Stream'
Branch: 1 branch
BranchTrueFalseTotal
if $class ne __PACKAGE__ 0 1117 1117
69 if $class ne __PACKAGE__;
70 1117 my $loop = delete $opt{loop};
71 1117 ▶ croak 'new(): loop must be an object implementing add(), watch(), and watch_fd()'
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch") && $loop->can("watch_fd") 0 1117 1117
Condition8%1/12
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch") && $loop->can("watch_fd")
!ll&&!rl&&r
111700
ref $loop && $loop->can('add') && $loop->can('watch') && $loop->can('watch_fd')
!ll&&!rl&&r
000
ref $loop and $loop->can("add") and $loop->can("watch")
!ll&&!rl&&r
000
ref $loop and $loop->can("add")
!ll&&!rl&&r
000
MC/DC0%0/5
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch") && $loop->can("watch_fd")
defined $loop ref $loop $loop->can("add") $loop->can("watch") $loop->can('watch_fd')
Truth table16%1/6
A and not(B and C and D && E)
A= defined $loopB= ref $loopC= $loop->can("add")D= $loop->can("watch")E= $loop->can('watch_fd')
ABCDEresult
0XXXX0
111110
10XXX1
110XX1
1110X1
111101
72 if defined($loop) && (!ref($loop) || !$loop->can('add')
73 || !$loop->can('watch') || !$loop->can('watch_fd'));
74 1117 my $stream = delete $opt{stream};
75 1117 ▶ croak 'new(): stream must be a Linux::Event::_ByteStream object'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $stream and $stream->isa("Linux::Event::_ByteStream") 0 1117 1117
Condition33%1/3
ref $stream and $stream->isa("Linux::Event::_ByteStream")
!ll&&!rl&&r
001117
MC/DC0%0/2
ref $stream and $stream->isa("Linux::Event::_ByteStream")
ref $stream $stream->isa("Linux::Event::_ByteStream")
Truth table33%1/3
A and B
A= ref $streamB= $stream->isa("Linux::Event::_ByteStream")
ABresult
0X0
100
111
76 if !ref($stream) || !$stream->isa('Linux::Event::_ByteStream');
77 1117 my $timeout = _timeout(delete $opt{timeout});
78 1115 my $socket_policy = delete $opt{socket_policy};
79 1115 ▶ croak 'new(): internal socket_policy must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if ref $socket_policy ne "HASH" 0 1115 1115
80 if ref($socket_policy) ne 'HASH';
81 1115 my $bind_device = delete $opt{bind_device};
82 1115 ▶ croak 'new(): bind_device must be a non-empty interface name'
Branch: 1 branch
BranchTrueFalseTotal
if defined $bind_device and ref $bind_device || $bind_device eq "" || $bind_device =~ /\0/u 0 1115 1115
Condition11%1/9
defined $bind_device and ref $bind_device || $bind_device eq "" || $bind_device =~ /\0/u
!ll&&!rl&&r
111500
ref $bind_device or $bind_device eq "" or $bind_device =~ /\0/u
l!l&&r!l&&!r
000
ref $bind_device or $bind_device eq ""
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $bind_device and ref $bind_device || $bind_device eq "" || $bind_device =~ /\0/u
defined $bind_device ref $bind_device $bind_device eq "" $bind_device =~ /\0/u
Truth table20%1/5
A and B or C or D
A= defined $bind_deviceB= ref $bind_deviceC= $bind_device eq ""D= $bind_device =~ /\0/u
ABCDresult
0XXX0
10000
11XX1
101X1
10011
83 if defined($bind_device)
84 && (ref($bind_device) || $bind_device eq '' || $bind_device =~ /\0/);
85 1115 my $has_local_host = exists $opt{local_host};
86 1115 my $local_host = delete $opt{local_host};
87 1115 my $has_local_port = exists $opt{local_port};
88 1115 my $local_port = delete $opt{local_port};
89 1115 ▶ $local_port = 0 if !$has_local_port;
Branch: 1 branch
BranchTrueFalseTotal
unless $has_local_port 1110 5 1115
90 1115 ▶ croak 'new(): local_port must be an integer between 0 and 65535'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $local_port or ref $local_port or not $local_port =~ /\A\d+\z/u or $local_port > 65535 1 1114 1115
Condition66%6/9
not defined $local_port or ref $local_port or not $local_port =~ /\A\d+\z/u or $local_port > 65535
l!l&&r!l&&!r
101114
not defined $local_port or ref $local_port or not $local_port =~ /\A\d+\z/u
l!l&&r!l&&!r
101114
not defined $local_port or ref $local_port
l!l&&r!l&&!r
101114
MC/DC25%1/4
not defined $local_port or ref $local_port or not $local_port =~ /\A\d+\z/u or $local_port > 65535
not defined $local_port ref $local_port not $local_port =~ /\A\d+\z/u $local_port > 65535
Truth table40%2/5
not(A) or B or not(C) or D
A= not defined $local_portB= ref $local_portC= not $local_port =~ /\A\d+\z/uD= $local_port > 65535
ABCDresult
1XXX1
01XX1
001X1
00011
00000
91 if !defined($local_port) || ref($local_port)
92 || $local_port !~ /\A\d+\z/
93 || $local_port > 65535;
94 1114 my ($local_family, $local_packed);
95 1114 ▶ if ($has_local_host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_local_host) 2 1112 1114
96 2 ▶ croak 'new(): local_host must be a non-empty numeric IP address'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $local_host or ref $local_host or $local_host eq "" 0 2 2
Condition33%2/6
not defined $local_host or ref $local_host or $local_host eq ""
l!l&&r!l&&!r
002
not defined $local_host or ref $local_host
l!l&&r!l&&!r
002
MC/DC0%0/3
not defined $local_host or ref $local_host or $local_host eq ""
not defined $local_host ref $local_host $local_host eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $local_hostB= ref $local_hostC= $local_host eq ""
ABCresult
1XX1
01X1
0011
0000
97 if !defined($local_host) || ref($local_host) || $local_host eq '';
98 2 $local_packed = inet_pton(AF_INET, $local_host);
99 2 ▶ $local_family = AF_INET if defined $local_packed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $local_packed 1 1 2
100 2 ▶ if (!defined $local_packed) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $local_packed) 1 1 2
101 1 $local_packed = inet_pton(AF_INET6, $local_host);
102 1 ▶ $local_family = AF_INET6 if defined $local_packed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $local_packed 1 0 1
103 }
104 2 ▶ croak 'new(): local_host must be a numeric IPv4 or IPv6 address'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local_family 0 2 2
105 if !defined $local_family;
106 }
107  
108 1114 ▶ my $host_mode = exists($opt{host}) || exists($opt{port});
Condition66%2/3
exists $opt{'host'} || exists $opt{'port'}
l!l&&r!l&&!r
1104010
MC/DC50%1/2
exists $opt{'host'} || exists $opt{'port'}
exists $opt{'host'} exists $opt{'port'}
Truth table66%2/3
A || B
A= exists $opt{'host'}B= exists $opt{'port'}
ABresult
1X1
011
000
109 1114 my $unix_mode = exists $opt{unix};
110 1114 my $sockaddr_mode = exists $opt{sockaddr};
111 1114 ▶ my $mode_count = ($host_mode ? 1 : 0) + ($unix_mode ? 1 : 0)
Branch: 3 branches
BranchTrueFalseTotal
$host_mode ? : 1104 10 1114
$unix_mode ? : 5 1109 1114
$sockaddr_mode ? : 5 1109 1114
112 + ($sockaddr_mode ? 1 : 0);
113 1114 ▶ croak 'new(): exactly one address mode is required '
Branch: 1 branch
BranchTrueFalseTotal
if $mode_count != 1 2 1112 1114
114 . '(host/port, unix, or sockaddr)'
115 if $mode_count != 1;
116  
117 1112 my ($host, $port, $unix, $sockaddr, $family);
118 1112 ▶ if ($host_mode) {
Branch: 2 branches
BranchTrueFalseTotal
if ($host_mode) { } 1103 9 1112
elsif ($unix_mode) { } 4 5 9
119 1103 $host = delete $opt{host};
120 1103 $port = delete $opt{port};
121 1103 ▶ croak 'new(): host is required' if !defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 1103 1103
122 1103 ▶ croak 'new(): host must be a non-empty string without NUL bytes'
Branch: 1 branch
BranchTrueFalseTotal
if ref $host or $host eq "" or $host =~ /\0/u 2 1101 1103
Condition83%5/6
ref $host or $host eq "" or $host =~ /\0/u
l!l&&r!l&&!r
111101
ref $host or $host eq ""
l!l&&r!l&&!r
011102
MC/DC66%2/3
ref $host or $host eq "" or $host =~ /\0/u
ref $host $host eq "" $host =~ /\0/u
Truth table75%3/4
A or B or C
A= ref $hostB= $host eq ""C= $host =~ /\0/u
ABCresult
1XX1
01X1
0011
0000
123 if ref($host) || $host eq '' || $host =~ /\0/;
124 1101 ▶ croak 'new(): port is required' if !defined $port;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port 0 1101 1101
125 1101 ▶ croak 'new(): port must be an integer'
Branch: 1 branch
BranchTrueFalseTotal
if ref $port or not $port =~ /\A\d+\z/u 0 1101 1101
Condition33%1/3
ref $port or not $port =~ /\A\d+\z/u
l!l&&r!l&&!r
001101
MC/DC0%0/2
ref $port or not $port =~ /\A\d+\z/u
ref $port not $port =~ /\A\d+\z/u
Truth table33%1/3
A or not(B)
A= ref $portB= not $port =~ /\A\d+\z/u
ABresult
1X1
011
000
126 if ref($port) || $port !~ /\A\d+\z/;
127 1101 $port = 0 + $port;
128 1101 ▶ croak 'new(): port must be between 0 and 65535'
Branch: 1 branch
BranchTrueFalseTotal
if $port < 0 or $port > 65535 1 1100 1101
Condition66%2/3
$port < 0 or $port > 65535
l!l&&r!l&&!r
011100
MC/DC50%1/2
$port < 0 or $port > 65535
$port < 0 $port > 65535
Truth table66%2/3
A or B
A= $port < 0B= $port > 65535
ABresult
1X1
011
000
129 if $port < 0 || $port > 65535;
130 croak 'new(): family is not allowed with host/port'
131 1100 ▶ if exists $opt{family};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"family"} 0 1100 1100
132 } elsif ($unix_mode) {
133 4 $unix = delete $opt{unix};
134 4 ▶ croak 'new(): unix must be a non-empty path without NUL bytes'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $unix or ref $unix or $unix eq "" or $unix =~ /\0/u 1 3 4
Condition44%4/9
not defined $unix or ref $unix or $unix eq "" or $unix =~ /\0/u
l!l&&r!l&&!r
013
not defined $unix or ref $unix or $unix eq ""
l!l&&r!l&&!r
004
not defined $unix or ref $unix
l!l&&r!l&&!r
004
MC/DC25%1/4
not defined $unix or ref $unix or $unix eq "" or $unix =~ /\0/u
not defined $unix ref $unix $unix eq "" $unix =~ /\0/u
Truth table40%2/5
not(A) or B or C or D
A= not defined $unixB= ref $unixC= $unix eq ""D= $unix =~ /\0/u
ABCDresult
1XXX1
01XX1
001X1
00011
00000
135 if !defined($unix) || ref($unix) || $unix eq '' || $unix =~ /\0/;
136 croak 'new(): family is not allowed with unix'
137 3 ▶ if exists $opt{family};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"family"} 0 3 3
138 3 ▶ croak 'new(): local_host, local_port, and bind_device are not valid '
Branch: 1 branch
BranchTrueFalseTotal
if $has_local_host or $has_local_port or defined $bind_device 0 3 3
Condition33%2/6
$has_local_host or $has_local_port or defined $bind_device
l!l&&r!l&&!r
003
$has_local_host or $has_local_port
l!l&&r!l&&!r
003
MC/DC0%0/3
$has_local_host or $has_local_port or defined $bind_device
$has_local_host $has_local_port defined $bind_device
Truth table25%1/4
A or B or C
A= $has_local_hostB= $has_local_portC= defined $bind_device
ABCresult
1XX1
01X1
0011
0000
139 . 'for Unix connections'
140 if $has_local_host || $has_local_port || defined $bind_device;
141 } else {
142 5 $sockaddr = delete $opt{sockaddr};
143 5 $family = delete $opt{family};
144 5 ▶ croak 'new(): sockaddr must be a defined scalar'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $sockaddr or ref $sockaddr 0 5 5
Condition33%1/3
not defined $sockaddr or ref $sockaddr
l!l&&r!l&&!r
005
MC/DC0%0/2
not defined $sockaddr or ref $sockaddr
not defined $sockaddr ref $sockaddr
Truth table33%1/3
not(A) or B
A= not defined $sockaddrB= ref $sockaddr
ABresult
1X1
011
000
145 if !defined($sockaddr) || ref($sockaddr);
146 5 ▶ croak 'new(): family is required with sockaddr'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $family 0 5 5
147 if !defined $family;
148 5 ▶ croak 'new(): family must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
if ref $family or not $family =~ /\A\d+\z/u 0 5 5
Condition33%1/3
ref $family or not $family =~ /\A\d+\z/u
l!l&&r!l&&!r
005
MC/DC0%0/2
ref $family or not $family =~ /\A\d+\z/u
ref $family not $family =~ /\A\d+\z/u
Truth table33%1/3
A or not(B)
A= ref $familyB= not $family =~ /\A\d+\z/u
ABresult
1X1
011
000
149 if ref($family) || $family !~ /\A\d+\z/;
150 5 $family = 0 + $family;
151 5 ▶ croak 'new(): local_host, local_port, and bind_device require an '
Branch: 1 branch
BranchTrueFalseTotal
if $has_local_host || $has_local_port || defined $bind_device and $family != 2 and $family != 10 1 4 5
Condition66%8/12
$has_local_host || $has_local_port || defined $bind_device and $family != 2 and $family != 10
!ll&&!rl&&r
401
$has_local_host || $has_local_port || defined $bind_device and $family != 2
!ll&&!rl&&r
401
$has_local_host or $has_local_port or defined $bind_device
l!l&&r!l&&!r
104
$has_local_host or $has_local_port
l!l&&r!l&&!r
014
MC/DC20%1/5
$has_local_host || $has_local_port || defined $bind_device and $family != 2 and $family != 10
$has_local_host $has_local_port defined $bind_device $family != 2 $family != 10
Truth table20%2/10
A or B or C and D and E
A= $has_local_hostB= $has_local_portC= defined $bind_deviceD= $family != 2E= $family != 10
ABCDEresult
000XX0
1XX0X0
01X0X0
0010X0
1XX100
01X100
001100
1XX111
01X111
001111
152 . 'IPv4 or IPv6 sockaddr'
153 if ($has_local_host || $has_local_port || defined $bind_device)
154 && $family != AF_INET && $family != AF_INET6;
155 }
156 1107 ▶ croak 'new(): unknown options: ' . join(', ', sort keys %opt) if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 1 1106 1107
157  
158 1106 ▶ my $self = bless {
Branch: 1 branch
BranchTrueFalseTotal
$has_local_host || $has_local_port ? : 4 1102 1106
Condition100%3/3
$has_local_host or $has_local_port
l!l&&r!l&&!r
221102
MC/DC100%2/2
$has_local_host or $has_local_port
$has_local_host $has_local_port
Truth table100%3/3
A or B
A= $has_local_hostB= $has_local_port
ABresult
1X1
011
000
159 loop => undef,
160 stream => $stream,
161 timeout => $timeout,
162 host => $host,
163 port => $port,
164 unix => $unix,
165 sockaddr => $sockaddr,
166 family => $family,
167 state => 'detached',
168 error => undef,
169 candidates => [],
170 candidate_at => 0,
171 attempts => {},
172 attempt_count => 0,
173 next_attempt => 1,
174 last_errno => undef,
175 last_operation => undef,
176 socket_policy => $socket_policy,
177 bind_device => $bind_device,
178 local_host => $local_host,
179 local_port => 0 + $local_port,
180 local_bind => ($has_local_host || $has_local_port) ? 1 : 0,
181 local_family => $local_family,
182 local_packed => $local_packed,
183 compatible_candidate_seen => 0,
184 timer_fd => undef,
185 timer_watcher => undef,
186 pending_result => undef,
187 deadline_at => undef,
188 fallback_at => undef,
189 resolver => undef,
190 resolver_request => undef,
191 needs_resolution => 0,
192 }, $class;
193  
194 1106 $self->_resolve_candidates;
195 1106 ▶ $self->_attach_to_loop($loop) if $loop;
Branch: 1 branch
BranchTrueFalseTotal
if $loop 0 1106 1106
196 1106 return $self;
197 }
198  
199 0 ▶sub loop ($self) { $self->{loop} }
Subroutine loop: not called CC=1 SCAR=6.9
Pod undocumented
200 0 ▶sub host ($self) { $self->{host} }
Subroutine host: not called CC=1 SCAR=6.9
Pod undocumented
201 0 ▶sub port ($self) { $self->{port} }
Subroutine port: not called CC=1 SCAR=6.9
Pod undocumented
202 0 ▶sub path ($self) { $self->{unix} }
Subroutine path: not called CC=1 SCAR=6.9
Pod undocumented
203 0 ▶sub family ($self) { $self->{family} }
Subroutine family: not called CC=1 SCAR=6.9
Pod undocumented
204 0 ▶sub timeout ($self) { $self->{timeout} }
Subroutine timeout: not called CC=1 SCAR=6.9
Pod undocumented
205 0 ▶sub state ($self) { $self->{state} }
Subroutine state: not called CC=1 SCAR=6.9
Pod undocumented
206 0 ▶sub error ($self) { $self->{error} }
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
207 0 ▶sub attempts ($self) { $self->{attempt_count} }
Subroutine attempts: not called CC=1 SCAR=6.9
Pod undocumented
208 0 ▶sub is_pending ($self) { $self->{state} eq 'pending' }
Subroutine is_pending: not called CC=1 SCAR=6.9
Pod undocumented
209 5 ▶sub is_done ($self) {
Subroutine is_done: called CC=3 SCAR=15.4
Pod undocumented
210 return $self->{state} eq 'connected' || $self->{state} eq 'failed'
211 5 ▶ || $self->{state} eq 'cancelled';
Condition33%2/6
$self->{'state'} eq 'connected' || $self->{'state'} eq 'failed' || $self->{'state'} eq 'cancelled'
l!l&&r!l&&!r
005
$self->{"state"} eq "connected" or $self->{"state"} eq "failed"
l!l&&r!l&&!r
005
MC/DC0%0/3
$self->{'state'} eq 'connected' || $self->{'state'} eq 'failed' || $self->{'state'} eq 'cancelled'
$self->{"state"} eq "connected" $self->{"state"} eq "failed" $self->{'state'} eq 'cancelled'
Truth table25%1/4
A or B || C
A= $self->{"state"} eq "connected"B= $self->{"state"} eq "failed"C= $self->{'state'} eq 'cancelled'
ABCresult
1XX1
01X1
0011
0000
212 }
213 0 ▶sub is_terminal ($self) { $self->is_done }
Subroutine is_terminal: not called CC=1 SCAR=6.9
Pod undocumented
214  
215 1102 ▶sub _attach_to_loop ($self, $loop) {
Subroutine _attach_to_loop: called CC=9 SCAR=33.0
216 croak 'add(): Stream connection is not detached'
217 1102 ▶ if $self->{state} ne 'detached' || $self->{loop};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "detached" or $self->{"loop"} 0 1102 1102
Condition33%1/3
$self->{"state"} ne "detached" or $self->{"loop"}
l!l&&r!l&&!r
001102
MC/DC0%0/2
$self->{"state"} ne "detached" or $self->{"loop"}
$self->{"state"} ne "detached" $self->{"loop"}
Truth table33%1/3
A or B
A= $self->{"state"} ne "detached"B= $self->{"loop"}
ABresult
1X1
011
000
218 1102 $self->{loop} = $loop;
219 1102 $self->{state} = 'pending';
220 1102 my $attached = eval {
221 $self->{deadline_at} = _now() + $self->{timeout}
222 1102 ▶ if $self->{timeout} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"timeout"} > 0 1102 0 1102
223 1102 ▶ $self->_rearm_timer if defined $self->{deadline_at};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"deadline_at"} 1102 0 1102
224 1102 ▶ if ($self->{pending_result}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'pending_result'}) { } 0 1102 1102
elsif ($self->{'needs_resolution'}) { } 2 1100 1102
225 0 $self->_rearm_timer;
226 } elsif ($self->{needs_resolution}) {
227 2 $self->_start_resolution;
228 } else {
229 1100 $self->_attempt_next;
230 }
231 1102 1;
232 };
233 1102 ▶ if (!$attached) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attached) 0 1102 1102
234 0 ▶ my $failure = $@ || 'connection attachment failed';
Condition0%0/2
$@ || 'connection attachment failed'
l!l
00
MC/DC0%0/1
$@ || 'connection attachment failed'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
235 0 eval { $self->_cancel_resolution; 1 };
236 0 eval { $self->_close_attempts; 1 };
237 0 eval { $self->_close_timer; 1 };
238 0 $self->{loop} = undef;
239 0 $self->{state} = 'detached';
240 0 $self->{pending_result} = undef;
241 0 $self->{deadline_at} = undef;
242 0 $self->{fallback_at} = undef;
243 0 $self->{candidate_at} = 0;
244 0 $self->{attempt_count} = 0;
245 0 $self->{last_errno} = undef;
246 0 $self->{last_operation} = undef;
247 0 $self->{compatible_candidate_seen} = 0;
248 0 die $failure;
249 }
250 1102 return $self;
251 }
252  
253 5 ▶sub cancel ($self) {
Subroutine cancel: called CC=2 SCAR=7.0
Pod undocumented
254 5 ▶ return 0 if $self->is_done;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_done 0 5 5
255 5 $self->{state} = 'cancelled';
256 5 $self->{pending_result} = undef;
257 5 $self->_cancel_resolution;
258 5 $self->_close_attempts;
259 5 $self->_close_timer;
260 5 return 1;
261 }
262  
263 1106 ▶sub _resolve_candidates ($self) {
Subroutine _resolve_candidates: called CC=8 SCAR=21.9
264 1106 ▶ if (defined $self->{unix}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"unix"}) 2 1104 1106
265 2 push @{ $self->{candidates} }, {
266 family => AF_UNIX,
267 protocol => 0,
268 2 sockaddr => pack_sockaddr_un($self->{unix}),
269 };
270 2 return;
271 }
272 1104 ▶ if (defined $self->{sockaddr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"sockaddr"}) 4 1100 1104
273 4 push @{ $self->{candidates} }, {
274 family => $self->{family},
275 protocol => 0,
276 sockaddr => $self->{sockaddr},
277 4 };
278 4 return;
279 }
280  
281 1100 my $literal = $self->{host};
282 1100 $literal =~ s/\A[ \t\r\n]+//;
283 1100 $literal =~ s/[ \t\r\n]+\z//;
284 1100 ▶ if (length($literal) >= 2 && substr($literal, 0, 1) eq '['
Branch: 1 branch
BranchTrueFalseTotal
if (length $literal >= 2 and substr($literal, 0, 1) eq "[" and substr($literal, -1, 1) eq "]") 0 1100 1100
Condition33%2/6
length $literal >= 2 and substr($literal, 0, 1) eq "[" and substr($literal, -1, 1) eq "]"
!ll&&!rl&&r
110000
length $literal >= 2 and substr($literal, 0, 1) eq "["
!ll&&!rl&&r
011000
MC/DC0%0/3
length $literal >= 2 and substr($literal, 0, 1) eq "[" and substr($literal, -1, 1) eq "]"
length $literal >= 2 substr($literal, 0, 1) eq "[" substr($literal, -1, 1) eq "]"
Truth table25%1/4
A and B and C
A= length $literal >= 2B= substr($literal, 0, 1) eq "["C= substr($literal, -1, 1) eq "]"
ABCresult
0XX0
10X0
1100
1111
285 && substr($literal, -1, 1) eq ']') {
286 0 $literal = substr($literal, 1, length($literal) - 2);
287 }
288  
289 1100 my $packed4 = inet_pton(AF_INET, $literal);
290 1100 ▶ if (defined $packed4) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packed4) 1097 3 1100
291 1097 push @{ $self->{candidates} }, {
292 family => AF_INET,
293 protocol => 0,
294 1097 sockaddr => pack_sockaddr_in($self->{port}, $packed4),
295 };
296 1097 return;
297 }
298 3 my $packed6 = inet_pton(AF_INET6, $literal);
299 3 ▶ if (defined $packed6) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packed6) 0 3 3
300 0 push @{ $self->{candidates} }, {
301 family => AF_INET6,
302 protocol => 0,
303 0 sockaddr => pack_sockaddr_in6($self->{port}, $packed6),
304 };
305 0 return;
306 }
307  
308 3 $self->{needs_resolution} = 1;
309 3 return;
310 }
311  
312 3309 ▶sub _now () { clock_gettime(CLOCK_MONOTONIC) }
Subroutine _now: called CC=1 SCAR=0.0
313  
314 2 ▶sub _start_resolution ($self) {
Subroutine _start_resolution: called CC=5 SCAR=19.4
315 2 ▶ return if $self->{state} ne 'pending' || $self->{resolver_request};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "pending" or $self->{"resolver_request"} 0 2 2
Condition33%1/3
$self->{"state"} ne "pending" or $self->{"resolver_request"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$self->{"state"} ne "pending" or $self->{"resolver_request"}
$self->{"state"} ne "pending" $self->{"resolver_request"}
Truth table33%1/3
A or B
A= $self->{"state"} ne "pending"B= $self->{"resolver_request"}
ABresult
1X1
011
000
316 2 my $resolver = Linux::Event::_Resolver->for_loop($self->{loop});
317 2 $self->{resolver} = $resolver;
318 2 my $id = eval { $resolver->submit($self, $self->{host}, $self->{port}) };
319 2 ▶ if (!$id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 0 2 2
320 0 ▶ my $message = $@ || 'could not submit hostname resolution';
Condition0%0/2
$@ || 'could not submit hostname resolution'
l!l
00
MC/DC0%0/1
$@ || 'could not submit hostname resolution'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
321 0 $self->_queue_error($self->_error(
322 type => 'resolve',
323 operation => 'resolve',
324 errno => Errno::EIO(),
325 message => $message,
326 resolver_message => $message,
327 ));
328 0 return;
329 }
330 2 $self->{resolver_request} = $id;
331 2 $self->_rearm_timer;
332 2 return;
333 }
334  
335 1106 ▶sub _cancel_resolution ($self) {
Subroutine _cancel_resolution: called CC=3 SCAR=12.0
336 1106 my $id = delete $self->{resolver_request};
337 1106 my $resolver = delete $self->{resolver};
338 1106 ▶ $resolver->cancel($id) if $resolver && defined $id;
Branch: 1 branch
BranchTrueFalseTotal
if $resolver and defined $id 0 1106 1106
Condition33%1/3
$resolver and defined $id
!ll&&!rl&&r
110600
MC/DC0%0/2
$resolver and defined $id
$resolver defined $id
Truth table33%1/3
A and B
A= $resolverB= defined $id
ABresult
0X0
100
111
339 1106 return;
340 }
341  
342 2 ▶sub _resolver_completed ($self, $result) {
Subroutine _resolver_completed: called CC=8 SCAR=27.7
343 2 ▶ return if $self->{state} ne 'pending';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "pending" 0 2 2
344 return if !defined($self->{resolver_request})
345 2 ▶ || $result->{id} != $self->{resolver_request};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $self->{"resolver_request"} or $result->{"id"} != $self->{"resolver_request"} 0 2 2
Condition33%1/3
not defined $self->{"resolver_request"} or $result->{"id"} != $self->{"resolver_request"}
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $self->{"resolver_request"} or $result->{"id"} != $self->{"resolver_request"}
not defined $self->{"resolver_request"} $result->{"id"} != $self->{"resolver_request"}
Truth table33%1/3
not(A) or B
A= not defined $self->{"resolver_request"}B= $result->{"id"} != $self->{"resolver_request"}
ABresult
1X1
011
000
346 2 delete $self->{resolver_request};
347 2 delete $self->{resolver};
348  
349 2 ▶ if ($result->{error_code}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"error_code"}) 0 2 2
350 0 ▶ my $message = $result->{message} || 'hostname resolution failed';
Condition0%0/2
$result->{'message'} || 'hostname resolution failed'
l!l
00
MC/DC0%0/1
$result->{'message'} || 'hostname resolution failed'
$result->{'message'}
Truth table0%0/2
A
A= $result->{'message'}
Aresult
11
00
351 0 ▶ my $errno = $result->{system_errno} || Errno::ENOENT();
Condition0%0/2
$result->{'system_errno'} || 2
l!l
00
MC/DC0%0/1
$result->{'system_errno'} || 2
$result->{'system_errno'}
Truth table0%0/2
A
A= $result->{'system_errno'}
Aresult
11
00
352 0 $self->_queue_error($self->_error(
353 type => 'resolve',
354 operation => 'resolve',
355 errno => $errno,
356 message => $message,
357 resolver_message => $message,
358 ));
359 0 return;
360 }
361  
362 2 $self->{candidates} = _happy_eyeballs_order($result->{candidates});
363 2 ▶ if (!@{ $self->{candidates} }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"candidates"};}) 0 2 2
364 0 $self->_queue_error($self->_error(
365 type => 'resolve',
366 operation => 'resolve',
367 errno => Errno::ENOENT(),
368 message => 'hostname resolution returned no stream addresses',
369 ));
370 0 return;
371 }
372 2 $self->{candidate_at} = 0;
373 2 $self->_attempt_next;
374 2 return;
375 }
376  
377 3 ▶sub _happy_eyeballs_order ($input) {
Subroutine _happy_eyeballs_order: called CC=15 SCAR=33.8
378 3 my (@v4, @v6, @other);
379 3 for my $candidate (@$input) {
380 next if !defined($candidate->{family})
381 8 ▶ || !defined($candidate->{sockaddr});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $candidate->{"family"} and defined $candidate->{"sockaddr"} 0 8 8
Condition33%1/3
defined $candidate->{"family"} and defined $candidate->{"sockaddr"}
!ll&&!rl&&r
008
MC/DC0%0/2
defined $candidate->{"family"} and defined $candidate->{"sockaddr"}
defined $candidate->{"family"} defined $candidate->{"sockaddr"}
Truth table33%1/3
A and B
A= defined $candidate->{"family"}B= defined $candidate->{"sockaddr"}
ABresult
0X0
100
111
382 8 ▶ if ($candidate->{family} == AF_INET) {
Branch: 2 branches
BranchTrueFalseTotal
if ($candidate->{'family'} == 2) { } 4 4 8
elsif ($candidate->{'family'} == 10) { } 4 0 4
383 4 push @v4, $candidate;
384 } elsif ($candidate->{family} == AF_INET6) {
385 4 push @v6, $candidate;
386 } else {
387 0 push @other, $candidate;
388 }
389 }
390 3 ▶ my $first_family = @$input && $input->[0]{family} == AF_INET
Branch: 1 branch
BranchTrueFalseTotal
@$input && $input->[0]{'family'} == 2 ? : 0 3 3
Condition33%1/3
@$input and $input->[0]{"family"} == 2
!ll&&!rl&&r
030
MC/DC0%0/2
@$input and $input->[0]{"family"} == 2
@$input $input->[0]{"family"} == 2
Truth table33%1/3
A and B
A= @$inputB= $input->[0]{"family"} == 2
ABresult
0X0
100
111
391 ? AF_INET : AF_INET6;
392 3 my @ordered;
393 3 ▶ while (@v4 || @v6) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v4 or @v6) 4 3 7
Condition66%2/3
@v4 or @v6
l!l&&r!l&&!r
403
MC/DC50%1/2
@v4 or @v6
@v4 @v6
Truth table66%2/3
A or B
A= @v4B= @v6
ABresult
1X1
011
000
394 4 ▶ if ($first_family == AF_INET) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_family == 2) { } 0 4 4
395 0 ▶ push @ordered, shift @v4 if @v4;
Branch: 1 branch
BranchTrueFalseTotal
if @v4 0 0 0
396 0 ▶ push @ordered, shift @v6 if @v6;
Branch: 1 branch
BranchTrueFalseTotal
if @v6 0 0 0
397 } else {
398 4 ▶ push @ordered, shift @v6 if @v6;
Branch: 1 branch
BranchTrueFalseTotal
if @v6 4 0 4
399 4 ▶ push @ordered, shift @v4 if @v4;
Branch: 1 branch
BranchTrueFalseTotal
if @v4 4 0 4
400 }
401 }
402 3 return [ @ordered, @other ];
403 }
404  
405 1103 ▶sub _attempt_next ($self) {
Subroutine _attempt_next: called CC=31 SCAR=38.3
406 1103 ▶ return if $self->{state} ne 'pending' || $self->{pending_result};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "pending" or $self->{"pending_result"} 0 1103 1103
Condition33%1/3
$self->{"state"} ne "pending" or $self->{"pending_result"}
l!l&&r!l&&!r
001103
MC/DC0%0/2
$self->{"state"} ne "pending" or $self->{"pending_result"}
$self->{"state"} ne "pending" $self->{"pending_result"}
Truth table33%1/3
A or B
A= $self->{"state"} ne "pending"B= $self->{"pending_result"}
ABresult
1X1
011
000
407  
408 1103 ▶ while ($self->{candidate_at} < @{ $self->{candidates} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"candidate_at"} < @{$self->{"candidates"};}) 1103 4 1107
409 1103 my $candidate = $self->{candidates}[ $self->{candidate_at}++ ];
410 next if defined($self->{local_family})
411 1103 ▶ && $candidate->{family} != $self->{local_family};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"local_family"} and $candidate->{"family"} != $self->{"local_family"} 1 1102 1103
Condition100%3/3
defined $self->{"local_family"} and $candidate->{"family"} != $self->{"local_family"}
!ll&&!rl&&r
110111
MC/DC100%2/2
defined $self->{"local_family"} and $candidate->{"family"} != $self->{"local_family"}
defined $self->{"local_family"} $candidate->{"family"} != $self->{"local_family"}
Truth table100%3/3
A and B
A= defined $self->{"local_family"}B= $candidate->{"family"} != $self->{"local_family"}
ABresult
0X0
100
111
412 1102 $self->{compatible_candidate_seen} = 1;
413 1102 my $fh;
414 1102 $self->{attempt_count}++;
415 1102 ▶ if (!socket(
Branch: 1 branch
BranchTrueFalseTotal
unless (socket $fh, $candidate->{"family"}, 526337, $candidate->{"protocol"}) 3 1099 1102
416 $fh,
417 $candidate->{family},
418 SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
419 $candidate->{protocol},
420 )) {
421 3 $self->{last_errno} = 0 + $!;
422 3 $self->{last_operation} = 'socket';
423 3 next;
424 }
425  
426 1099 my $configured = eval {
427 Linux::Event::_SocketConfig::apply_policy(
428 $fh, $candidate->{family}, $self->{socket_policy},
429 1099 );
430 Linux::Event::_SocketConfig::bind_device(
431 $fh, $self->{bind_device},
432 1099 ▶ ) if defined $self->{bind_device};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"bind_device"} 0 1099 1099
433 $self->{stream}->_configure_socket(
434 $fh, 'connect',
435 1099 Linux::Event::Address->new($candidate->{sockaddr}),
436 );
437 1099 ▶ if ($self->{local_bind}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"local_bind"}) 2 1097 1099
438 my $packed = defined($self->{local_family})
439 ? $self->{local_packed}
440 2 ▶ : $candidate->{family} == AF_INET
Branch: 2 branches
BranchTrueFalseTotal
defined $self->{'local_family'} ? : 1 1 2
$candidate->{'family'} == 2 ? : 1 0 1
441 ? inet_pton(AF_INET, '0.0.0.0')
442 : inet_pton(AF_INET6, '::');
443 my $sockaddr = $candidate->{family} == AF_INET
444 ? pack_sockaddr_in($self->{local_port}, $packed)
445 2 ▶ : pack_sockaddr_in6($self->{local_port}, $packed);
Branch: 1 branch
BranchTrueFalseTotal
$candidate->{'family'} == 2 ? : 2 0 2
446 2 ▶ if (!bind($fh, $sockaddr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (bind $fh, $sockaddr) 1 1 2
447 1 my $errno = 0 + $!;
448 1 local $! = $errno;
449 die Linux::Event::Error->new(
450 type => 'socket_configuration',
451 operation => 'bind',
452 option => defined($self->{local_host})
453 ? 'local_host' : 'local_port',
454 errno => $errno,
455 message => "$!",
456 host => $self->{local_host},
457 port => $self->{local_port},
458 1 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'local_host'} ? : 0 1 1
459 }
460 }
461 1098 1;
462 };
463 1099 ▶ if (!$configured) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($configured) 1 1098 1099
464 1 my $failure = $@;
465 1 close $fh;
466 1 ▶ my $error = blessed($failure)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($failure) && $failure->isa('Linux::Event::Error') ? : 1 0 1
Condition20%1/5
builtin::blessed($failure) and $failure->isa("Linux::Event::Error")
!ll&&!rl&&r
001
"$failure" || 'socket configuration failed'
l!l
00
MC/DC0%0/2
builtin::blessed($failure) and $failure->isa("Linux::Event::Error")
builtin::blessed($failure) $failure->isa("Linux::Event::Error")
MC/DC0%0/1
"$failure" || 'socket configuration failed'
"$failure"
Truth table33%1/3
A and B
A= builtin::blessed($failure)B= $failure->isa("Linux::Event::Error")
ABresult
0X0
100
111
Truth table0%0/2
A
A= "$failure"
Aresult
11
00
467 && $failure->isa('Linux::Event::Error')
468 ? $failure
469 : Linux::Event::Error->new(
470 type => 'socket_configuration',
471 operation => 'configure_socket',
472 message => "$failure" || 'socket configuration failed',
473 );
474 1 $self->_queue_error($error);
475 1 return;
476 }
477  
478 1098 my $id = $self->{next_attempt}++;
479 1098 my $attempt = {
480 request => $self,
481 id => $id,
482 fh => $fh,
483 watcher => undef,
484 };
485 1098 $self->{attempts}{$id} = $attempt;
486  
487 1098 ▶ if (connect($fh, $candidate->{sockaddr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (connect $fh, $candidate->{"sockaddr"}) 2 1096 1098
488 2 $self->_queue_success($attempt);
489 2 return;
490 }
491  
492 1096 my $errno = 0 + $!;
493 1096 ▶ if ($errno == Errno::EINPROGRESS()
Branch: 1 branch
BranchTrueFalseTotal
if ($errno == 115 or $errno == 114 or $errno == 11) 1096 0 1096
Condition33%2/6
$errno == 115 or $errno == 114 or $errno == 11
l!l&&r!l&&!r
109600
$errno == 115 or $errno == 114
l!l&&r!l&&!r
109600
MC/DC0%0/3
$errno == 115 or $errno == 114 or $errno == 11
$errno == 115 $errno == 114 $errno == 11
Truth table25%1/4
A or B or C
A= $errno == 115B= $errno == 114C= $errno == 11
ABCresult
1XX1
01X1
0011
0000
494 || $errno == Errno::EALREADY()
495 || $errno == Errno::EWOULDBLOCK()) {
496 1096 my $watcher = eval {
497 $self->{loop}->watch_fd(
498 1096 fileno($fh),
499 _internal => 1,
500 fh => $fh,
501 data => $attempt,
502 write => \&_attempt_ready,
503 error => \&_attempt_ready,
504 _callback_data_arg => 1,
505 );
506 };
507 1096 ▶ if (!$watcher) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($watcher) 0 1096 1096
508 0 ▶ my $message = "$@" || 'could not register connection socket';
Condition0%0/2
"$@" || 'could not register connection socket'
l!l
00
MC/DC0%0/1
"$@" || 'could not register connection socket'
"$@"
Truth table0%0/2
A
A= "$@"
Aresult
11
00
509 0 $self->_close_attempt($attempt);
510 0 $self->_queue_error($self->_error(
511 type => 'setup', operation => 'watch',
512 message => $message,
513 ));
514 0 return;
515 }
516 1096 $attempt->{watcher} = $watcher;
517 $self->{fallback_at} = _now() + 0.250
518 1096 ▶ if $self->{candidate_at} < @{ $self->{candidates} };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"candidate_at"} < @{$self->{"candidates"};} 2 1094 1096
519 1096 $self->_rearm_timer;
520 1096 return;
521 }
522  
523 0 $self->{last_errno} = $errno;
524 0 $self->{last_operation} = 'connect';
525 0 delete $self->{attempts}{$id};
526 0 close $fh;
527 }
528  
529 4 $self->{fallback_at} = undef;
530 4 $self->_rearm_timer;
531 4 ▶ return if keys %{ $self->{attempts} };
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"attempts"};} 0 4 4
532  
533 4 ▶ if (defined($self->{local_family})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"local_family"} and not $self->{"compatible_candidate_seen"}) 1 3 4
Condition66%2/3
defined $self->{"local_family"} and not $self->{"compatible_candidate_seen"}
!ll&&!rl&&r
301
MC/DC50%1/2
defined $self->{"local_family"} and not $self->{"compatible_candidate_seen"}
defined $self->{"local_family"} not $self->{"compatible_candidate_seen"}
Truth table66%2/3
A and not(B)
A= defined $self->{"local_family"}B= not $self->{"compatible_candidate_seen"}
ABresult
0X0
100
111
534 && !$self->{compatible_candidate_seen}) {
535 1 $self->_queue_error($self->_error(
536 type => 'socket_configuration',
537 operation => 'bind',
538 option => 'local_host',
539 message => 'local_host address family does not match any peer address',
540 ));
541 1 return;
542 }
543  
544 3 ▶ my $errno = $self->{last_errno} // Errno::EIO();
Condition50%1/2
$self->{"last_errno"} // 5
l!l
30
MC/DC0%0/1
$self->{"last_errno"} // 5
$self->{"last_errno"}
Truth table50%1/2
A
A= $self->{"last_errno"}
Aresult
11
00
545 3 ▶ my $operation = $self->{last_operation} // 'connect';
Condition50%1/2
$self->{"last_operation"} // "connect"
l!l
30
MC/DC0%0/1
$self->{"last_operation"} // "connect"
$self->{"last_operation"}
Truth table50%1/2
A
A= $self->{"last_operation"}
Aresult
11
00
546 3 ▶ my $type = $operation eq 'socket' ? 'socket' : 'connect';
Branch: 1 branch
BranchTrueFalseTotal
$operation eq 'socket' ? : 3 0 3
547 3 $self->_queue_error($self->_error(
548 type => $type,
549 operation => $operation,
550 errno => $errno,
551 message => _system_message($errno),
552 ));
553 3 return;
554 }
555  
556 1096 ▶sub _attempt_ready ($attempt) {
Subroutine _attempt_ready: called CC=7 SCAR=20.7
557 1096 my $self = $attempt->{request};
558 1096 ▶ return if !$self || $self->{state} ne 'pending';
Branch: 1 branch
BranchTrueFalseTotal
if not $self or $self->{"state"} ne "pending" 0 1096 1096
Condition33%1/3
not $self or $self->{"state"} ne "pending"
l!l&&r!l&&!r
001096
MC/DC0%0/2
not $self or $self->{"state"} ne "pending"
not $self $self->{"state"} ne "pending"
Truth table33%1/3
not(A) or B
A= not $selfB= $self->{"state"} ne "pending"
ABresult
1X1
011
000
559 1096 ▶ return if !exists $self->{attempts}{ $attempt->{id} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"attempts"}{$attempt->{"id"}} 0 1096 1096
560  
561 1096 my $raw = getsockopt($attempt->{fh}, SOL_SOCKET, SO_ERROR);
562 1096 my $errno;
563 1096 ▶ if (!defined $raw) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $raw) { } 0 1096 1096
elsif (length $raw < 4) { } 0 1096 1096
564 0 $errno = 0 + $!;
565 } elsif (length($raw) < 4) {
566 0 $errno = Errno::EIO();
567 } else {
568 1096 $errno = unpack('i', $raw);
569 }
570  
571 1096 ▶ if ($errno == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errno == 0) 1094 2 1096
572 1094 $self->_finish_success($attempt);
573 1094 return;
574 }
575 2 $self->{last_errno} = $errno;
576 2 $self->{last_operation} = 'connect';
577 2 $self->_close_attempt($attempt);
578 2 $self->_attempt_next;
579 2 return;
580 }
581  
582 2211 ▶sub _ensure_timer ($self) {
Subroutine _ensure_timer: called CC=4 SCAR=15.5
583 2211 ▶ return $self->{timer_fd} if defined $self->{timer_fd};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"timer_fd"} 1109 1102 2211
584 1102 my $fd = __PACKAGE__->_timerfd_new;
585 1102 my $watcher = eval {
586 $self->{loop}->watch(
587 1102 fd => $fd,
588 _internal => 1,
589 data => $self,
590 read => \&_timer_ready,
591 _callback_data_arg => 1,
592 );
593 };
594 1102 ▶ if (!$watcher) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($watcher) 0 1102 1102
595 0 ▶ my $failure = $@ || 'could not register connection timer';
Condition0%0/2
$@ || 'could not register connection timer'
l!l
00
MC/DC0%0/1
$@ || 'could not register connection timer'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
596 0 __PACKAGE__->_timerfd_close($fd);
597 0 die $failure;
598 }
599 1102 $self->{timer_fd} = $fd;
600 1102 $self->{timer_watcher} = $watcher;
601 1102 return $fd;
602 }
603  
604 2211 ▶sub _rearm_timer ($self) {
Subroutine _rearm_timer: called CC=10 SCAR=25.5
605 2211 ▶ return if !$self->{loop} || $self->{state} ne 'pending';
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"loop"} or $self->{"state"} ne "pending" 0 2211 2211
Condition33%1/3
not $self->{"loop"} or $self->{"state"} ne "pending"
l!l&&r!l&&!r
002211
MC/DC0%0/2
not $self->{"loop"} or $self->{"state"} ne "pending"
not $self->{"loop"} $self->{"state"} ne "pending"
Truth table33%1/3
not(A) or B
A= not $self->{"loop"}B= $self->{"state"} ne "pending"
ABresult
1X1
011
000
606 2211 my $delay;
607 2211 ▶ if ($self->{pending_result}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'pending_result'}) { } 7 2204 2211
608 7 $delay = 0.000000001;
609 } else {
610 2204 my @when = grep { defined } $self->{deadline_at}, $self->{fallback_at};
611 2204 ▶ if (@when) {
Branch: 1 branch
BranchTrueFalseTotal
if (@when) 2204 0 2204
612 2204 my $next = $when[0];
613 2204 for my $when (@when[1 .. $#when]) {
614 4 ▶ $next = $when if $when < $next;
Branch: 1 branch
BranchTrueFalseTotal
if $when < $next 4 0 4
615 }
616 2204 $delay = $next - _now();
617 2204 ▶ $delay = 0.000000001 if $delay <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $delay <= 0 0 2204 2204
618 }
619 }
620 2211 ▶ if (defined $delay) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $delay) { } 2211 0 2211
elsif (defined $self->{'timer_fd'}) { } 0 0 0
621 2211 __PACKAGE__->_timerfd_arm($self->_ensure_timer, $delay);
622 } elsif (defined $self->{timer_fd}) {
623 0 __PACKAGE__->_timerfd_arm($self->{timer_fd}, 0);
624 }
625 2211 return;
626 }
627  
628 2 ▶sub _queue_success ($self, $attempt) {
Subroutine _queue_success: called CC=5 SCAR=18.9
629 return if ($self->{state} ne 'pending' && $self->{state} ne 'detached')
630 2 ▶ || $self->{pending_result};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "pending" and $self->{"state"} ne "detached" or $self->{"pending_result"} 0 2 2
Condition33%2/6
$self->{"state"} ne "pending" and $self->{"state"} ne "detached" or $self->{"pending_result"}
l!l&&r!l&&!r
002
$self->{"state"} ne "pending" and $self->{"state"} ne "detached"
!ll&&!rl&&r
200
MC/DC0%0/3
$self->{"state"} ne "pending" and $self->{"state"} ne "detached" or $self->{"pending_result"}
$self->{"state"} ne "pending" $self->{"state"} ne "detached" $self->{"pending_result"}
Truth table20%1/5
A and B or C
A= $self->{"state"} ne "pending"B= $self->{"state"} ne "detached"C= $self->{"pending_result"}
ABCresult
11X1
0X11
1011
0X00
1000
631 2 $self->{pending_result} = [ success => $attempt ];
632 2 ▶ return if !$self->{loop};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"loop"} 0 2 2
633 2 $self->_rearm_timer;
634 2 return;
635 }
636  
637 5 ▶sub _queue_error ($self, $error) {
Subroutine _queue_error: called CC=5 SCAR=18.9
638 return if ($self->{state} ne 'pending' && $self->{state} ne 'detached')
639 5 ▶ || $self->{pending_result};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "pending" and $self->{"state"} ne "detached" or $self->{"pending_result"} 0 5 5
Condition33%2/6
$self->{"state"} ne "pending" and $self->{"state"} ne "detached" or $self->{"pending_result"}
l!l&&r!l&&!r
005
$self->{"state"} ne "pending" and $self->{"state"} ne "detached"
!ll&&!rl&&r
500
MC/DC0%0/3
$self->{"state"} ne "pending" and $self->{"state"} ne "detached" or $self->{"pending_result"}
$self->{"state"} ne "pending" $self->{"state"} ne "detached" $self->{"pending_result"}
Truth table20%1/5
A and B or C
A= $self->{"state"} ne "pending"B= $self->{"state"} ne "detached"C= $self->{"pending_result"}
ABCresult
11X1
0X11
1011
0X00
1000
640 5 $self->{pending_result} = [ error => $error ];
641 5 ▶ return if !$self->{loop};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"loop"} 0 5 5
642 5 $self->_rearm_timer;
643 5 return;
644 }
645  
646 7 ▶sub _timer_ready ($self) {
Subroutine _timer_ready: called CC=8 SCAR=26.0
647 7 ▶ return if $self->{state} ne 'pending';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "pending" 0 7 7
648 7 __PACKAGE__->_timerfd_consume($self->{timer_fd});
649 7 ▶ if (my $result = delete $self->{pending_result}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = delete $self->{"pending_result"}) 6 1 7
650 6 my ($kind, $value) = @$result;
651 6 ▶ if ($kind eq 'success') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'success') { } 1 5 6
652 1 $self->_finish_success($value);
653 } else {
654 5 $self->_finish_error($value);
655 }
656 5 return;
657 }
658  
659 1 my $now = _now();
660 1 ▶ if (defined($self->{deadline_at}) && $now >= $self->{deadline_at}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"deadline_at"} and $now >= $self->{"deadline_at"}) 1 0 1
Condition33%1/3
defined $self->{"deadline_at"} and $now >= $self->{"deadline_at"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $self->{"deadline_at"} and $now >= $self->{"deadline_at"}
defined $self->{"deadline_at"} $now >= $self->{"deadline_at"}
Truth table33%1/3
A and B
A= defined $self->{"deadline_at"}B= $now >= $self->{"deadline_at"}
ABresult
0X0
100
111
661 1 $self->_finish_error($self->_error(
662 type => 'timeout',
663 operation => 'connect',
664 errno => Errno::ETIMEDOUT(),
665 message => 'connection deadline expired',
666 ));
667 1 return;
668 }
669 0 ▶ if (defined($self->{fallback_at}) && $now >= $self->{fallback_at}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"fallback_at"} and $now >= $self->{"fallback_at"}) 0 0 0
Condition0%0/3
defined $self->{"fallback_at"} and $now >= $self->{"fallback_at"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"fallback_at"} and $now >= $self->{"fallback_at"}
defined $self->{"fallback_at"} $now >= $self->{"fallback_at"}
Truth table0%0/3
A and B
A= defined $self->{"fallback_at"}B= $now >= $self->{"fallback_at"}
ABresult
0X0
100
111
670 0 $self->{fallback_at} = undef;
671 0 $self->_attempt_next;
672 0 return;
673 }
674 0 $self->_rearm_timer;
675 0 return;
676 }
677  
678 3 ▶sub _close_attempt ($self, $attempt, $keep_fh = 0) {
Subroutine _close_attempt: called CC=6 SCAR=18.6
679 3 ▶ return if !$attempt;
Branch: 1 branch
BranchTrueFalseTotal
unless $attempt 0 3 3
680 3 delete $self->{attempts}{ $attempt->{id} };
681 3 ▶ if (my $watcher = delete $attempt->{watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $attempt->{"watcher"}) 2 1 3
682 2 $watcher->cancel;
683 }
684 3 my $fh = delete $attempt->{fh};
685 3 ▶ close $fh if $fh && !$keep_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $fh and not $keep_fh 3 0 3
Condition33%1/3
$fh and not $keep_fh
!ll&&!rl&&r
003
MC/DC0%0/2
$fh and not $keep_fh
$fh not $keep_fh
Truth table33%1/3
A and not(B)
A= $fhB= not $keep_fh
ABresult
0X0
100
111
686 3 $attempt->{request} = undef;
687 3 return $fh;
688 }
689  
690 1106 ▶sub _close_attempts ($self, $except = undef) {
Subroutine _close_attempts: called CC=5 SCAR=16.1
691 1106 for my $attempt (values %{ $self->{attempts} }) {
692 1096 ▶ next if $except && refaddr($attempt) == refaddr($except);
Branch: 1 branch
BranchTrueFalseTotal
if $except and builtin::refaddr($attempt) == builtin::refaddr($except) 1095 1 1096
Condition66%2/3
$except and builtin::refaddr($attempt) == builtin::refaddr($except)
!ll&&!rl&&r
101095
MC/DC50%1/2
$except and builtin::refaddr($attempt) == builtin::refaddr($except)
$except builtin::refaddr($attempt) == builtin::refaddr($except)
Truth table66%2/3
A and B
A= $exceptB= builtin::refaddr($attempt) == builtin::refaddr($except)
ABresult
0X0
100
111
693 1 $self->_close_attempt($attempt);
694 }
695 1106 return;
696 }
697  
698 1106 ▶sub _close_timer ($self) {
Subroutine _close_timer: called CC=3 SCAR=11.0
699 1106 ▶ if (my $watcher = delete $self->{timer_watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $self->{"timer_watcher"}) 1102 4 1106
700 1102 $watcher->cancel;
701 }
702 1106 ▶ if (defined(my $fd = delete $self->{timer_fd})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $fd = delete $self->{"timer_fd"})) 1102 4 1106
703 1102 __PACKAGE__->_timerfd_close($fd);
704 }
705 1106 return;
706 }
707  
708 1095 ▶sub _finish_success ($self, $attempt) {
Subroutine _finish_success: called CC=5 SCAR=16.2
709 1095 ▶ return if $self->{state} ne 'pending';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "pending" 0 1095 1095
710 1095 ▶ return if !exists $self->{attempts}{ $attempt->{id} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"attempts"}{$attempt->{"id"}} 0 1095 1095
711  
712 1095 $self->{state} = 'connected';
713 1095 $self->_cancel_resolution;
714 1095 $self->_close_attempts($attempt);
715 1095 $self->_close_timer;
716  
717 1095 my $watcher = delete $attempt->{watcher};
718 1095 my $fh = delete $attempt->{fh};
719 1095 delete $self->{attempts}{ $attempt->{id} };
720 1095 $attempt->{request} = undef;
721  
722 1095 my $stream = $self->{stream};
723 1095 my $ok = eval { $stream->_connect_succeeded($fh); 1 };
724 1095 my $callback_error = $@;
725  
726 # If the callback registered Stream or another watcher for this fd, the
727 # old handle is already inactive and cancel() is harmless. Otherwise this
728 # removes connection's now-unused writable registration.
729 1095 ▶ $watcher->cancel if $watcher;
Branch: 1 branch
BranchTrueFalseTotal
if $watcher 1094 1 1095
730 1095 ▶ die $callback_error if !$ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1095 1095
731 1095 return;
732 }
733  
734 6 ▶sub _finish_error ($self, $error) {
Subroutine _finish_error: called CC=2 SCAR=6.9
735 6 ▶ return if $self->{state} ne 'pending';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "pending" 0 6 6
736 6 $self->{state} = 'failed';
737 6 $self->{error} = $error;
738 6 $self->{pending_result} = undef;
739 6 $self->_cancel_resolution;
740 6 $self->_close_attempts;
741 6 $self->_close_timer;
742 6 $self->{stream}->_connect_failed($error);
743 5 return;
744 }
745  
746 120 1;
« blib/lib/Linux/Event/_Socket/Dgram.pm ↑ Summary blib/lib/Linux/Event/Loop.pm »