blib/lib/Linux/Event/Stream/_Connection.pm

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