blib/lib/Linux/Event/Datagram.pm

filter: Statementstmt 84.3% 570 / 676 Branchbran 57.4% 300 / 522 Conditioncond 37.1% 151 / 407 MC/DCmcdc 14.1% 33 / 233 Subroutinesub 92.1% 70 / 76 Podpod 91.6% 22 / 24 totaltotal 59.1% 1146 / 1938 CC 415 SCAR 60.7
CC
415
Cov
64%
_construct
1373.5
_create_bound_inet
100.1
_resolver_completed
96.9
CRAP 434.1
↑ Summary blib/lib/Linux/Event/Stream/_Connection.pm »
1 package Linux::Event::Datagram;
2 8 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 our $VERSION = '0.105';
7  
8 8 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Fcntl qw(F_GETFD F_GETFL F_SETFD F_SETFL FD_CLOEXEC O_NONBLOCK);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Socket qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 AF_INET AF_INET6 AF_UNIX AI_PASSIVE
15 IPPROTO_IPV6 IPV6_V6ONLY
16 SOCK_DGRAM SOCK_NONBLOCK SOCK_CLOEXEC
17 SOL_SOCKET SO_BROADCAST SO_ERROR SO_REUSEADDR SO_REUSEPORT SO_TYPE
18 getaddrinfo inet_pton pack_sockaddr_in pack_sockaddr_in6 pack_sockaddr_un
19 8 );
20 8 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 8 ▶use Linux::Event::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶use Linux::Event::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 8 ▶use Linux::Event::_SocketConfig ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 8 ▶use Linux::Event::_Resolver ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 8 require Linux::Event::Timer;
27 8 require XSLoader;
28 8 XSLoader::load(__PACKAGE__, $VERSION);
29  
30 8 my %CLASS_DESCRIPTOR;
31 8 ▶my $MAX_INTEGER = $Config::Config{ivsize} >= 8
Branch: 1 branch
BranchTrueFalseTotal
$Config::Config{'ivsize'} >= 8 ? : 8 0 8
32 ? '9223372036854775807' : '2147483647';
33  
34 318 ▶sub _integer ($target, $name, $value, $minimum, $maximum = undef) {
Subroutine _integer: called CC=10 SCAR=23.8
35 318 ▶ croak "$target $name must be an integer"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or not $value =~ /\A\d+\z/u 1 317 318
Condition66%4/6
not defined $value or ref $value or not $value =~ /\A\d+\z/u
l!l&&r!l&&!r
10317
not defined $value or ref $value
l!l&&r!l&&!r
10317
MC/DC33%1/3
not defined $value or ref $value or not $value =~ /\A\d+\z/u
not defined $value ref $value not $value =~ /\A\d+\z/u
Truth table50%2/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not $value =~ /\A\d+\z/u
ABCresult
1XX1
01X1
0011
0000
36 if !defined($value) || ref($value) || $value !~ /\A\d+\z/;
37 317 ▶ $maximum //= $MAX_INTEGER;
Condition66%2/3
$maximum //= $MAX_INTEGER
l!l&&r!l&&!r
732440
MC/DC0%0/2
$maximum //= $MAX_INTEGER
$maximum $MAX_INTEGER
Truth table66%2/3
A //= B
A= $maximumB= $MAX_INTEGER
ABresult
1X1
011
000
38 317 my $digits = "$value";
39 317 $digits =~ s/\A0+(?=\d)//;
40 317 ▶ croak "$target $name must be at most $maximum"
Branch: 1 branch
BranchTrueFalseTotal
if length $digits > length "$maximum" or length $digits == length "$maximum" and $digits gt "$maximum" 1 316 317
Condition66%4/6
length $digits > length "$maximum" or length $digits == length "$maximum" and $digits gt "$maximum"
l!l&&r!l&&!r
10316
length $digits == length "$maximum" and $digits gt "$maximum"
!ll&&!rl&&r
31240
MC/DC33%1/3
length $digits > length "$maximum" or length $digits == length "$maximum" and $digits gt "$maximum"
length $digits > length "$maximum" length $digits == length "$maximum" $digits gt "$maximum"
Truth table75%3/4
A or B and C
A= length $digits > length "$maximum"B= length $digits == length "$maximum"C= $digits gt "$maximum"
ABCresult
1XX1
0111
00X0
0100
41 if length($digits) > length("$maximum")
42 || (length($digits) == length("$maximum")
43 && $digits gt "$maximum");
44 316 $value = 0 + $value;
45 316 ▶ croak "$target $name must be at least $minimum" if $value < $minimum;
Branch: 1 branch
BranchTrueFalseTotal
if $value < $minimum 0 316 316
46 316 return $value;
47 }
48  
49 201 ▶sub _boolean ($target, $name, $value) {
Subroutine _boolean: called CC=5 SCAR=19.2
50 201 ▶ croak "$target $name must be zero or one"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or not $value =~ /\A[01]\z/u 0 201 201
Condition33%2/6
not defined $value or ref $value or not $value =~ /\A[01]\z/u
l!l&&r!l&&!r
00201
not defined $value or ref $value
l!l&&r!l&&!r
00201
MC/DC0%0/3
not defined $value or ref $value or not $value =~ /\A[01]\z/u
not defined $value ref $value not $value =~ /\A[01]\z/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not $value =~ /\A[01]\z/u
ABCresult
1XX1
01X1
0011
0000
51 if !defined($value) || ref($value) || $value !~ /\A[01]\z/;
52 201 ▶ return $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 6 195 201
53 }
54  
55 40 ▶sub _descriptor_for ($class) {
Subroutine _descriptor_for: called CC=18 SCAR=30.9
56 40 ▶ return $CLASS_DESCRIPTOR{$class} if exists $CLASS_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$class} 27 13 40
57 13 ▶ croak 'Linux::Event::Datagram is an abstract base class'
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ 1 12 13
58 if $class eq __PACKAGE__;
59 12 ▶ croak "$class is not a Linux::Event::Datagram subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 12 12
60 if !$class->isa(__PACKAGE__);
61 12 my %callback = map { $_ => scalar $class->can($_) } qw(
62 on_datagram on_drain on_ready on_error on_close configure_socket
63 );
64 12 ▶ croak "$class must define on_datagram()" if !$callback{on_datagram};
Branch: 1 branch
BranchTrueFalseTotal
unless $callback{"on_datagram"} 1 11 12
65  
66 11 my %option = (
67 max_datagram_size => 65_535,
68 max_datagrams_per_tick => 256,
69 edge_triggered => 0,
70 high_watermark => 1_048_576,
71 low_watermark => 262_144,
72 max_pending_bytes => 0,
73 max_pending_datagrams => 0,
74 reuseaddr => 0,
75 reuseport => 0,
76 broadcast => 0,
77 v6only => undef,
78 send_buffer => undef,
79 receive_buffer => undef,
80 );
81 11 ▶ if (my $configure = $class->can('datagram_options')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $configure = $class->can("datagram_options")) 2 9 11
82 2 my @configured = $configure->($class);
83 2 my %configured;
84 2 ▶ if (@configured == 1 && ref($configured[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@configured == 1 and ref $configured[0] eq 'HASH') { } 0 2 2
Condition33%1/3
@configured == 1 and ref $configured[0] eq "HASH"
!ll&&!rl&&r
200
MC/DC0%0/2
@configured == 1 and ref $configured[0] eq "HASH"
@configured == 1 ref $configured[0] eq "HASH"
Truth table33%1/3
A and B
A= @configured == 1B= ref $configured[0] eq "HASH"
ABresult
0X0
100
111
85 0 %configured = %{ $configured[0] };
86 } else {
87 2 ▶ croak "$class datagram_options() returned an odd option list"
Branch: 1 branch
BranchTrueFalseTotal
if @configured % 2 0 2 2
88 if @configured % 2;
89 2 %configured = @configured;
90 }
91 2 my @unknown = grep { !exists $option{$_} } keys %configured;
92 2 ▶ croak "$class datagram_options() returned unknown options: "
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 0 2 2
93 . join(', ', sort @unknown) if @unknown;
94 2 @option{keys %configured} = values %configured;
95 }
96 $option{max_datagram_size} = _integer(
97 11 $class, 'max_datagram_size', $option{max_datagram_size}, 1, 16_777_216,
98 );
99 $option{max_datagrams_per_tick} = _integer(
100 $class, 'max_datagrams_per_tick',
101 11 $option{max_datagrams_per_tick}, 0,
102 );
103 11 for my $name (qw(high_watermark low_watermark max_pending_bytes
104 max_pending_datagrams)) {
105 44 $option{$name} = _integer($class, $name, $option{$name}, 0);
106 }
107 croak "$class low_watermark must be <= high_watermark"
108 11 ▶ if $option{low_watermark} > $option{high_watermark};
Branch: 1 branch
BranchTrueFalseTotal
if $option{"low_watermark"} > $option{"high_watermark"} 0 11 11
109 11 for my $name (qw(edge_triggered reuseaddr reuseport broadcast)) {
110 44 $option{$name} = _boolean($class, $name, $option{$name});
111 }
112 $option{v6only} = _boolean($class, 'v6only', $option{v6only})
113 11 ▶ if defined $option{v6only};
Branch: 1 branch
BranchTrueFalseTotal
if defined $option{"v6only"} 0 11 11
114 11 for my $name (qw(send_buffer receive_buffer)) {
115 $option{$name} = Linux::Event::_SocketConfig::normalize(
116 $class, $name, $option{$name},
117 22 ▶ ) if defined $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $option{$name} 0 22 22
118 }
119 croak "$class edge_triggered requires max_datagrams_per_tick => 0"
120 11 ▶ if $option{edge_triggered} && $option{max_datagrams_per_tick};
Branch: 1 branch
BranchTrueFalseTotal
if $option{"edge_triggered"} and $option{"max_datagrams_per_tick"} 0 11 11
Condition33%1/3
$option{"edge_triggered"} and $option{"max_datagrams_per_tick"}
!ll&&!rl&&r
1100
MC/DC0%0/2
$option{"edge_triggered"} and $option{"max_datagrams_per_tick"}
$option{"edge_triggered"} $option{"max_datagrams_per_tick"}
Truth table33%1/3
A and B
A= $option{"edge_triggered"}B= $option{"max_datagrams_per_tick"}
ABresult
0X0
100
111
121 11 return $CLASS_DESCRIPTOR{$class} = {
122 class => $class, callbacks => \%callback, options => \%option,
123 };
124 }
125  
126 26 ▶sub new ($class, %option) {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
127 26 return $class->_construct(0, %option);
128 }
129  
130 15 ▶sub connect ($class, %option) {
Subroutine connect: called CC=1 SCAR=0.0
Pod undocumented
131 15 return $class->_construct(1, %option);
132 }
133  
134 41 ▶sub _construct ($class, $connect, %option) {
Subroutine _construct: called CC=147 SCAR=72.3
135 41 ▶ croak(($connect ? 'connect' : 'new') .
Branch: 2 branches
BranchTrueFalseTotal
if ref $class 0 41 41
$connect ? : 0 0 0
136 '(): must be called as a class method') if ref $class;
137 41 ▶ my $method = $connect ? 'connect' : 'new';
Branch: 1 branch
BranchTrueFalseTotal
$connect ? : 15 26 41
138 41 my %known = map { $_ => 1 } qw(
139 loop data bind_device
140 max_datagram_size max_datagrams_per_tick edge_triggered
141 high_watermark low_watermark max_pending_bytes
142 max_pending_datagrams reuseaddr reuseport broadcast v6only
143 send_buffer receive_buffer
144 unlink unlink_on_close permissions owns_socket
145 fh host port unix local_host local_port local_unix
146 );
147 41 my @unknown = sort grep { !$known{$_} } keys %option;
148 41 ▶ croak "$method(): unknown options: " . join(', ', @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 40 41
149 40 my %supplied = map { $_ => 1 } keys %option;
150 40 my $descriptor = _descriptor_for($class);
151 38 my $loop = delete $option{loop};
152 38 ▶ croak "$method(): loop must be an object implementing add() and watch()"
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch") 0 38 38
Condition44%4/9
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch")
!ll&&!rl&&r
3710
ref $loop && $loop->can('add') && $loop->can('watch')
!ll&&!rl&&r
001
ref $loop and $loop->can("add")
!ll&&!rl&&r
001
MC/DC0%0/4
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch")
defined $loop ref $loop $loop->can("add") $loop->can('watch')
Truth table40%2/5
A and not(B and C && D)
A= defined $loopB= ref $loopC= $loop->can("add")D= $loop->can('watch')
ABCDresult
0XXX0
11110
10XX1
110X1
11101
153 if defined($loop) && (!ref($loop) || !$loop->can('add')
154 || !$loop->can('watch'));
155 38 my $data = delete $option{data};
156 38 my $bind_device = delete $option{bind_device};
157 38 ▶ croak "$method(): 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 38 38
Condition11%1/9
defined $bind_device and ref $bind_device || $bind_device eq "" || $bind_device =~ /\0/u
!ll&&!rl&&r
3800
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
158 if defined($bind_device)
159 && (ref($bind_device) || $bind_device eq '' || $bind_device =~ /\0/);
160  
161 38 my %effective = %{ $descriptor->{options} };
162 38 for my $name (keys %effective) {
163 494 ▶ next if !exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{$name} 488 6 494
164 6 $effective{$name} = delete $option{$name};
165 }
166 $effective{max_datagram_size} = _integer(
167 "$method():", 'max_datagram_size', $effective{max_datagram_size},
168 38 1, 16_777_216,
169 );
170 $effective{max_datagrams_per_tick} = _integer(
171 "$method():", 'max_datagrams_per_tick',
172 38 $effective{max_datagrams_per_tick}, 0,
173 );
174 38 for my $name (qw(high_watermark low_watermark max_pending_bytes
175 max_pending_datagrams)) {
176 $effective{$name} = _integer(
177 151 "$method():", $name, $effective{$name}, 0,
178 );
179 }
180 croak "$method(): low_watermark must be <= high_watermark"
181 37 ▶ if $effective{low_watermark} > $effective{high_watermark};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"low_watermark"} > $effective{"high_watermark"} 0 37 37
182 37 for my $name (qw(edge_triggered reuseaddr reuseport broadcast)) {
183 $effective{$name} = _boolean(
184 148 "$method():", $name, $effective{$name},
185 );
186 }
187 $effective{v6only} = _boolean(
188 "$method():", 'v6only', $effective{v6only},
189 37 ▶ ) if defined $effective{v6only};
Branch: 1 branch
BranchTrueFalseTotal
if defined $effective{"v6only"} 2 35 37
190 37 for my $name (qw(send_buffer receive_buffer)) {
191 $effective{$name} = Linux::Event::_SocketConfig::normalize(
192 $method, $name, $effective{$name},
193 73 ▶ ) if defined $effective{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $effective{$name} 1 72 73
194 }
195 croak "$method(): edge_triggered requires max_datagrams_per_tick => 0"
196 36 ▶ if $effective{edge_triggered} && $effective{max_datagrams_per_tick};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"edge_triggered"} and $effective{"max_datagrams_per_tick"} 1 35 36
Condition66%2/3
$effective{"edge_triggered"} and $effective{"max_datagrams_per_tick"}
!ll&&!rl&&r
3501
MC/DC50%1/2
$effective{"edge_triggered"} and $effective{"max_datagrams_per_tick"}
$effective{"edge_triggered"} $effective{"max_datagrams_per_tick"}
Truth table66%2/3
A and B
A= $effective{"edge_triggered"}B= $effective{"max_datagrams_per_tick"}
ABresult
0X0
100
111
197 croak "$method(): broadcast and v6only cannot be combined"
198 35 ▶ if $effective{broadcast} && defined $effective{v6only};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"broadcast"} and defined $effective{"v6only"} 0 35 35
Condition33%1/3
$effective{"broadcast"} and defined $effective{"v6only"}
!ll&&!rl&&r
3500
MC/DC0%0/2
$effective{"broadcast"} and defined $effective{"v6only"}
$effective{"broadcast"} defined $effective{"v6only"}
Truth table33%1/3
A and B
A= $effective{"broadcast"}B= defined $effective{"v6only"}
ABresult
0X0
100
111
199  
200 my $unlink_existing = exists($option{unlink})
201 35 ▶ ? _boolean("$method():", 'unlink', delete $option{unlink}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'unlink'} ? : 1 34 35
202 my $unlink_on_close = exists($option{unlink_on_close})
203 ? _boolean("$method():", 'unlink_on_close',
204 35 ▶ delete $option{unlink_on_close}) : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'unlink_on_close'} ? : 0 35 35
205 35 my $permissions = delete $option{permissions};
206 35 ▶ $permissions = _integer("$method():", 'permissions', $permissions, 0, 07777)
Branch: 1 branch
BranchTrueFalseTotal
if defined $permissions 1 34 35
207 if defined $permissions;
208 35 my $owns_socket_supplied = exists $option{owns_socket};
209 my $owns_socket = $owns_socket_supplied
210 ? _boolean("$method():", 'owns_socket', delete $option{owns_socket})
211 35 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
$owns_socket_supplied ? : 4 31 35
212  
213 35 my ($fh, $family, $local, $peer, $path, $local_path);
214 35 my $adopted = 0;
215 35 my ($host, $port, $local_host, $local_port, $needs_resolution,
216 $local_bind, $required_family, $required_family_option);
217 35 ▶ if (!$connect && exists $option{fh}) {
Branch: 5 branches
BranchTrueFalseTotal
if (not $connect and exists $option{'fh'}) { } 3 32 35
elsif (not $connect and exists $option{'host'} || exists $option{'port'}) { } 14 18 32
elsif (not $connect and exists $option{'unix'}) { } 4 14 18
elsif ($connect and exists $option{'host'} || exists $option{'port'}) { } 9 5 14
elsif ($connect and exists $option{'unix'}) { } 5 0 5
Condition100%3/3
not $connect and exists $option{"fh"}
!ll&&!rl&&r
14183
MC/DC100%2/2
not $connect and exists $option{"fh"}
not $connect exists $option{"fh"}
Truth table100%3/3
not(A) and B
A= not $connectB= exists $option{"fh"}
ABresult
0X0
100
111
218 3 $adopted = 1;
219 3 $fh = delete $option{fh};
220 3 ▶ croak 'new(): fh must be a datagram socket filehandle'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh and defined fileno $fh 0 3 3
Condition33%1/3
defined $fh and defined fileno $fh
!ll&&!rl&&r
003
MC/DC0%0/2
defined $fh and defined fileno $fh
defined $fh defined fileno $fh
Truth table33%1/3
A and B
A= defined $fhB= defined fileno $fh
ABresult
0X0
100
111
221 if !defined($fh) || !defined(fileno($fh));
222 croak 'new(): address options are not valid with fh'
223 3 ▶ if grep { exists $option{$_} } qw(host port unix local_host
Branch: 1 branch
BranchTrueFalseTotal
if grep {exists $option{$_};} "host", "port", "unix", "local_host", "local_port", "local_unix" 0 3 3
224 local_port local_unix);
225 3 my $type = getsockopt($fh, SOL_SOCKET, SO_TYPE);
226 3 ▶ croak 'new(): fh must be a datagram socket'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $type or length $type < 4 or unpack("i", $type) != 2 0 3 3
Condition33%2/6
not defined $type or length $type < 4 or unpack("i", $type) != 2
l!l&&r!l&&!r
003
not defined $type or length $type < 4
l!l&&r!l&&!r
003
MC/DC0%0/3
not defined $type or length $type < 4 or unpack("i", $type) != 2
not defined $type length $type < 4 unpack("i", $type) != 2
Truth table25%1/4
not(A) or B or C
A= not defined $typeB= length $type < 4C= unpack("i", $type) != 2
ABCresult
1XX1
01X1
0011
0000
227 if !defined($type) || length($type) < 4
228 || unpack('i', $type) != SOCK_DGRAM;
229 3 $local = Linux::Event::Address->new(getsockname($fh));
230 3 $family = $local->family_number;
231 3 ▶ croak 'new(): fh must use an IPv4, IPv6, or Unix address family'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $family or $family != 2 and $family != 10 and $family != 1 0 3 3
Condition33%3/9
not defined $family or $family != 2 and $family != 10 and $family != 1
l!l&&r!l&&!r
003
$family != 2 and $family != 10 and $family != 1
!ll&&!rl&&r
300
$family != 2 and $family != 10
!ll&&!rl&&r
300
MC/DC0%0/4
not defined $family or $family != 2 and $family != 10 and $family != 1
not defined $family $family != 2 $family != 10 $family != 1
Truth table20%1/5
not(A) or B and C and D
A= not defined $familyB= $family != 2C= $family != 10D= $family != 1
ABCDresult
1XXX1
01111
00XX0
010X0
01100
232 if !defined($family) || ($family != AF_INET
233 && $family != AF_INET6 && $family != AF_UNIX);
234 3 my @invalid = grep { $supplied{$_} }
235 qw(unlink unlink_on_close permissions);
236 3 ▶ if ($family == AF_UNIX) {
Branch: 1 branch
BranchTrueFalseTotal
if ($family == 1) 0 3 3
237 0 push @invalid, grep { $supplied{$_} }
238 qw(bind_device v6only broadcast reuseaddr reuseport);
239 push @invalid, 'broadcast'
240 0 ▶ if $effective{broadcast} && !$supplied{broadcast};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"broadcast"} and not $supplied{"broadcast"} 0 0 0
Condition0%0/3
$effective{"broadcast"} and not $supplied{"broadcast"}
!ll&&!rl&&r
000
MC/DC0%0/2
$effective{"broadcast"} and not $supplied{"broadcast"}
$effective{"broadcast"} not $supplied{"broadcast"}
Truth table0%0/3
A and not(B)
A= $effective{"broadcast"}B= not $supplied{"broadcast"}
ABresult
0X0
100
111
241 push @invalid, 'reuseaddr'
242 0 ▶ if $effective{reuseaddr} && !$supplied{reuseaddr};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"reuseaddr"} and not $supplied{"reuseaddr"} 0 0 0
Condition0%0/3
$effective{"reuseaddr"} and not $supplied{"reuseaddr"}
!ll&&!rl&&r
000
MC/DC0%0/2
$effective{"reuseaddr"} and not $supplied{"reuseaddr"}
$effective{"reuseaddr"} not $supplied{"reuseaddr"}
Truth table0%0/3
A and not(B)
A= $effective{"reuseaddr"}B= not $supplied{"reuseaddr"}
ABresult
0X0
100
111
243 push @invalid, 'reuseport'
244 0 ▶ if $effective{reuseport} && !$supplied{reuseport};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"reuseport"} and not $supplied{"reuseport"} 0 0 0
Condition0%0/3
$effective{"reuseport"} and not $supplied{"reuseport"}
!ll&&!rl&&r
000
MC/DC0%0/2
$effective{"reuseport"} and not $supplied{"reuseport"}
$effective{"reuseport"} not $supplied{"reuseport"}
Truth table0%0/3
A and not(B)
A= $effective{"reuseport"}B= not $supplied{"reuseport"}
ABresult
0X0
100
111
245 push @invalid, 'v6only'
246 0 ▶ if defined($effective{v6only}) && !$supplied{v6only};
Branch: 1 branch
BranchTrueFalseTotal
if defined $effective{"v6only"} and not $supplied{"v6only"} 0 0 0
Condition0%0/3
defined $effective{"v6only"} and not $supplied{"v6only"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $effective{"v6only"} and not $supplied{"v6only"}
defined $effective{"v6only"} not $supplied{"v6only"}
Truth table0%0/3
A and not(B)
A= defined $effective{"v6only"}B= not $supplied{"v6only"}
ABresult
0X0
100
111
247 }
248 3 ▶ croak 'new(): options not valid for this socket source: '
Branch: 1 branch
BranchTrueFalseTotal
if @invalid 0 3 3
249 . join(', ', sort @invalid) if @invalid;
250 3 _set_adopted_flags($fh);
251 3 my $packed_peer = eval { getpeername($fh) };
252 3 ▶ $peer = Linux::Event::Address->new($packed_peer)
Branch: 1 branch
BranchTrueFalseTotal
if defined $packed_peer 0 3 3
253 if defined $packed_peer;
254 3 ▶ $connect = defined($peer) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $peer ? : 0 3 3
255 ▶ } elsif (!$connect && (exists($option{host}) || exists($option{port}))) {
Condition83%5/6
not $connect and exists $option{"host"} || exists $option{"port"}
!ll&&!rl&&r
14414
exists $option{"host"} or exists $option{"port"}
l!l&&r!l&&!r
1404
MC/DC66%2/3
not $connect and exists $option{"host"} || exists $option{"port"}
not $connect exists $option{"host"} exists $option{"port"}
Truth table75%3/4
not(A) and B or C
A= not $connectB= exists $option{"host"}C= exists $option{"port"}
ABCresult
0XX0
1000
11X1
1011
256 14 $host = delete $option{host};
257 14 $port = delete $option{port};
258 14 ▶ croak 'new(): host is required' if !defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 14 14
259 14 ▶ 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 1 13 14
Condition50%3/6
ref $host or $host eq "" or $host =~ /\0/u
l!l&&r!l&&!r
0113
ref $host or $host eq ""
l!l&&r!l&&!r
0014
MC/DC33%1/3
ref $host or $host eq "" or $host =~ /\0/u
ref $host $host eq "" $host =~ /\0/u
Truth table50%2/4
A or B or C
A= ref $hostB= $host eq ""C= $host =~ /\0/u
ABCresult
1XX1
01X1
0011
0000
260 if ref($host) || $host eq '' || $host =~ /\0/;
261 13 $port = _integer('new():', 'port', $port, 0, 65535);
262 12 my @invalid = grep { $supplied{$_} }
263 qw(unix local_host local_port local_unix unlink unlink_on_close
264 permissions owns_socket);
265 12 ▶ croak 'new(): options not valid for UDP: '
Branch: 1 branch
BranchTrueFalseTotal
if @invalid 1 11 12
266 . join(', ', sort @invalid) if @invalid;
267 11 ($fh, $family) = _create_bound_inet(
268 $host, $port, \%effective, $bind_device,
269 );
270 10 $local = Linux::Event::Address->new(getsockname($fh));
271 10 $owns_socket = 1;
272 ▶ } elsif (!$connect && exists $option{unix}) {
Condition66%2/3
not $connect and exists $option{"unix"}
!ll&&!rl&&r
1404
MC/DC50%1/2
not $connect and exists $option{"unix"}
not $connect exists $option{"unix"}
Truth table66%2/3
not(A) and B
A= not $connectB= exists $option{"unix"}
ABresult
0X0
100
111
273 4 $path = delete $option{unix};
274 4 ▶ croak 'new(): unix must be a non-empty path without NUL bytes'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or ref $path or $path eq "" or $path =~ /\0/u 1 3 4
Condition44%4/9
not defined $path or ref $path or $path eq "" or $path =~ /\0/u
l!l&&r!l&&!r
013
not defined $path or ref $path or $path eq ""
l!l&&r!l&&!r
004
not defined $path or ref $path
l!l&&r!l&&!r
004
MC/DC25%1/4
not defined $path or ref $path or $path eq "" or $path =~ /\0/u
not defined $path ref $path $path eq "" $path =~ /\0/u
Truth table40%2/5
not(A) or B or C or D
A= not defined $pathB= ref $pathC= $path eq ""D= $path =~ /\0/u
ABCDresult
1XXX1
01XX1
001X1
00011
00000
275 if !defined($path) || ref($path) || $path eq '' || $path =~ /\0/;
276 3 my @invalid = grep { $supplied{$_} }
277 qw(local_host local_port local_unix bind_device v6only broadcast
278 reuseaddr reuseport owns_socket);
279 push @invalid, 'broadcast'
280 3 ▶ if $effective{broadcast} && !$supplied{broadcast};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"broadcast"} and not $supplied{"broadcast"} 0 3 3
Condition33%1/3
$effective{"broadcast"} and not $supplied{"broadcast"}
!ll&&!rl&&r
300
MC/DC0%0/2
$effective{"broadcast"} and not $supplied{"broadcast"}
$effective{"broadcast"} not $supplied{"broadcast"}
Truth table33%1/3
A and not(B)
A= $effective{"broadcast"}B= not $supplied{"broadcast"}
ABresult
0X0
100
111
281 push @invalid, 'reuseaddr'
282 3 ▶ if $effective{reuseaddr} && !$supplied{reuseaddr};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"reuseaddr"} and not $supplied{"reuseaddr"} 0 3 3
Condition33%1/3
$effective{"reuseaddr"} and not $supplied{"reuseaddr"}
!ll&&!rl&&r
300
MC/DC0%0/2
$effective{"reuseaddr"} and not $supplied{"reuseaddr"}
$effective{"reuseaddr"} not $supplied{"reuseaddr"}
Truth table33%1/3
A and not(B)
A= $effective{"reuseaddr"}B= not $supplied{"reuseaddr"}
ABresult
0X0
100
111
283 push @invalid, 'reuseport'
284 3 ▶ if $effective{reuseport} && !$supplied{reuseport};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"reuseport"} and not $supplied{"reuseport"} 0 3 3
Condition33%1/3
$effective{"reuseport"} and not $supplied{"reuseport"}
!ll&&!rl&&r
300
MC/DC0%0/2
$effective{"reuseport"} and not $supplied{"reuseport"}
$effective{"reuseport"} not $supplied{"reuseport"}
Truth table33%1/3
A and not(B)
A= $effective{"reuseport"}B= not $supplied{"reuseport"}
ABresult
0X0
100
111
285 push @invalid, 'v6only'
286 3 ▶ if defined($effective{v6only}) && !$supplied{v6only};
Branch: 1 branch
BranchTrueFalseTotal
if defined $effective{"v6only"} and not $supplied{"v6only"} 0 3 3
Condition33%1/3
defined $effective{"v6only"} and not $supplied{"v6only"}
!ll&&!rl&&r
300
MC/DC0%0/2
defined $effective{"v6only"} and not $supplied{"v6only"}
defined $effective{"v6only"} not $supplied{"v6only"}
Truth table33%1/3
A and not(B)
A= defined $effective{"v6only"}B= not $supplied{"v6only"}
ABresult
0X0
100
111
287 3 ▶ croak 'new(): options not valid for Unix datagrams: '
Branch: 1 branch
BranchTrueFalseTotal
if @invalid 1 2 3
288 . join(', ', sort @invalid) if @invalid;
289 2 ($fh, $family) = _create_bound_unix(
290 $path, $unlink_existing, $permissions, \%effective,
291 );
292 2 $local = Linux::Event::Address->new(getsockname($fh));
293 2 $owns_socket = 1;
294 ▶ } elsif ($connect && (exists($option{host}) || exists($option{port}))) {
Condition66%4/6
$connect and exists $option{"host"} || exists $option{"port"}
!ll&&!rl&&r
059
exists $option{"host"} or exists $option{"port"}
l!l&&r!l&&!r
905
MC/DC33%1/3
$connect and exists $option{"host"} || exists $option{"port"}
$connect exists $option{"host"} exists $option{"port"}
Truth table50%2/4
A and B or C
A= $connectB= exists $option{"host"}C= exists $option{"port"}
ABCresult
0XX0
1000
11X1
1011
295 9 $host = delete $option{host};
296 9 $port = delete $option{port};
297 9 ▶ croak 'connect(): host is required' if !defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 9 9
298 9 ▶ croak 'connect(): host must be a non-empty string without NUL bytes'
Branch: 1 branch
BranchTrueFalseTotal
if ref $host or $host eq "" or $host =~ /\0/u 1 8 9
Condition50%3/6
ref $host or $host eq "" or $host =~ /\0/u
l!l&&r!l&&!r
018
ref $host or $host eq ""
l!l&&r!l&&!r
009
MC/DC33%1/3
ref $host or $host eq "" or $host =~ /\0/u
ref $host $host eq "" $host =~ /\0/u
Truth table50%2/4
A or B or C
A= ref $hostB= $host eq ""C= $host =~ /\0/u
ABCresult
1XX1
01X1
0011
0000
299 if ref($host) || $host eq '' || $host =~ /\0/;
300 8 $port = _integer('connect():', 'port', $port, 0, 65535);
301 8 my $has_local_host = exists $option{local_host};
302 8 $local_host = delete $option{local_host};
303 8 my $has_local_port = exists $option{local_port};
304 $local_port = $has_local_port ? _integer(
305 8 ▶ 'connect():', 'local_port', delete($option{local_port}), 0, 65535,
Branch: 1 branch
BranchTrueFalseTotal
$has_local_port ? : 3 5 8
306 ) : 0;
307 8 ▶ $local_bind = $has_local_host || $has_local_port ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$has_local_host || $has_local_port ? : 5 3 8
Condition100%3/3
$has_local_host or $has_local_port
l!l&&r!l&&!r
323
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
308 8 ▶ if ($has_local_host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_local_host) 3 5 8
309 3 ▶ croak 'connect(): 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 3 3
Condition33%2/6
not defined $local_host or ref $local_host or $local_host eq ""
l!l&&r!l&&!r
003
not defined $local_host or ref $local_host
l!l&&r!l&&!r
003
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
310 if !defined($local_host) || ref($local_host) || $local_host eq '';
311 3 ▶ croak 'connect(): local_host must be a numeric IPv4 or IPv6 address'
Branch: 1 branch
BranchTrueFalseTotal
unless defined inet_pton(2, $local_host) or defined inet_pton(10, $local_host) 1 2 3
Condition100%3/3
defined inet_pton(2, $local_host) or defined inet_pton(10, $local_host)
l!l&&r!l&&!r
111
MC/DC100%2/2
defined inet_pton(2, $local_host) or defined inet_pton(10, $local_host)
defined inet_pton(2, $local_host) defined inet_pton(10, $local_host)
Truth table100%3/3
A or B
A= defined inet_pton(2, $local_host)B= defined inet_pton(10, $local_host)
ABresult
1X1
011
000
312 if !defined(inet_pton(AF_INET, $local_host))
313 && !defined(inet_pton(AF_INET6, $local_host));
314 2 ▶ $required_family = defined(inet_pton(AF_INET, $local_host))
Branch: 1 branch
BranchTrueFalseTotal
defined inet_pton(2, $local_host) ? : 1 1 2
315 ? AF_INET : AF_INET6;
316 2 $required_family_option = 'local_host';
317 }
318 7 ▶ if (defined $effective{v6only}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $effective{"v6only"}) 0 7 7
319 0 ▶ croak 'connect(): local_host conflicts with v6only'
Branch: 1 branch
BranchTrueFalseTotal
if defined $required_family and $required_family != 10 0 0 0
Condition0%0/3
defined $required_family and $required_family != 10
!ll&&!rl&&r
000
MC/DC0%0/2
defined $required_family and $required_family != 10
defined $required_family $required_family != 10
Truth table0%0/3
A and B
A= defined $required_familyB= $required_family != 10
ABresult
0X0
100
111
320 if defined($required_family) && $required_family != AF_INET6;
321 0 $required_family = AF_INET6;
322 0 $required_family_option = 'v6only';
323 }
324 7 ▶ if ($effective{broadcast}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($effective{"broadcast"}) 0 7 7
325 0 ▶ croak 'connect(): local_host conflicts with broadcast'
Branch: 1 branch
BranchTrueFalseTotal
if defined $required_family and $required_family != 2 0 0 0
Condition0%0/3
defined $required_family and $required_family != 2
!ll&&!rl&&r
000
MC/DC0%0/2
defined $required_family and $required_family != 2
defined $required_family $required_family != 2
Truth table0%0/3
A and B
A= defined $required_familyB= $required_family != 2
ABresult
0X0
100
111
326 if defined($required_family) && $required_family != AF_INET;
327 0 $required_family = AF_INET;
328 0 $required_family_option = 'broadcast';
329 }
330 7 my @invalid = grep { $supplied{$_} }
331 qw(fh unix local_unix unlink unlink_on_close permissions
332 owns_socket);
333 7 ▶ croak 'connect(): options not valid for UDP: '
Branch: 1 branch
BranchTrueFalseTotal
if @invalid 0 7 7
334 . join(', ', sort @invalid) if @invalid;
335 7 ▶ $needs_resolution = !defined(inet_pton(AF_INET, $host))
Condition66%2/3
defined inet_pton(2, $host) || defined inet_pton(10, $host)
l!l&&r!l&&!r
502
MC/DC50%1/2
defined inet_pton(2, $host) || defined inet_pton(10, $host)
defined inet_pton(2, $host) defined inet_pton(10, $host)
Truth table66%2/3
A || B
A= defined inet_pton(2, $host)B= defined inet_pton(10, $host)
ABresult
1X1
011
000
336 && !defined(inet_pton(AF_INET6, $host));
337 7 $owns_socket = 1;
338 ▶ } elsif ($connect && exists $option{unix}) {
Condition33%1/3
$connect and exists $option{"unix"}
!ll&&!rl&&r
005
MC/DC0%0/2
$connect and exists $option{"unix"}
$connect exists $option{"unix"}
Truth table33%1/3
A and B
A= $connectB= exists $option{"unix"}
ABresult
0X0
100
111
339 5 $path = delete $option{unix};
340 5 $local_path = delete $option{local_unix};
341 5 ▶ croak 'connect(): unix must be a non-empty path without NUL bytes'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or ref $path or $path eq "" or $path =~ /\0/u 1 4 5
Condition44%4/9
not defined $path or ref $path or $path eq "" or $path =~ /\0/u
l!l&&r!l&&!r
014
not defined $path or ref $path or $path eq ""
l!l&&r!l&&!r
005
not defined $path or ref $path
l!l&&r!l&&!r
005
MC/DC25%1/4
not defined $path or ref $path or $path eq "" or $path =~ /\0/u
not defined $path ref $path $path eq "" $path =~ /\0/u
Truth table40%2/5
not(A) or B or C or D
A= not defined $pathB= ref $pathC= $path eq ""D= $path =~ /\0/u
ABCDresult
1XXX1
01XX1
001X1
00011
00000
342 if !defined($path) || ref($path) || $path eq '' || $path =~ /\0/;
343 4 ▶ croak 'connect(): local_unix must be a non-empty path without NUL bytes'
Branch: 1 branch
BranchTrueFalseTotal
if defined $local_path and ref $local_path || $local_path eq "" || $local_path =~ /\0/u 1 3 4
Condition66%6/9
defined $local_path and ref $local_path || $local_path eq "" || $local_path =~ /\0/u
!ll&&!rl&&r
211
ref $local_path or $local_path eq "" or $local_path =~ /\0/u
l!l&&r!l&&!r
011
ref $local_path or $local_path eq ""
l!l&&r!l&&!r
002
MC/DC50%2/4
defined $local_path and ref $local_path || $local_path eq "" || $local_path =~ /\0/u
defined $local_path ref $local_path $local_path eq "" $local_path =~ /\0/u
Truth table60%3/5
A and B or C or D
A= defined $local_pathB= ref $local_pathC= $local_path eq ""D= $local_path =~ /\0/u
ABCDresult
0XXX0
10000
11XX1
101X1
10011
344 if defined($local_path)
345 && (ref($local_path) || $local_path eq '' || $local_path =~ /\0/);
346 3 my @invalid = grep { $supplied{$_} }
347 qw(fh host port local_host local_port bind_device v6only broadcast
348 reuseaddr reuseport owns_socket);
349 3 ▶ push @invalid, grep { $supplied{$_} }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local_path 2 1 3
350 qw(unlink unlink_on_close permissions) if !defined $local_path;
351 push @invalid, 'broadcast'
352 3 ▶ if $effective{broadcast} && !$supplied{broadcast};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"broadcast"} and not $supplied{"broadcast"} 0 3 3
Condition33%1/3
$effective{"broadcast"} and not $supplied{"broadcast"}
!ll&&!rl&&r
300
MC/DC0%0/2
$effective{"broadcast"} and not $supplied{"broadcast"}
$effective{"broadcast"} not $supplied{"broadcast"}
Truth table33%1/3
A and not(B)
A= $effective{"broadcast"}B= not $supplied{"broadcast"}
ABresult
0X0
100
111
353 push @invalid, 'reuseaddr'
354 3 ▶ if $effective{reuseaddr} && !$supplied{reuseaddr};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"reuseaddr"} and not $supplied{"reuseaddr"} 0 3 3
Condition33%1/3
$effective{"reuseaddr"} and not $supplied{"reuseaddr"}
!ll&&!rl&&r
300
MC/DC0%0/2
$effective{"reuseaddr"} and not $supplied{"reuseaddr"}
$effective{"reuseaddr"} not $supplied{"reuseaddr"}
Truth table33%1/3
A and not(B)
A= $effective{"reuseaddr"}B= not $supplied{"reuseaddr"}
ABresult
0X0
100
111
355 push @invalid, 'reuseport'
356 3 ▶ if $effective{reuseport} && !$supplied{reuseport};
Branch: 1 branch
BranchTrueFalseTotal
if $effective{"reuseport"} and not $supplied{"reuseport"} 0 3 3
Condition33%1/3
$effective{"reuseport"} and not $supplied{"reuseport"}
!ll&&!rl&&r
300
MC/DC0%0/2
$effective{"reuseport"} and not $supplied{"reuseport"}
$effective{"reuseport"} not $supplied{"reuseport"}
Truth table33%1/3
A and not(B)
A= $effective{"reuseport"}B= not $supplied{"reuseport"}
ABresult
0X0
100
111
357 push @invalid, 'v6only'
358 3 ▶ if defined($effective{v6only}) && !$supplied{v6only};
Branch: 1 branch
BranchTrueFalseTotal
if defined $effective{"v6only"} and not $supplied{"v6only"} 0 3 3
Condition33%1/3
defined $effective{"v6only"} and not $supplied{"v6only"}
!ll&&!rl&&r
300
MC/DC0%0/2
defined $effective{"v6only"} and not $supplied{"v6only"}
defined $effective{"v6only"} not $supplied{"v6only"}
Truth table33%1/3
A and not(B)
A= defined $effective{"v6only"}B= not $supplied{"v6only"}
ABresult
0X0
100
111
359 3 ▶ croak 'connect(): options not valid for Unix datagrams: '
Branch: 1 branch
BranchTrueFalseTotal
if @invalid 2 1 3
360 . join(', ', sort @invalid) if @invalid;
361 1 $owns_socket = 1;
362 } else {
363 0 ▶ croak "$method(): exactly one socket source is required "
Branch: 1 branch
BranchTrueFalseTotal
$connect ? : 0 0 0
364 . ($connect ? '(host/port or unix)' : '(fh, host/port, or unix)');
365 }
366 23 ▶ my $validation_error = !$adopted && $owns_socket_supplied
Branch: 2 branches
BranchTrueFalseTotal
!$adopted && $owns_socket_supplied ? : 0 23 23
%option ? : 0 23 23
Condition66%2/3
not $adopted and $owns_socket_supplied
!ll&&!rl&&r
3200
MC/DC0%0/2
not $adopted and $owns_socket_supplied
not $adopted $owns_socket_supplied
Truth table66%2/3
not(A) and B
A= not $adoptedB= $owns_socket_supplied
ABresult
0X0
100
111
367 ? "$method(): owns_socket is valid only with fh"
368 : %option
369 ? "$method(): options not valid for this socket source: "
370 . join(', ', sort keys %option)
371 : undef;
372 23 ▶ if (defined $validation_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $validation_error) 0 23 23
373 0 ▶ if (!$adopted && defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $adopted and defined $fh) 0 0 0
Condition0%0/3
not $adopted and defined $fh
!ll&&!rl&&r
000
MC/DC0%0/2
not $adopted and defined $fh
not $adopted defined $fh
Truth table0%0/3
not(A) and B
A= not $adoptedB= defined $fh
ABresult
0X0
100
111
374 0 close $fh;
375 0 ▶ unlink $path if !$connect && defined($path) && -S $path;
Branch: 1 branch
BranchTrueFalseTotal
if not $connect and defined $path and -S $path 0 0 0
Condition0%0/6
not $connect and defined $path and -S $path
!ll&&!rl&&r
000
not $connect and defined $path
!ll&&!rl&&r
000
MC/DC0%0/3
not $connect and defined $path and -S $path
not $connect defined $path -S $path
Truth table0%0/4
not(A) and B and C
A= not $connectB= defined $pathC= -S $path
ABCresult
0XX0
10X0
1100
1111
376 }
377 0 croak $validation_error;
378 }
379  
380 23 ▶ my $self = bless {
Branch: 4 branches
BranchTrueFalseTotal
$connect ? : 8 15 23
$local_bind ? : 4 19 23
$needs_resolution ? : 2 21 23
$owns_socket ? : 22 1 23
381 descriptor => $descriptor,
382 options => \%effective,
383 loop => undef,
384 data => $data,
385 fh => $fh,
386 watcher => undef,
387 family_number => $family,
388 local => $local,
389 peer => $peer,
390 connected => $connect ? 1 : 0,
391 host => $host,
392 port => $port,
393 path => $path,
394 local_host => $local_host,
395 local_port => $local_port,
396 local_bind => $local_bind ? 1 : 0,
397 local_path => $local_path,
398 bind_device => $bind_device,
399 required_family => $required_family,
400 required_family_option => $required_family_option,
401 needs_resolution => $needs_resolution ? 1 : 0,
402 resolver => undef,
403 resolver_request => undef,
404 owns_socket => $owns_socket ? 1 : 0,
405 unlink_existing => $unlink_existing,
406 unlink_on_close => $unlink_on_close,
407 permissions => $permissions,
408 queue => [],
409 pending_bytes => 0,
410 above_high => 0,
411 read_paused => 0,
412 state => 'unattached',
413 last_error => undef,
414 ready_fired => 0,
415 ready_timer => undef,
416 }, $class;
417  
418 23 ▶ if ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 15 8 23
419 15 my $configured = eval {
420 15 ▶ $self->_apply_socket_policy($fh, $family) if $adopted;
Branch: 1 branch
BranchTrueFalseTotal
if $adopted 3 12 15
421 15 ▶ $self->_configure_socket(
Branch: 2 branches
BranchTrueFalseTotal
$adopted ? : 3 12 15
$adopted ? : 3 12 15
Condition33%1/3
$peer // $local
l!l&&r!l&&!r
030
MC/DC0%0/2
$peer // $local
$peer $local
Truth table33%1/3
A // B
A= $peerB= $local
ABresult
1X1
011
000
422 $fh, $adopted ? 'adopted' : 'bind',
423 $adopted ? ($peer // $local) : $local,
424 );
425 15 1;
426 };
427 15 ▶ if (!$configured) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($configured) 0 15 15
428 0 ▶ my $error = $@ || 'socket configuration failed';
Condition0%0/2
$@ || 'socket configuration failed'
l!l
00
MC/DC0%0/1
$@ || 'socket configuration failed'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
429 0 ▶ close $fh if $self->{owns_socket};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"owns_socket"} 0 0 0
430 unlink $path
431 0 ▶ if $self->{owns_socket} && defined($path) && -S $path;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"owns_socket"} and defined $path and -S $path 0 0 0
Condition0%0/6
$self->{"owns_socket"} and defined $path and -S $path
!ll&&!rl&&r
000
$self->{"owns_socket"} and defined $path
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"owns_socket"} and defined $path and -S $path
$self->{"owns_socket"} defined $path -S $path
Truth table0%0/4
A and B and C
A= $self->{"owns_socket"}B= defined $pathC= -S $path
ABCresult
0XX0
10X0
1100
1111
432 0 $self->{fh} = undef;
433 0 die $error;
434 }
435 }
436 23 ▶ $loop->add($self) if defined $loop;
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop 1 22 23
437 23 return $self;
438 }
439  
440 1 ▶sub _message ($errno) { local $! = $errno; return "$!" }
Subroutine _message: called CC=1 SCAR=0.0
441  
442 0 ▶sub _setup_error ($operation, $errno, %field) {
Subroutine _setup_error: not called CC=1 SCAR=6.9
443 0 die Linux::Event::Error->new(
444 type => 'setup', operation => $operation, errno => $errno,
445 message => _message($errno), fatal => 1, %field,
446 );
447 }
448  
449 3 ▶sub _set_adopted_flags ($fh) {
Subroutine _set_adopted_flags: called CC=5 SCAR=17.0
450 3 my $status = fcntl($fh, F_GETFL, 0);
451 3 ▶ _setup_error('fcntl', 0 + $!) if !defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 0 3 3
452 3 ▶ fcntl($fh, F_SETFL, $status | O_NONBLOCK)
Branch: 1 branch
BranchTrueFalseTotal
fcntl $fh, 4, $status | 2048 or _setup_error("fcntl", 0 + $!) 3 0 3
453 or _setup_error('fcntl', 0 + $!);
454 3 my $descriptor = fcntl($fh, F_GETFD, 0);
455 3 ▶ _setup_error('fcntl', 0 + $!) if !defined $descriptor;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $descriptor 0 3 3
456 3 ▶ fcntl($fh, F_SETFD, $descriptor | FD_CLOEXEC)
Branch: 1 branch
BranchTrueFalseTotal
fcntl $fh, 2, $descriptor | 1 or _setup_error("fcntl", 0 + $!) 3 0 3
457 or _setup_error('fcntl', 0 + $!);
458 3 return;
459 }
460  
461 11 ▶sub _create_bound_inet ($host, $port, $option, $bind_device) {
Subroutine _create_bound_inet: called CC=23 SCAR=46.1
462 11 ▶ my $node = $host eq '*' ? undef : $host;
Branch: 1 branch
BranchTrueFalseTotal
$host eq '*' ? : 0 11 11
463 11 my ($error, @candidate) = getaddrinfo(
464 $node, $port, { socktype => SOCK_DGRAM, flags => AI_PASSIVE },
465 );
466 11 ▶ die Linux::Event::Error->new(
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 11 11
467 type => 'resolve', operation => 'resolve', message => "$error",
468 host => $host, port => $port,
469 ) if $error;
470 11 my $last_errno = Errno::EADDRNOTAVAIL();
471 11 my $compatible = 0;
472 11 for my $candidate (@candidate) {
473 next if $candidate->{family} != AF_INET
474 11 ▶ && $candidate->{family} != AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->{"family"} != 2 and $candidate->{"family"} != 10 0 11 11
Condition66%2/3
$candidate->{"family"} != 2 and $candidate->{"family"} != 10
!ll&&!rl&&r
1010
MC/DC0%0/2
$candidate->{"family"} != 2 and $candidate->{"family"} != 10
$candidate->{"family"} != 2 $candidate->{"family"} != 10
Truth table66%2/3
A and B
A= $candidate->{"family"} != 2B= $candidate->{"family"} != 10
ABresult
0X0
100
111
475 next if defined($option->{v6only})
476 11 ▶ && $candidate->{family} != AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
if defined $option->{"v6only"} and $candidate->{"family"} != 10 1 10 11
Condition100%3/3
defined $option->{"v6only"} and $candidate->{"family"} != 10
!ll&&!rl&&r
911
MC/DC100%2/2
defined $option->{"v6only"} and $candidate->{"family"} != 10
defined $option->{"v6only"} $candidate->{"family"} != 10
Truth table100%3/3
A and B
A= defined $option->{"v6only"}B= $candidate->{"family"} != 10
ABresult
0X0
100
111
477 10 ▶ next if $option->{broadcast} && $candidate->{family} != AF_INET;
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"broadcast"} and $candidate->{"family"} != 2 0 10 10
Condition33%1/3
$option->{"broadcast"} and $candidate->{"family"} != 2
!ll&&!rl&&r
1000
MC/DC0%0/2
$option->{"broadcast"} and $candidate->{"family"} != 2
$option->{"broadcast"} $candidate->{"family"} != 2
Truth table33%1/3
A and B
A= $option->{"broadcast"}B= $candidate->{"family"} != 2
ABresult
0X0
100
111
478 10 $compatible = 1;
479 10 my $fh;
480 10 ▶ if (!socket($fh, $candidate->{family},
Branch: 1 branch
BranchTrueFalseTotal
unless (socket $fh, $candidate->{"family"}, 526338, $candidate->{"protocol"} // 0) 0 10 10
Condition50%1/2
$candidate->{"protocol"} // 0
l!l
100
MC/DC0%0/1
$candidate->{"protocol"} // 0
$candidate->{"protocol"}
Truth table50%1/2
A
A= $candidate->{"protocol"}
Aresult
11
00
481 SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
482 $candidate->{protocol} // 0)) {
483 0 $last_errno = 0 + $!;
484 0 next;
485 }
486 10 my $ok = eval {
487 _apply_creation_policy(
488 10 $fh, $candidate->{family}, $option, $bind_device,
489 );
490 bind($fh, $candidate->{addr})
491 10 ▶ or _setup_error('bind', 0 + $!, host => $host, port => $port);
Branch: 1 branch
BranchTrueFalseTotal
bind $fh, $candidate->{"addr"} or _setup_error("bind", 0 + $!, "host", $host, "port", $port) 10 0 10
492 10 1;
493 };
494 10 ▶ return ($fh, $candidate->{family}) if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 10 0 10
495 0 my $failure = $@;
496 0 close $fh;
497 0 ▶ die $failure if blessed($failure)
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($failure) and $failure->isa("Linux::Event::Error") and $failure->type eq "socket_configuration" 0 0 0
Condition0%0/6
builtin::blessed($failure) and $failure->isa("Linux::Event::Error") and $failure->type eq "socket_configuration"
!ll&&!rl&&r
000
builtin::blessed($failure) and $failure->isa("Linux::Event::Error")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($failure) and $failure->isa("Linux::Event::Error") and $failure->type eq "socket_configuration"
builtin::blessed($failure) $failure->isa("Linux::Event::Error") $failure->type eq "socket_configuration"
Truth table0%0/4
A and B and C
A= builtin::blessed($failure)B= $failure->isa("Linux::Event::Error")C= $failure->type eq "socket_configuration"
ABCresult
0XX0
10X0
1100
1111
498 && $failure->isa('Linux::Event::Error')
499 && $failure->type eq 'socket_configuration';
500 0 ▶ $last_errno = blessed($failure) && defined($failure->errno)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($failure) && defined $failure->errno ? : 0 0 0
Condition0%0/3
builtin::blessed($failure) and defined $failure->errno
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($failure) and defined $failure->errno
builtin::blessed($failure) defined $failure->errno
Truth table0%0/3
A and B
A= builtin::blessed($failure)B= defined $failure->errno
ABresult
0X0
100
111
501 ? $failure->errno : 0 + $!;
502 }
503 die Linux::Event::Error->new(
504 type => 'socket_configuration', operation => 'setsockopt',
505 option => 'v6only',
506 message => 'v6only requires an IPv6 bind address',
507 host => $host, port => $port,
508 1 ▶ ) if defined($option->{v6only}) && !$compatible;
Branch: 1 branch
BranchTrueFalseTotal
if defined $option->{"v6only"} and not $compatible 1 0 1
Condition33%1/3
defined $option->{"v6only"} and not $compatible
!ll&&!rl&&r
001
MC/DC0%0/2
defined $option->{"v6only"} and not $compatible
defined $option->{"v6only"} not $compatible
Truth table33%1/3
A and not(B)
A= defined $option->{"v6only"}B= not $compatible
ABresult
0X0
100
111
509 die Linux::Event::Error->new(
510 type => 'socket_configuration', operation => 'setsockopt',
511 option => 'broadcast',
512 message => 'broadcast requires an IPv4 bind address',
513 host => $host, port => $port,
514 0 ▶ ) if $option->{broadcast} && !$compatible;
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"broadcast"} and not $compatible 0 0 0
Condition0%0/3
$option->{"broadcast"} and not $compatible
!ll&&!rl&&r
000
MC/DC0%0/2
$option->{"broadcast"} and not $compatible
$option->{"broadcast"} not $compatible
Truth table0%0/3
A and not(B)
A= $option->{"broadcast"}B= not $compatible
ABresult
0X0
100
111
515 0 _setup_error('bind', $last_errno, host => $host, port => $port);
516 }
517  
518 3 ▶sub _prepare_unix_path ($path, $unlink_existing) {
Subroutine _prepare_unix_path: called CC=6 SCAR=30.5
519 3 ▶ if (-e $path || -l $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $path or -l $path) 0 3 3
Condition33%1/3
-e $path or -l $path
l!l&&r!l&&!r
003
MC/DC0%0/2
-e $path or -l $path
-e $path -l $path
Truth table33%1/3
A or B
A= -e $pathB= -l $path
ABresult
1X1
011
000
520 0 ▶ croak "Unix datagram path already exists: $path" if !$unlink_existing;
Branch: 1 branch
BranchTrueFalseTotal
unless $unlink_existing 0 0 0
521 0 ▶ croak "refusing to unlink non-socket path: $path" if !-S $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -S $path 0 0 0
522 0 ▶ unlink($path) or _setup_error('unlink', 0 + $!, path => $path);
Branch: 1 branch
BranchTrueFalseTotal
unlink $path or _setup_error("unlink", 0 + $!, "path", $path) 0 0 0
523 }
524 3 return;
525 }
526  
527 2 ▶sub _create_bound_unix ($path, $unlink_existing, $permissions, $option) {
Subroutine _create_bound_unix: called CC=7 SCAR=25.2
528 2 _prepare_unix_path($path, $unlink_existing);
529 2 ▶ socket(my $fh, AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)
Branch: 1 branch
BranchTrueFalseTotal
socket my $fh, 1, 526338, 0 or _setup_error("socket", 0 + $!, "path", $path) 2 0 2
530 or _setup_error('socket', 0 + $!, path => $path);
531 2 my $ok = eval {
532 Linux::Event::_SocketConfig::apply_policy($fh, AF_UNIX, {
533 send_buffer => $option->{send_buffer},
534 receive_buffer => $option->{receive_buffer},
535 2 });
536 2 ▶ bind($fh, pack_sockaddr_un($path))
Branch: 1 branch
BranchTrueFalseTotal
bind $fh, pack_sockaddr_un($path) or _setup_error("bind", 0 + $!, "path", $path) 2 0 2
537 or _setup_error('bind', 0 + $!, path => $path);
538 2 ▶ if (defined($permissions) && !chmod($permissions, $path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $permissions and not chmod($permissions, $path)) 0 2 2
Condition33%1/3
defined $permissions and not chmod($permissions, $path)
!ll&&!rl&&r
200
MC/DC0%0/2
defined $permissions and not chmod($permissions, $path)
defined $permissions not chmod($permissions, $path)
Truth table33%1/3
A and not(B)
A= defined $permissionsB= not chmod($permissions, $path)
ABresult
0X0
100
111
539 0 _setup_error('chmod', 0 + $!, path => $path);
540 }
541 2 1;
542 };
543 2 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 2 2
544 0 my $failure = $@;
545 0 close $fh;
546 0 ▶ unlink $path if -S $path;
Branch: 1 branch
BranchTrueFalseTotal
if -S $path 0 0 0
547 0 die $failure;
548 }
549 2 return ($fh, AF_UNIX);
550 }
551  
552 1 ▶sub _socket_option_error ($name, $errno, $message = undef,
Subroutine _socket_option_error: called CC=5 SCAR=18.4
553 1 $operation = 'setsockopt') {
554 1 ▶ die Linux::Event::Error->new(
Condition40%2/5
$errno || undef
l!l
01
$message // _message($errno)
l!l&&r!l&&!r
100
MC/DC0%0/1
$errno || undef
$errno
MC/DC0%0/2
$message // _message($errno)
$message _message($errno)
Truth table50%1/2
A
A= $errno
Aresult
11
00
Truth table33%1/3
A // B
A= $messageB= _message($errno)
ABresult
1X1
011
000
555 type => 'socket_configuration', operation => $operation,
556 option => $name, errno => $errno || undef,
557 message => $message // _message($errno),
558 );
559 }
560  
561 20 ▶sub _apply_creation_policy ($fh, $family, $option, $bind_device) {
Subroutine _apply_creation_policy: called CC=11 SCAR=32.1
562 20 for my $item (
563 ['reuseaddr', SO_REUSEADDR, $option->{reuseaddr}],
564 ['reuseport', SO_REUSEPORT, $option->{reuseport}],
565 ['broadcast', SO_BROADCAST, $option->{broadcast}],
566 ) {
567 60 ▶ next if !$item->[2];
Branch: 1 branch
BranchTrueFalseTotal
unless $item->[2] 60 0 60
568 0 ▶ _socket_option_error(
Branch: 1 branch
BranchTrueFalseTotal
if $item->[0] eq "broadcast" and $family != 2 0 0 0
Condition0%0/3
$item->[0] eq "broadcast" and $family != 2
!ll&&!rl&&r
000
MC/DC0%0/2
$item->[0] eq "broadcast" and $family != 2
$item->[0] eq "broadcast" $family != 2
Truth table0%0/3
A and B
A= $item->[0] eq "broadcast"B= $family != 2
ABresult
0X0
100
111
569 'broadcast', 0, 'broadcast is valid only for IPv4 sockets',
570 ) if $item->[0] eq 'broadcast' && $family != AF_INET;
571 0 ▶ setsockopt($fh, SOL_SOCKET, $item->[1], pack('i', 1))
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $fh, 1, $item->[1], "\1\0\0\0" or _socket_option_error($item->[0], 0 + $!) 0 0 0
572 or _socket_option_error($item->[0], 0 + $!);
573 }
574 20 ▶ if (defined($option->{v6only}) && $family != AF_INET6) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option->{"v6only"} and $family != 10) 0 20 20
Condition66%2/3
defined $option->{"v6only"} and $family != 10
!ll&&!rl&&r
1910
MC/DC0%0/2
defined $option->{"v6only"} and $family != 10
defined $option->{"v6only"} $family != 10
Truth table66%2/3
A and B
A= defined $option->{"v6only"}B= $family != 10
ABresult
0X0
100
111
575 0 die Linux::Event::Error->new(
576 type => 'socket_configuration', operation => 'setsockopt',
577 option => 'v6only',
578 message => 'v6only is valid only for IPv6 sockets',
579 );
580 }
581 20 ▶ if (defined($option->{v6only})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $option->{"v6only"}) 1 19 20
582 setsockopt($fh, IPPROTO_IPV6, IPV6_V6ONLY,
583 1 ▶ pack('i', $option->{v6only}))
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $fh, 41, 26, pack("i", $option->{"v6only"}) or _socket_option_error("v6only", 0 + $!) 1 0 1
584 or _socket_option_error('v6only', 0 + $!);
585 }
586 Linux::Event::_SocketConfig::apply_policy($fh, $family, {
587 send_buffer => $option->{send_buffer},
588 receive_buffer => $option->{receive_buffer},
589 20 });
590 20 ▶ Linux::Event::_SocketConfig::bind_device($fh, $bind_device)
Branch: 1 branch
BranchTrueFalseTotal
if defined $bind_device 0 20 20
591 if defined $bind_device;
592 20 return;
593 }
594  
595 10 ▶sub _apply_socket_policy ($self, $fh, $family) {
Subroutine _apply_socket_policy: called CC=1 SCAR=0.0
596 _apply_creation_policy(
597 $fh, $family, $self->{options}, $self->{bind_device},
598 10 );
599 10 return;
600 }
601  
602 22 ▶sub _configure_socket ($self, $fh, $role, $address) {
Subroutine _configure_socket: called CC=4 SCAR=13.9
603 22 my $callback = $self->{descriptor}{callbacks}{configure_socket};
604 22 ▶ return if !$callback;
Branch: 1 branch
BranchTrueFalseTotal
unless $callback 20 2 22
605 2 my $ok = eval { $callback->($self, $fh, $role, $address); 1 };
606 2 ▶ return if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 1 1 2
607 1 my $message = "$@";
608 1 $message =~ s/\s+\z//;
609 1 ▶ die Linux::Event::Error->new(
Condition50%1/2
$message || 'configure_socket callback failed'
l!l
10
MC/DC0%0/1
$message || 'configure_socket callback failed'
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
610 type => 'socket_configuration', operation => 'configure_socket',
611 message => $message || 'configure_socket callback failed',
612 );
613 }
614  
615 17 ▶sub _attach_to_loop ($self, $loop) {
Subroutine _attach_to_loop: called CC=21 SCAR=35.0
616 croak 'add(): Datagram is not unattached'
617 17 ▶ if $self->{state} ne 'unattached' || $self->{loop};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "unattached" or $self->{"loop"} 0 17 17
Condition33%1/3
$self->{"state"} ne "unattached" or $self->{"loop"}
l!l&&r!l&&!r
0017
MC/DC0%0/2
$self->{"state"} ne "unattached" or $self->{"loop"}
$self->{"state"} ne "unattached" $self->{"loop"}
Truth table33%1/3
A or B
A= $self->{"state"} ne "unattached"B= $self->{"loop"}
ABresult
1X1
011
000
618 17 $self->{loop} = $loop;
619 17 ▶ if ($self->{fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fh"}) 10 7 17
620 10 $self->{state} = 'active';
621 10 my $registered = eval {
622 10 $self->_register;
623 9 $self->_schedule_ready;
624 9 1;
625 };
626 10 ▶ if (!$registered) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($registered) 1 9 10
627 1 ▶ my $failure = $@ || 'could not register Datagram socket';
Condition50%1/2
$@ || 'could not register Datagram socket'
l!l
10
MC/DC0%0/1
$@ || 'could not register Datagram socket'
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
628 1 ▶ if (my $timer = delete $self->{ready_timer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $timer = delete $self->{"ready_timer"}) 0 1 1
629 0 ▶ $timer->cancel if !$timer->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $timer->is_terminal 0 0 0
630 }
631 1 ▶ if (my $watcher = delete $self->{watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $self->{"watcher"}) 0 1 1
632 0 $watcher->cancel;
633 }
634 1 $self->{state} = 'unattached';
635 1 $self->{loop} = undef;
636 1 ▶ die $failure if blessed($failure)
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($failure) and $failure->isa("Linux::Event::Error") 0 1 1
Condition33%1/3
builtin::blessed($failure) and $failure->isa("Linux::Event::Error")
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($failure) and $failure->isa("Linux::Event::Error")
builtin::blessed($failure) $failure->isa("Linux::Event::Error")
Truth table33%1/3
A and B
A= builtin::blessed($failure)B= $failure->isa("Linux::Event::Error")
ABresult
0X0
100
111
637 && $failure->isa('Linux::Event::Error');
638 1 die Linux::Event::Error->new(
639 type => 'setup',
640 operation => 'watch',
641 fatal => 0,
642 message => "$failure",
643 );
644 }
645 9 return $self;
646 }
647 7 ▶ if ($self->{needs_resolution}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"needs_resolution"}) 2 5 7
648 2 $self->{state} = 'resolving';
649 2 my ($resolver, $id);
650 2 my $submitted = eval {
651 2 $resolver = Linux::Event::_Resolver->for_loop($loop);
652 2 $self->{resolver} = $resolver;
653 $id = $resolver->submit(
654 2 $self, $self->{host}, $self->{port}, SOCK_DGRAM,
655 );
656 2 1;
657 };
658 2 ▶ if (!$submitted || !$id) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $submitted && $id) { } 0 2 2
Condition33%1/3
$submitted && $id
!ll&&!rl&&r
002
MC/DC0%0/2
$submitted && $id
$submitted $id
Truth table33%1/3
A && B
A= $submittedB= $id
ABresult
0X0
100
111
659 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
660 $self->_fail(Linux::Event::Error->new(
661 type => 'resolve', operation => 'resolve', message => $message,
662 host => $self->{host}, port => $self->{port},
663 0 ));
664 } else {
665 2 $self->{resolver_request} = $id;
666 }
667 2 return $self;
668 }
669 5 my $activated = eval {
670 5 ▶ if ($self->{path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'path'}) { } 1 4 5
671 1 $self->_activate_unix;
672 } else {
673 4 my $packed4 = inet_pton(AF_INET, $self->{host});
674 4 my ($family, $sockaddr);
675 4 ▶ if (defined $packed4) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packed4) { } 4 0 4
676 4 $family = AF_INET;
677 4 $sockaddr = pack_sockaddr_in($self->{port}, $packed4);
678 } else {
679 0 $family = AF_INET6;
680 $sockaddr = pack_sockaddr_in6(
681 0 $self->{port}, inet_pton(AF_INET6, $self->{host}),
682 );
683 }
684 4 $self->_activate_inet_candidate({
685 family => $family, protocol => 0, sockaddr => $sockaddr,
686 });
687 }
688 3 1;
689 };
690 5 ▶ if (!$activated) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($activated) 2 3 5
691 2 my $failure = $@;
692 my $error = blessed($failure)
693 && $failure->isa('Linux::Event::Error')
694 ? $failure
695 : Linux::Event::Error->new(
696 type => 'connect', operation => 'connect',
697 message => "$failure" || 'datagram connection failed',
698 host => $self->{host}, port => $self->{port},
699 path => $self->{path},
700 2 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($failure) && $failure->isa('Linux::Event::Error') ? : 2 0 2
Condition20%1/5
builtin::blessed($failure) and $failure->isa("Linux::Event::Error")
!ll&&!rl&&r
002
"$failure" || 'datagram connection 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" || 'datagram connection 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
701 2 $self->_fail($error);
702 }
703 5 return $self;
704 }
705  
706 2 ▶sub _resolver_completed ($self, $result) {
Subroutine _resolver_completed: called CC=23 SCAR=45.7
707 2 ▶ return if $self->{state} ne 'resolving';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "resolving" 0 2 2
708 return if !defined($self->{resolver_request})
709 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
710 2 delete $self->{resolver_request};
711 2 delete $self->{resolver};
712 2 ▶ if ($result->{error_code}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"error_code"}) 0 2 2
713 $self->_fail(Linux::Event::Error->new(
714 type => 'resolve', operation => 'resolve',
715 errno => $result->{system_errno} || undef,
716 message => $result->{message} || 'hostname resolution failed',
717 resolver_message => $result->{message},
718 host => $self->{host}, port => $self->{port},
719 0 ▶ ));
Condition0%0/4
$result->{'system_errno'} || undef
l!l
00
$result->{'message'} || 'hostname resolution failed'
l!l
00
MC/DC0%0/1
$result->{'system_errno'} || undef
$result->{'system_errno'}
MC/DC0%0/1
$result->{'message'} || 'hostname resolution failed'
$result->{'message'}
Truth table0%0/2
A
A= $result->{'system_errno'}
Aresult
11
00
Truth table0%0/2
A
A= $result->{'message'}
Aresult
11
00
720 0 return;
721 }
722 2 my $last_error;
723 2 my $compatible = 0;
724 2 for my $candidate (@{ $result->{candidates} }) {
725 next if $candidate->{family} != AF_INET
726 3 ▶ && $candidate->{family} != AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->{"family"} != 2 and $candidate->{"family"} != 10 0 3 3
Condition66%2/3
$candidate->{"family"} != 2 and $candidate->{"family"} != 10
!ll&&!rl&&r
120
MC/DC0%0/2
$candidate->{"family"} != 2 and $candidate->{"family"} != 10
$candidate->{"family"} != 2 $candidate->{"family"} != 10
Truth table66%2/3
A and B
A= $candidate->{"family"} != 2B= $candidate->{"family"} != 10
ABresult
0X0
100
111
727 next if defined($self->{required_family})
728 3 ▶ && $candidate->{family} != $self->{required_family};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"required_family"} and $candidate->{"family"} != $self->{"required_family"} 1 2 3
Condition100%3/3
defined $self->{"required_family"} and $candidate->{"family"} != $self->{"required_family"}
!ll&&!rl&&r
111
MC/DC100%2/2
defined $self->{"required_family"} and $candidate->{"family"} != $self->{"required_family"}
defined $self->{"required_family"} $candidate->{"family"} != $self->{"required_family"}
Truth table100%3/3
A and B
A= defined $self->{"required_family"}B= $candidate->{"family"} != $self->{"required_family"}
ABresult
0X0
100
111
729 2 $compatible = 1;
730 2 my $ok = eval { $self->_activate_inet_candidate($candidate); 1 };
731 2 ▶ return if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 1 1 2
732 1 $last_error = $@;
733 1 ▶ if (blessed($last_error)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($last_error) and $last_error->isa("Linux::Event::Error") and $last_error->type eq "socket_configuration" || $last_error->type eq "setup") 1 0 1
Condition33%3/9
builtin::blessed($last_error) and $last_error->isa("Linux::Event::Error") and $last_error->type eq "socket_configuration" || $last_error->type eq "setup"
!ll&&!rl&&r
001
builtin::blessed($last_error) and $last_error->isa("Linux::Event::Error")
!ll&&!rl&&r
001
$last_error->type eq "socket_configuration" or $last_error->type eq "setup"
l!l&&r!l&&!r
100
MC/DC0%0/4
builtin::blessed($last_error) and $last_error->isa("Linux::Event::Error") and $last_error->type eq "socket_configuration" || $last_error->type eq "setup"
builtin::blessed($last_error) $last_error->isa("Linux::Event::Error") $last_error->type eq "socket_configuration" $last_error->type eq "setup"
Truth table20%1/5
A and B and C or D
A= builtin::blessed($last_error)B= $last_error->isa("Linux::Event::Error")C= $last_error->type eq "socket_configuration"D= $last_error->type eq "setup"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
734 && $last_error->isa('Linux::Event::Error')
735 && ($last_error->type eq 'socket_configuration'
736 || $last_error->type eq 'setup')) {
737 1 $self->_fail($last_error);
738 1 return;
739 }
740 }
741 0 ▶ if (defined($self->{required_family}) && !$compatible) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"required_family"} and not $compatible) 0 0 0
Condition0%0/3
defined $self->{"required_family"} and not $compatible
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"required_family"} and not $compatible
defined $self->{"required_family"} not $compatible
Truth table0%0/3
A and not(B)
A= defined $self->{"required_family"}B= not $compatible
ABresult
0X0
100
111
742 0 my $option = $self->{required_family_option};
743 0 ▶ my $message = $option eq 'local_host'
Branch: 1 branch
BranchTrueFalseTotal
$option eq 'local_host' ? : 0 0 0
744 ? 'local_host address family does not match any peer address'
745 : "$option has no compatible peer address";
746 $self->_fail(Linux::Event::Error->new(
747 type => 'socket_configuration', operation => 'bind',
748 option => $option,
749 message => $message,
750 host => $self->{host}, port => $self->{port},
751 0 ));
752 0 return;
753 }
754 $self->_fail(blessed($last_error)
755 && $last_error->isa('Linux::Event::Error')
756 ? $last_error
757 : Linux::Event::Error->new(
758 type => 'connect', operation => 'connect',
759 message => "$last_error" || 'no compatible datagram address',
760 host => $self->{host}, port => $self->{port},
761 0 ▶ ));
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($last_error) && $last_error->isa('Linux::Event::Error') ? : 0 0 0
Condition0%0/5
builtin::blessed($last_error) and $last_error->isa("Linux::Event::Error")
!ll&&!rl&&r
000
"$last_error" || 'no compatible datagram address'
l!l
00
MC/DC0%0/2
builtin::blessed($last_error) and $last_error->isa("Linux::Event::Error")
builtin::blessed($last_error) $last_error->isa("Linux::Event::Error")
MC/DC0%0/1
"$last_error" || 'no compatible datagram address'
"$last_error"
Truth table0%0/3
A and B
A= builtin::blessed($last_error)B= $last_error->isa("Linux::Event::Error")
ABresult
0X0
100
111
Truth table0%0/2
A
A= "$last_error"
Aresult
11
00
762 0 return;
763 }
764  
765 6 ▶sub _activate_inet_candidate ($self, $candidate) {
Subroutine _activate_inet_candidate: called CC=12 SCAR=25.1
766 6 my $fh;
767 socket($fh, $candidate->{family},
768 SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
769 $candidate->{protocol} // 0)
770 or _setup_error('socket', 0 + $!,
771 6 ▶ host => $self->{host}, port => $self->{port});
Branch: 1 branch
BranchTrueFalseTotal
socket $fh, $candidate->{"family"}, 526338, $candidate->{"protocol"} // 0 or _setup_error("socket", 0 + $!, "host", $self->{"host"}, "port", $self->{"port"}) 6 0 6
Condition50%1/2
$candidate->{"protocol"} // 0
l!l
60
MC/DC0%0/1
$candidate->{"protocol"} // 0
$candidate->{"protocol"}
Truth table50%1/2
A
A= $candidate->{"protocol"}
Aresult
11
00
772 6 my $ok = eval {
773 6 $self->_apply_socket_policy($fh, $candidate->{family});
774 $self->_configure_socket(
775 6 $fh, 'connect', Linux::Event::Address->new($candidate->{sockaddr}),
776 );
777 5 ▶ if ($self->{local_bind}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"local_bind"}) 3 2 5
778 3 my $packed;
779 3 ▶ if (defined $self->{local_host}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'local_host'}) { } 2 1 3
780 2 $packed = inet_pton($candidate->{family}, $self->{local_host});
781 2 ▶ die Linux::Event::Error->new(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 1 1 2
782 type => 'socket_configuration', operation => 'bind',
783 option => 'local_host',
784 message => 'local_host address family does not match peer',
785 ) if !defined $packed;
786 } else {
787 $packed = inet_pton(
788 $candidate->{family},
789 1 ▶ $candidate->{family} == AF_INET ? '0.0.0.0' : '::',
Branch: 1 branch
BranchTrueFalseTotal
$candidate->{'family'} == 2 ? : 1 0 1
790 );
791 }
792 my $local = $candidate->{family} == AF_INET
793 ? pack_sockaddr_in($self->{local_port}, $packed)
794 2 ▶ : pack_sockaddr_in6($self->{local_port}, $packed);
Branch: 1 branch
BranchTrueFalseTotal
$candidate->{'family'} == 2 ? : 2 0 2
795 2 ▶ if (!bind($fh, $local)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (bind $fh, $local) 1 1 2
796 1 my $errno = 0 + $!;
797 die Linux::Event::Error->new(
798 type => 'socket_configuration',
799 operation => 'bind',
800 option => defined($self->{local_host})
801 ? 'local_host' : 'local_port',
802 errno => $errno,
803 message => _message($errno),
804 host => $self->{local_host},
805 port => $self->{local_port},
806 1 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'local_host'} ? : 0 1 1
807 }
808 }
809 CORE::connect($fh, $candidate->{sockaddr})
810 or _setup_error('connect', 0 + $!,
811 3 ▶ host => $self->{host}, port => $self->{port});
Branch: 1 branch
BranchTrueFalseTotal
CORE::connect $fh, $candidate->{"sockaddr"} or _setup_error("connect", 0 + $!, "host", $self->{"host"}, "port", $self->{"port"}) 3 0 3
812 3 1;
813 };
814 6 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 3 3 6
815 3 my $failure = $@;
816 3 close $fh;
817 3 die $failure;
818 }
819 3 $self->_finish_activation($fh, $candidate->{family});
820 3 return;
821 }
822  
823 1 ▶sub _activate_unix ($self) {
Subroutine _activate_unix: called CC=13 SCAR=36.7
824 1 my $fh;
825 socket($fh, AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)
826 1 ▶ or _setup_error('socket', 0 + $!, path => $self->{path});
Branch: 1 branch
BranchTrueFalseTotal
socket $fh, 1, 526338, 0 or _setup_error("socket", 0 + $!, "path", $self->{"path"}) 1 0 1
827 1 my $ok = eval {
828 1 $self->_apply_socket_policy($fh, AF_UNIX);
829 $self->_configure_socket(
830 $fh, 'connect', Linux::Event::Address->new(
831 1 pack_sockaddr_un($self->{path}),
832 ),
833 );
834 1 ▶ if (defined $self->{local_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"local_path"}) 1 0 1
835 1 _prepare_unix_path($self->{local_path}, $self->{unlink_existing});
836 bind($fh, pack_sockaddr_un($self->{local_path}))
837 1 ▶ or _setup_error('bind', 0 + $!, path => $self->{local_path});
Branch: 1 branch
BranchTrueFalseTotal
bind $fh, pack_sockaddr_un($self->{"local_path"}) or _setup_error("bind", 0 + $!, "path", $self->{"local_path"}) 1 0 1
838 chmod($self->{permissions}, $self->{local_path})
839 or _setup_error('chmod', 0 + $!, path => $self->{local_path})
840 1 ▶ if defined $self->{permissions};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"permissions"} 0 1 1
Condition16%1/6
defined $self->{'permissions'} && (chmod($self->{'permissions'}, $self->{'local_path'}) || _setup_error('chmod', 0 + $!, 'path', $self->{'local_path'}))
!ll&&!rl&&r
100
chmod $self->{"permissions"}, $self->{"local_path"} or _setup_error("chmod", 0 + $!, "path", $self->{"local_path"})
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $self->{'permissions'} && (chmod($self->{'permissions'}, $self->{'local_path'}) || _setup_error('chmod', 0 + $!, 'path', $self->{'local_path'}))
defined $self->{'permissions'} chmod $self->{"permissions"}, $self->{"local_path"} _setup_error("chmod", 0 + $!, "path", $self->{"local_path"})
Truth table0%0/4
A && B or C
A= defined $self->{'permissions'}B= chmod $self->{"permissions"}, $self->{"local_path"}C= _setup_error("chmod", 0 + $!, "path", $self->{"local_path"})
ABCresult
0XX0
1000
11X1
1011
841 }
842 CORE::connect($fh, pack_sockaddr_un($self->{path}))
843 1 ▶ or _setup_error('connect', 0 + $!, path => $self->{path});
Branch: 1 branch
BranchTrueFalseTotal
CORE::connect $fh, pack_sockaddr_un($self->{"path"}) or _setup_error("connect", 0 + $!, "path", $self->{"path"}) 1 0 1
844 1 1;
845 };
846 1 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 1 1
847 0 my $failure = $@;
848 0 close $fh;
849 unlink $self->{local_path}
850 0 ▶ if defined($self->{local_path}) && -S $self->{local_path};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"local_path"} and -S $self->{"local_path"} 0 0 0
Condition0%0/3
defined $self->{"local_path"} and -S $self->{"local_path"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"local_path"} and -S $self->{"local_path"}
defined $self->{"local_path"} -S $self->{"local_path"}
Truth table0%0/3
A and B
A= defined $self->{"local_path"}B= -S $self->{"local_path"}
ABresult
0X0
100
111
851 0 die $failure;
852 }
853 1 my $activated = eval { $self->_finish_activation($fh, AF_UNIX); 1 };
854 1 ▶ if (!$activated) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($activated) 0 1 1
855 0 my $failure = $@;
856 unlink $self->{local_path}
857 0 ▶ if defined($self->{local_path}) && -S $self->{local_path};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"local_path"} and -S $self->{"local_path"} 0 0 0
Condition0%0/3
defined $self->{"local_path"} and -S $self->{"local_path"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"local_path"} and -S $self->{"local_path"}
defined $self->{"local_path"} -S $self->{"local_path"}
Truth table0%0/3
A and B
A= defined $self->{"local_path"}B= -S $self->{"local_path"}
ABresult
0X0
100
111
858 0 die $failure;
859 }
860 1 return;
861 }
862  
863 4 ▶sub _finish_activation ($self, $fh, $family) {
Subroutine _finish_activation: called CC=9 SCAR=35.5
864 4 my $previous_state = $self->{state};
865 4 $self->{fh} = $fh;
866 4 $self->{family_number} = $family;
867 4 my $activated = eval {
868 4 $self->{local} = Linux::Event::Address->new(getsockname($fh));
869 4 $self->{peer} = Linux::Event::Address->new(getpeername($fh));
870 4 $self->{state} = 'active';
871 4 $self->_register;
872 4 $self->_schedule_ready;
873 4 $self->_flush_output;
874 4 1;
875 };
876 4 ▶ return if $activated;
Branch: 1 branch
BranchTrueFalseTotal
if $activated 4 0 4
877  
878 0 ▶ my $failure = $@ || 'could not register Datagram socket';
Condition0%0/2
$@ || 'could not register Datagram socket'
l!l
00
MC/DC0%0/1
$@ || 'could not register Datagram socket'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
879 0 ▶ if (my $timer = delete $self->{ready_timer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $timer = delete $self->{"ready_timer"}) 0 0 0
880 0 ▶ $timer->cancel if $timer->is_active;
Branch: 1 branch
BranchTrueFalseTotal
if $timer->is_active 0 0 0
881 }
882 0 ▶ if (my $watcher = delete $self->{watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $self->{"watcher"}) 0 0 0
883 0 $watcher->cancel;
884 }
885 0 ▶ close delete $self->{fh} if $self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"fh"} 0 0 0
886 0 $self->{family_number} = undef;
887 0 $self->{local} = undef;
888 0 $self->{peer} = undef;
889 0 $self->{state} = $previous_state;
890 0 ▶ die $failure if blessed($failure)
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($failure) and $failure->isa("Linux::Event::Error") 0 0 0
Condition0%0/3
builtin::blessed($failure) and $failure->isa("Linux::Event::Error")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($failure) and $failure->isa("Linux::Event::Error")
builtin::blessed($failure) $failure->isa("Linux::Event::Error")
Truth table0%0/3
A and B
A= builtin::blessed($failure)B= $failure->isa("Linux::Event::Error")
ABresult
0X0
100
111
891 && $failure->isa('Linux::Event::Error');
892 0 die Linux::Event::Error->new(
893 type => 'setup', operation => 'watch', fatal => 1,
894 message => "$failure",
895 );
896 }
897  
898 14 ▶sub _register ($self) {
Subroutine _register: called CC=5 SCAR=17.0
899 14 ▶ return if !$self->{loop} || !$self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"loop"} and $self->{"fh"} 0 14 14
Condition33%1/3
$self->{"loop"} and $self->{"fh"}
!ll&&!rl&&r
0014
MC/DC0%0/2
$self->{"loop"} and $self->{"fh"}
$self->{"loop"} $self->{"fh"}
Truth table33%1/3
A and B
A= $self->{"loop"}B= $self->{"fh"}
ABresult
0X0
100
111
900 $self->{watcher} = $self->{loop}->watch(
901 fh => $self->{fh}, _internal => 1, data => $self,
902 read => \&_read_ready, write => \&_write_ready,
903 error => \&_error_ready,
904 edge_triggered => $self->{options}{edge_triggered},
905 14 _callback_data_arg => 1,
906 );
907 13 ▶ $self->{watcher}->disable_write if !@{ $self->{queue} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"queue"};} 12 1 13
908 13 ▶ $self->{watcher}->disable_read if $self->{read_paused};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"read_paused"} 0 13 13
909 13 return;
910 }
911  
912 13 ▶sub _schedule_ready ($self) {
Subroutine _schedule_ready: called CC=3 SCAR=11.8
913 13 ▶ return if $self->{ready_fired} || !$self->{loop};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ready_fired"} or not $self->{"loop"} 0 13 13
Condition33%1/3
$self->{"ready_fired"} or not $self->{"loop"}
l!l&&r!l&&!r
0013
MC/DC0%0/2
$self->{"ready_fired"} or not $self->{"loop"}
$self->{"ready_fired"} not $self->{"loop"}
Truth table33%1/3
A or not(B)
A= $self->{"ready_fired"}B= not $self->{"loop"}
ABresult
1X1
011
000
914 13 my $timer = Linux::Event::Datagram::_ReadyTimer->new(
915 after => 0, data => $self,
916 );
917 13 $self->{ready_timer} = $timer;
918 13 $self->{loop}->add($timer);
919 13 return;
920 }
921  
922 7 ▶sub _fire_ready ($self) {
Subroutine _fire_ready: called CC=4 SCAR=14.5
923 7 delete $self->{ready_timer};
924 7 ▶ return if $self->{state} ne 'active' || $self->{ready_fired}++;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "active" or $self->{"ready_fired"}++ 0 7 7
Condition33%1/3
$self->{"state"} ne "active" or $self->{"ready_fired"}++
l!l&&r!l&&!r
007
MC/DC0%0/2
$self->{"state"} ne "active" or $self->{"ready_fired"}++
$self->{"state"} ne "active" $self->{"ready_fired"}++
Truth table33%1/3
A or B
A= $self->{"state"} ne "active"B= $self->{"ready_fired"}++
ABresult
1X1
011
000
925 7 my $callback = $self->{descriptor}{callbacks}{on_ready};
926 7 ▶ $callback->($self) if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 3 4 7
927 7 return;
928 }
929  
930 5 ▶sub _report ($self, $error) {
Subroutine _report: called CC=2 SCAR=7.4
931 5 $self->{last_error} = $error;
932 5 ▶ if (my $callback = $self->{descriptor}{callbacks}{on_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $callback = $self->{'descriptor'}{'callbacks'}{'on_error'}) { } 5 0 5
933 5 $callback->($self, $error);
934 } else {
935 0 warn "$error\n";
936 }
937 5 return;
938 }
939  
940 3 ▶sub _fail ($self, $error) {
Subroutine _fail: called CC=3 SCAR=11.1
941 3 ▶ return if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 3 3
942 3 $self->{last_error} = $error;
943 3 $self->_shutdown('failed', 0, 1);
944 3 my $reported = eval { $self->_report($error); 1 };
945 3 my $failure = $@;
946 3 $self->{loop} = undef;
947 3 ▶ die $failure if !$reported;
Branch: 1 branch
BranchTrueFalseTotal
unless $reported 0 3 3
948 3 return;
949 }
950  
951 83 ▶sub _read_ready ($self) {
Subroutine _read_ready: called CC=9 SCAR=24.2
952 83 ▶ return if $self->{state} ne 'active' || $self->{read_paused};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "active" or $self->{"read_paused"} 0 83 83
Condition33%1/3
$self->{"state"} ne "active" or $self->{"read_paused"}
l!l&&r!l&&!r
0083
MC/DC0%0/2
$self->{"state"} ne "active" or $self->{"read_paused"}
$self->{"state"} ne "active" $self->{"read_paused"}
Truth table33%1/3
A or B
A= $self->{"state"} ne "active"B= $self->{"read_paused"}
ABresult
1X1
011
000
953 my $batch = Linux::Event::Datagram::_recv_batch(
954 fileno($self->{fh}), $self->{options}{max_datagram_size},
955 $self->{options}{max_datagrams_per_tick},
956 83 );
957 83 my $errno = $batch->[0];
958 83 ▶ for (my $at = 1; $at < @$batch; $at += 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at < @$batch) 85 83 168
959 85 ▶ last if $self->{state} ne 'active' || $self->{read_paused};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "active" or $self->{"read_paused"} 0 85 85
Condition33%1/3
$self->{"state"} ne "active" or $self->{"read_paused"}
l!l&&r!l&&!r
0085
MC/DC0%0/2
$self->{"state"} ne "active" or $self->{"read_paused"}
$self->{"state"} ne "active" $self->{"read_paused"}
Truth table33%1/3
A or B
A= $self->{"state"} ne "active"B= $self->{"read_paused"}
ABresult
1X1
011
000
960 85 my ($payload, $sockaddr, $length, $truncated)
961 = @$batch[$at .. $at + 3];
962 85 my $peer = Linux::Event::Address->new($sockaddr);
963 85 ▶ if ($truncated) {
Branch: 1 branch
BranchTrueFalseTotal
if ($truncated) 1 84 85
964 $self->_report(Linux::Event::Error->new(
965 type => 'datagram_size', operation => 'receive',
966 message => "received datagram exceeds "
967 . "$self->{options}{max_datagram_size} bytes",
968 datagram_size => $length,
969 limit => $self->{options}{max_datagram_size},
970 1 ));
971 1 next;
972 }
973 84 $self->{descriptor}{callbacks}{on_datagram}->($self, $payload, $peer);
974 }
975 83 ▶ if ($errno && $self->{state} eq 'active') {
Branch: 1 branch
BranchTrueFalseTotal
if ($errno and $self->{"state"} eq "active") 0 83 83
Condition33%1/3
$errno and $self->{"state"} eq "active"
!ll&&!rl&&r
8300
MC/DC0%0/2
$errno and $self->{"state"} eq "active"
$errno $self->{"state"} eq "active"
Truth table33%1/3
A and B
A= $errnoB= $self->{"state"} eq "active"
ABresult
0X0
100
111
976 0 $self->_report(Linux::Event::Error->new(
977 type => 'io', operation => 'receive', errno => $errno,
978 message => _message($errno),
979 ));
980 }
981 83 return;
982 }
983  
984 87 ▶sub send ($self, $payload, %option) {
Subroutine send: called CC=23 SCAR=41.4
Pod documented
985 87 ▶ croak 'send(): Datagram is terminal' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 87 87
986 87 ▶ croak 'send(): payload must be a defined scalar'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $payload or ref $payload 0 87 87
Condition33%1/3
not defined $payload or ref $payload
l!l&&r!l&&!r
0087
MC/DC0%0/2
not defined $payload or ref $payload
not defined $payload ref $payload
Truth table33%1/3
not(A) or B
A= not defined $payloadB= ref $payload
ABresult
1X1
011
000
987 if !defined($payload) || ref($payload);
988 87 $payload = "$payload";
989 87 ▶ croak 'send(): payload must be a byte string'
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($payload, 1) 1 86 87
990 if !utf8::downgrade($payload, 1);
991 croak "send(): payload exceeds $self->{options}{max_datagram_size} bytes"
992 86 ▶ if length($payload) > $self->{options}{max_datagram_size};
Branch: 1 branch
BranchTrueFalseTotal
if length $payload > $self->{"options"}{"max_datagram_size"} 0 86 86
993 86 my $to = delete $option{to};
994 86 ▶ croak 'send(): unknown options: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 86 86
995 if %option;
996 86 ▶ if ($self->{connected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'connected'}) { } 24 62 86
997 24 ▶ croak 'send(): to is not valid for a connected Datagram'
Branch: 1 branch
BranchTrueFalseTotal
if defined $to 0 24 24
998 if defined $to;
999 } else {
1000 62 ▶ croak 'send(): to requires a Linux::Event::Address'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($to) and $to->isa("Linux::Event::Address") 0 62 62
Condition33%1/3
builtin::blessed($to) and $to->isa("Linux::Event::Address")
!ll&&!rl&&r
0062
MC/DC0%0/2
builtin::blessed($to) and $to->isa("Linux::Event::Address")
builtin::blessed($to) $to->isa("Linux::Event::Address")
Truth table33%1/3
A and B
A= builtin::blessed($to)B= $to->isa("Linux::Event::Address")
ABresult
0X0
100
111
1001 if !blessed($to) || !$to->isa('Linux::Event::Address');
1002 }
1003 86 ▶ my $address = defined($to) ? $to->sockaddr : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $to ? : 62 24 86
1004 86 ▶ croak 'send(): destination Address has no packed socket address'
Branch: 1 branch
BranchTrueFalseTotal
if defined $to and !defined($address) || ref $address 0 86 86
Condition50%3/6
defined $to and !defined($address) || ref $address
!ll&&!rl&&r
24620
not defined $address or ref $address
l!l&&r!l&&!r
0062
MC/DC0%0/3
defined $to and !defined($address) || ref $address
defined $to not defined $address ref $address
Truth table50%2/4
A and not(B) or C
A= defined $toB= not defined $addressC= ref $address
ABCresult
0XX0
1000
11X1
1011
1005 if defined($to) && (!defined($address) || ref($address));
1006 return $self->_queue_packet($payload, $address)
1007 86 ▶ if !$self->{fh} || @{ $self->{queue} };
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"fh"} or @{$self->{"queue"};} 2 84 86
Condition66%2/3
not $self->{"fh"} or @{$self->{"queue"};}
l!l&&r!l&&!r
2084
MC/DC50%1/2
not $self->{"fh"} or @{$self->{"queue"};}
not $self->{"fh"} @{$self->{"queue"};}
Truth table66%2/3
not(A) or B
A= not $self->{"fh"}B= @{$self->{"queue"};}
ABresult
1X1
011
000
1008 my ($sent, $errno) = Linux::Event::Datagram::_send_packet(
1009 84 ▶ fileno($self->{fh}), $payload,
Branch: 1 branch
BranchTrueFalseTotal
defined $address ? : 62 22 84
1010 defined($address) ? $address : undef,
1011 );
1012 84 ▶ return 1 if $sent == length($payload);
Branch: 1 branch
BranchTrueFalseTotal
if $sent == length $payload 84 0 84
1013 0 ▶ if ($errno == Errno::EAGAIN() || $errno == Errno::EWOULDBLOCK()
Branch: 1 branch
BranchTrueFalseTotal
if ($errno == 11 or $errno == 11 or $errno == 105) 0 0 0
Condition0%0/6
$errno == 11 or $errno == 11 or $errno == 105
l!l&&r!l&&!r
000
$errno == 11 or $errno == 11
l!l&&r!l&&!r
000
MC/DC0%0/3
$errno == 11 or $errno == 11 or $errno == 105
$errno == 11 $errno == 11 $errno == 105
Truth table0%0/4
A or B or C
A= $errno == 11B= $errno == 11C= $errno == 105
ABCresult
1XX1
01X1
0011
0000
1014 || $errno == Errno::ENOBUFS()) {
1015 0 return $self->_queue_packet($payload, $address);
1016 }
1017 0 ▶ $self->_report(Linux::Event::Error->new(
Branch: 1 branch
BranchTrueFalseTotal
$errno ? : 0 0 0
1018 type => 'io', operation => 'send', errno => $errno,
1019 message => $errno ? _message($errno)
1020 : "short datagram send ($sent of " . length($payload) . ' bytes)',
1021 ));
1022 0 return undef;
1023 }
1024  
1025 2 ▶sub _queue_packet ($self, $payload, $address) {
Subroutine _queue_packet: called CC=10 SCAR=25.2
1026 2 my $bytes = $self->{pending_bytes} + length($payload);
1027 2 my $datagrams = @{ $self->{queue} } + 1;
1028 2 my $byte_limit = $self->{options}{max_pending_bytes};
1029 2 my $packet_limit = $self->{options}{max_pending_datagrams};
1030 2 ▶ if (($byte_limit && $bytes > $byte_limit)
Branch: 1 branch
BranchTrueFalseTotal
if ($byte_limit and $bytes > $byte_limit or $packet_limit and $datagrams > $packet_limit) 1 1 2
Condition55%5/9
$byte_limit and $bytes > $byte_limit or $packet_limit and $datagrams > $packet_limit
l!l&&r!l&&!r
101
$byte_limit and $bytes > $byte_limit
!ll&&!rl&&r
011
$packet_limit and $datagrams > $packet_limit
!ll&&!rl&&r
010
MC/DC25%1/4
$byte_limit and $bytes > $byte_limit or $packet_limit and $datagrams > $packet_limit
$byte_limit $bytes > $byte_limit $packet_limit $datagrams > $packet_limit
Truth table28%2/7
A and B or C and D
A= $byte_limitB= $bytes > $byte_limitC= $packet_limitD= $datagrams > $packet_limit
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1031 || ($packet_limit && $datagrams > $packet_limit)) {
1032 1 ▶ my $limit = $byte_limit && $bytes > $byte_limit
Branch: 1 branch
BranchTrueFalseTotal
$byte_limit && $bytes > $byte_limit ? : 1 0 1
Condition33%1/3
$byte_limit and $bytes > $byte_limit
!ll&&!rl&&r
001
MC/DC0%0/2
$byte_limit and $bytes > $byte_limit
$byte_limit $bytes > $byte_limit
Truth table33%1/3
A and B
A= $byte_limitB= $bytes > $byte_limit
ABresult
0X0
100
111
1033 ? $byte_limit : $packet_limit;
1034 1 $self->_report(Linux::Event::Error->new(
1035 type => 'output_limit', operation => 'send',
1036 message => 'pending datagram output limit would be exceeded',
1037 pending_bytes => $bytes,
1038 pending_datagrams => $datagrams,
1039 limit => $limit,
1040 ));
1041 1 return undef;
1042 }
1043 1 push @{ $self->{queue} }, [$payload, $address];
1044 1 $self->{pending_bytes} = $bytes;
1045 1 ▶ if ($bytes > $self->{options}{high_watermark}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes > $self->{"options"}{"high_watermark"}) 0 1 1
1046 0 $self->{above_high} = 1;
1047 }
1048 1 ▶ $self->{watcher}->enable_write if $self->{watcher};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"watcher"} 0 1 1
1049 1 ▶ return $self->{above_high} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'above_high'} ? : 0 1 1
1050 }
1051  
1052 0 ▶sub _write_ready ($self) {
Subroutine _write_ready: not called CC=2 SCAR=17.9
1053 0 ▶ return if $self->{state} ne 'active';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "active" 0 0 0
1054 0 $self->_flush_output;
1055 0 return;
1056 }
1057  
1058 4 ▶sub _flush_output ($self) {
Subroutine _flush_output: called CC=15 SCAR=41.2
1059 4 ▶ return if !$self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"fh"} 0 4 4
1060 4 ▶ while (my $packet = $self->{queue}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $packet = $self->{"queue"}[0]) 1 4 5
1061 1 my ($payload, $address) = @$packet;
1062 my ($sent, $errno) = Linux::Event::Datagram::_send_packet(
1063 1 ▶ fileno($self->{fh}), $payload,
Branch: 1 branch
BranchTrueFalseTotal
defined $address ? : 0 1 1
1064 defined($address) ? $address : undef,
1065 );
1066 1 ▶ if ($sent == length($payload)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sent == length $payload) 1 0 1
1067 1 shift @{ $self->{queue} };
1068 1 $self->{pending_bytes} -= length($payload);
1069 1 next;
1070 }
1071 0 ▶ last if $errno == Errno::EAGAIN() || $errno == Errno::EWOULDBLOCK()
Branch: 1 branch
BranchTrueFalseTotal
if $errno == 11 or $errno == 11 or $errno == 105 0 0 0
Condition0%0/6
$errno == 11 or $errno == 11 or $errno == 105
l!l&&r!l&&!r
000
$errno == 11 or $errno == 11
l!l&&r!l&&!r
000
MC/DC0%0/3
$errno == 11 or $errno == 11 or $errno == 105
$errno == 11 $errno == 11 $errno == 105
Truth table0%0/4
A or B or C
A= $errno == 11B= $errno == 11C= $errno == 105
ABCresult
1XX1
01X1
0011
0000
1072 || $errno == Errno::ENOBUFS();
1073 0 shift @{ $self->{queue} };
1074 0 $self->{pending_bytes} -= length($payload);
1075 0 ▶ $self->_report(Linux::Event::Error->new(
Branch: 1 branch
BranchTrueFalseTotal
$errno ? : 0 0 0
1076 type => 'io', operation => 'send', errno => $errno,
1077 message => $errno ? _message($errno)
1078 : "short datagram send ($sent of "
1079 . length($payload) . ' bytes)',
1080 ));
1081 0 ▶ last if $self->{state} ne 'active';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "active" 0 0 0
1082 }
1083 $self->{watcher}->disable_write
1084 4 ▶ if $self->{watcher} && !@{ $self->{queue} };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"watcher"} and not @{$self->{"queue"};} 4 0 4
Condition33%1/3
$self->{"watcher"} and not @{$self->{"queue"};}
!ll&&!rl&&r
004
MC/DC0%0/2
$self->{"watcher"} and not @{$self->{"queue"};}
$self->{"watcher"} not @{$self->{"queue"};}
Truth table33%1/3
A and not(B)
A= $self->{"watcher"}B= not @{$self->{"queue"};}
ABresult
0X0
100
111
1085 4 ▶ if ($self->{above_high}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"above_high"} and $self->{"pending_bytes"} <= $self->{"options"}{"low_watermark"}) 0 4 4
Condition33%1/3
$self->{"above_high"} and $self->{"pending_bytes"} <= $self->{"options"}{"low_watermark"}
!ll&&!rl&&r
400
MC/DC0%0/2
$self->{"above_high"} and $self->{"pending_bytes"} <= $self->{"options"}{"low_watermark"}
$self->{"above_high"} $self->{"pending_bytes"} <= $self->{"options"}{"low_watermark"}
Truth table33%1/3
A and B
A= $self->{"above_high"}B= $self->{"pending_bytes"} <= $self->{"options"}{"low_watermark"}
ABresult
0X0
100
111
1086 && $self->{pending_bytes} <= $self->{options}{low_watermark}) {
1087 0 $self->{above_high} = 0;
1088 0 my $callback = $self->{descriptor}{callbacks}{on_drain};
1089 0 ▶ $callback->($self) if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 0 0 0
1090 }
1091 4 return;
1092 }
1093  
1094 0 ▶sub _error_ready ($self) {
Subroutine _error_ready: not called CC=6 SCAR=37.4
1095 0 ▶ return if $self->{state} ne 'active';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "active" 0 0 0
1096 0 my $packed = getsockopt($self->{fh}, SOL_SOCKET, SO_ERROR);
1097 0 ▶ my $errno = defined($packed) && length($packed) >= 4
Branch: 1 branch
BranchTrueFalseTotal
defined $packed && length $packed >= 4 ? : 0 0 0
Condition0%0/3
defined $packed and length $packed >= 4
!ll&&!rl&&r
000
MC/DC0%0/2
defined $packed and length $packed >= 4
defined $packed length $packed >= 4
Truth table0%0/3
A and B
A= defined $packedB= length $packed >= 4
ABresult
0X0
100
111
1098 ? unpack('i', $packed) : 0 + $!;
1099 0 ▶ $self->_report(Linux::Event::Error->new(
Branch: 1 branch
BranchTrueFalseTotal
$errno ? : 0 0 0
Condition0%0/2
$errno || undef
l!l
00
MC/DC0%0/1
$errno || undef
$errno
Truth table0%0/2
A
A= $errno
Aresult
11
00
1100 type => 'io', operation => 'socket', errno => $errno || undef,
1101 message => $errno ? _message($errno) : 'datagram socket error',
1102 ));
1103 0 return;
1104 }
1105  
1106 24 ▶sub _shutdown ($self, $state, $fire_close = 1, $retain_loop = 0) {
Subroutine _shutdown: called CC=19 SCAR=29.6
1107 24 ▶ return if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 1 23 24
1108 23 $self->{state} = $state;
1109 23 my $request = delete $self->{resolver_request};
1110 23 my $resolver = delete $self->{resolver};
1111 23 ▶ $resolver->cancel($request) if $resolver && defined $request;
Branch: 1 branch
BranchTrueFalseTotal
if $resolver and defined $request 0 23 23
Condition33%1/3
$resolver and defined $request
!ll&&!rl&&r
2300
MC/DC0%0/2
$resolver and defined $request
$resolver defined $request
Truth table33%1/3
A and B
A= $resolverB= defined $request
ABresult
0X0
100
111
1112 23 ▶ if (my $timer = delete $self->{ready_timer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $timer = delete $self->{"ready_timer"}) 6 17 23
1113 6 ▶ $timer->cancel if $timer->is_active;
Branch: 1 branch
BranchTrueFalseTotal
if $timer->is_active 6 0 6
1114 }
1115 23 ▶ if (my $watcher = delete $self->{watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $self->{"watcher"}) 13 10 23
1116 13 $watcher->cancel;
1117 }
1118 23 ▶ if (my $fh = delete $self->{fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = delete $self->{"fh"}) 19 4 23
1119 19 ▶ close $fh if $self->{owns_socket};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"owns_socket"} 17 2 19
1120 }
1121 my $remove_path = $self->{connected}
1122 23 ▶ ? $self->{local_path} : $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'connected'} ? : 8 15 23
1123 unlink $remove_path if $self->{unlink_on_close}
1124 23 ▶ && defined($remove_path) && -S $remove_path;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"unlink_on_close"} and defined $remove_path and -S $remove_path 3 20 23
Condition83%5/6
$self->{"unlink_on_close"} and defined $remove_path and -S $remove_path
!ll&&!rl&&r
2003
$self->{"unlink_on_close"} and defined $remove_path
!ll&&!rl&&r
1193
MC/DC66%2/3
$self->{"unlink_on_close"} and defined $remove_path and -S $remove_path
$self->{"unlink_on_close"} defined $remove_path -S $remove_path
Truth table75%3/4
A and B and C
A= $self->{"unlink_on_close"}B= defined $remove_pathC= -S $remove_path
ABCresult
0XX0
10X0
1100
1111
1125 23 $self->{queue} = [];
1126 23 $self->{pending_bytes} = 0;
1127 23 my ($called, $failure) = (1, undef);
1128 23 ▶ if ($fire_close && (my $callback = $self->{descriptor}{callbacks}{on_close})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fire_close and my $callback = $self->{"descriptor"}{"callbacks"}{"on_close"}) 5 18 23
Condition100%3/3
$fire_close and my $callback = $self->{"descriptor"}{"callbacks"}{"on_close"}
!ll&&!rl&&r
4145
MC/DC100%2/2
$fire_close and my $callback = $self->{"descriptor"}{"callbacks"}{"on_close"}
$fire_close my $callback = $self->{"descriptor"}{"callbacks"}{"on_close"}
Truth table100%3/3
A and B
A= $fire_closeB= my $callback = $self->{"descriptor"}{"callbacks"}{"on_close"}
ABresult
0X0
100
111
1129 5 $called = eval { $callback->($self); 1 };
1130 5 $failure = $@;
1131 }
1132 23 ▶ $self->{loop} = undef if !$retain_loop;
Branch: 1 branch
BranchTrueFalseTotal
unless $retain_loop 20 3 23
1133 23 ▶ die $failure if !$called;
Branch: 1 branch
BranchTrueFalseTotal
unless $called 0 23 23
1134 23 return;
1135 }
1136  
1137 20 ▶sub close ($self) {
Subroutine close: called CC=1 SCAR=0.0
Pod documented
1138 20 $self->_shutdown('closed');
1139 20 return $self;
1140 }
1141  
1142 1 ▶sub detach ($self) {
Subroutine detach: called CC=2 SCAR=7.0
Pod documented
1143 1 ▶ croak 'detach(): Datagram has no active socket' if !$self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"fh"} 0 1 1
1144 1 my $fh = $self->{fh};
1145 1 $self->{owns_socket} = 0;
1146 1 $self->{unlink_on_close} = 0;
1147 1 $self->_shutdown('detached', 0);
1148 1 return $fh;
1149 }
1150  
1151 1 ▶sub pause_read ($self) {
Subroutine pause_read: called CC=3 SCAR=11.4
Pod documented
1152 1 ▶ return $self if $self->{read_paused};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"read_paused"} 0 1 1
1153 1 $self->{read_paused} = 1;
1154 1 ▶ $self->{watcher}->disable_read if $self->{watcher};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"watcher"} 1 0 1
1155 1 return $self;
1156 }
1157  
1158 1 ▶sub resume_read ($self) {
Subroutine resume_read: called CC=3 SCAR=11.4
Pod documented
1159 1 ▶ return $self if !$self->{read_paused};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"read_paused"} 0 1 1
1160 1 $self->{read_paused} = 0;
1161 1 ▶ $self->{watcher}->enable_read if $self->{watcher};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"watcher"} 1 0 1
1162 1 return $self;
1163 }
1164  
1165 2 ▶sub _buffer_option ($self, $name, @argument) {
Subroutine _buffer_option: called CC=4 SCAR=14.9
1166 2 ▶ croak "$name(): Datagram has no active socket" if !$self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"fh"} 0 2 2
1167 2 ▶ croak "$name(): expected zero or one argument" if @argument > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @argument > 1 0 2 2
1168 Linux::Event::_SocketConfig::set_option(
1169 2 ▶ $self->{fh}, $self->{family_number}, $name, $argument[0],
Branch: 1 branch
BranchTrueFalseTotal
if @argument 2 0 2
1170 ) if @argument;
1171 return Linux::Event::_SocketConfig::get_option(
1172 2 $self->{fh}, $self->{family_number}, $name,
1173 );
1174 }
1175  
1176 1 ▶sub send_buffer ($self, @argument) {
Subroutine send_buffer: called CC=1 SCAR=0.0
Pod documented
1177 1 return $self->_buffer_option('send_buffer', @argument);
1178 }
1179 1 ▶sub receive_buffer ($self, @argument) {
Subroutine receive_buffer: called CC=1 SCAR=0.0
Pod documented
1180 1 return $self->_buffer_option('receive_buffer', @argument);
1181 }
1182  
1183 3 ▶sub broadcast ($self, @argument) {
Subroutine broadcast: called CC=9 SCAR=23.1
Pod documented
1184 3 ▶ croak 'broadcast(): Datagram has no active socket' if !$self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"fh"} 0 3 3
1185 3 ▶ croak 'broadcast(): expected zero or one argument' if @argument > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @argument > 1 0 3 3
1186 _socket_option_error(
1187 'broadcast', 0, 'broadcast is valid only for IPv4 sockets',
1188 @argument ? 'setsockopt' : 'getsockopt',
1189 3 ▶ ) if $self->{family_number} != AF_INET;
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"family_number"} != 2 1 2 3
@argument ? : 0 1 1
1190 2 ▶ if (@argument) {
Branch: 1 branch
BranchTrueFalseTotal
if (@argument) 2 0 2
1191 2 my $value = _boolean('broadcast():', 'value', $argument[0]);
1192 2 ▶ setsockopt($self->{fh}, SOL_SOCKET, SO_BROADCAST, pack('i', $value))
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $self->{"fh"}, 1, 6, pack("i", $value) or die "Linux::Event::Error"->new("type", "socket_configuration", "operation", "setsockopt", "option", "broadcast", "errno", 0 + $!, "message", _message(0 + $!)) 2 0 2
1193 or die Linux::Event::Error->new(
1194 type => 'socket_configuration', operation => 'setsockopt',
1195 option => 'broadcast', errno => 0 + $!,
1196 message => _message(0 + $!),
1197 );
1198 }
1199 2 my $packed = getsockopt($self->{fh}, SOL_SOCKET, SO_BROADCAST);
1200 2 ▶ die Linux::Event::Error->new(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed 0 2 2
1201 type => 'socket_configuration', operation => 'getsockopt',
1202 option => 'broadcast', errno => 0 + $!, message => _message(0 + $!),
1203 ) if !defined $packed;
1204 2 ▶ return unpack('i', $packed) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
unpack('i', $packed) ? : 1 1 2
1205 }
1206  
1207 0 ▶sub fh ($self) { $self->{fh} }
Subroutine fh: not called CC=1 SCAR=6.9
Pod documented
1208 4 ▶sub fd ($self) { $self->{fh} ? fileno($self->{fh}) : undef }
Subroutine fd: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$self->{'fh'} ? : 4 0 4
1209 24 ▶sub loop ($self) { $self->{loop} }
Subroutine loop: called CC=1 SCAR=0.0
Pod documented
1210 11 ▶sub local ($self) { $self->{local} }
Subroutine local: called CC=1 SCAR=0.0
Pod documented
1211 4 ▶sub peer ($self) { $self->{peer} }
Subroutine peer: called CC=1 SCAR=0.0
Pod documented
1212 5 ▶sub is_connected ($self) { !!$self->{connected} }
Subroutine is_connected: called CC=1 SCAR=0.0
Pod documented
1213 8 ▶sub state ($self) { $self->{state} }
Subroutine state: called CC=1 SCAR=0.0
Pod documented
1214 0 ▶sub last_error ($self) { $self->{last_error} }
Subroutine last_error: not called CC=1 SCAR=6.9
Pod documented
1215 4 ▶sub pending_bytes ($self) { $self->{pending_bytes} }
Subroutine pending_bytes: called CC=1 SCAR=0.0
Pod documented
1216 6 ▶sub pending_datagrams ($self) { scalar @{ $self->{queue} } }
Subroutine pending_datagrams: called CC=1 SCAR=0.0
Pod documented
1217 5 ▶sub is_read_paused ($self) { !!$self->{read_paused} }
Subroutine is_read_paused: called CC=1 SCAR=0.0
Pod documented
1218 2 ▶sub is_active ($self) { $self->{state} eq 'active' }
Subroutine is_active: called CC=1 SCAR=0.0
Pod documented
1219 156 ▶sub is_terminal ($self) {
Subroutine is_terminal: called CC=3 SCAR=11.0
Pod documented
1220 return $self->{state} eq 'closed' || $self->{state} eq 'failed'
1221 156 ▶ || $self->{state} eq 'detached';
Condition100%6/6
$self->{'state'} eq 'closed' || $self->{'state'} eq 'failed' || $self->{'state'} eq 'detached'
l!l&&r!l&&!r
241131
$self->{"state"} eq "closed" or $self->{"state"} eq "failed"
l!l&&r!l&&!r
213132
MC/DC100%3/3
$self->{'state'} eq 'closed' || $self->{'state'} eq 'failed' || $self->{'state'} eq 'detached'
$self->{"state"} eq "closed" $self->{"state"} eq "failed" $self->{'state'} eq 'detached'
Truth table100%4/4
A or B || C
A= $self->{"state"} eq "closed"B= $self->{"state"} eq "failed"C= $self->{'state'} eq 'detached'
ABCresult
1XX1
01X1
0011
0000
1222 }
1223  
1224 42 ▶sub data ($self, @argument) {
Subroutine data: called CC=2 SCAR=7.2
Pod documented
1225 42 ▶ $self->{data} = $argument[0] if @argument;
Branch: 1 branch
BranchTrueFalseTotal
if @argument 0 42 42
1226 42 return $self->{data};
1227 }
1228  
1229 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
1230  
1231 23 ▶sub DESTROY ($self) {
Subroutine DESTROY: called CC=2 SCAR=8.1
1232 0 ▶ eval { $self->_shutdown('closed', 0) } if !$self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_terminal 0 23 23
1233 23 return;
1234 }
1235  
1236 package Linux::Event::Datagram::_ReadyTimer;
1237 8 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
1238 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1239 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1240 8 ▶use parent -norequire, 'Linux::Event::Timer';
Subroutine BEGIN: called CC=1 SCAR=0.0
1241  
1242 7 ▶sub on_timer ($timer) {
Subroutine on_timer: called CC=2 SCAR=7.1
1243 7 my $datagram = $timer->data;
1244 7 ▶ $datagram->_fire_ready if $datagram;
Branch: 1 branch
BranchTrueFalseTotal
if $datagram 7 0 7
1245 7 return;
1246 }
1247  
1248 8 1;
1249  
1250 __END__
↑ Summary blib/lib/Linux/Event/Stream/_Connection.pm »