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

filter: Statementstmt 80.3% 364 / 453 Branchbran 61.8% 167 / 270 Conditioncond 46.8% 104 / 222 MC/DCmcdc 18.0% 22 / 122 Subroutinesub 82.8% 53 / 64 Podpod 0.0% 0 / 23 totaltotal 61.5% 710 / 1154 CC 220 SCAR 40.2
CC
220
Cov
67%
_create_inet_listener
188.0
new
124.7
_create_unix_listener
46.9
CRAP 55.7
« bench/run-reactor-comparison.pl ↑ Summary blib/lib/Linux/Event/_IO.pm »
1 package Linux::Event::_Socket::Listener;
2 26 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 26 ▶use parent 'Linux::Event::_Socket';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 26 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 26 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 26 ▶use Fcntl qw(F_GETFD F_GETFL F_SETFD F_SETFL FD_CLOEXEC O_NONBLOCK);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 26 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 26 ▶use Socket qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 AF_INET AF_INET6 AF_UNIX AI_PASSIVE
14 IPPROTO_IPV6 IPV6_V6ONLY
15 SOCK_STREAM SOCK_NONBLOCK SOCK_CLOEXEC
16 SOL_SOCKET SO_ACCEPTCONN SO_ERROR SO_REUSEADDR SO_REUSEPORT
17 getaddrinfo pack_sockaddr_un
18 26 );
19  
20 26 ▶use Linux::Event::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 26 ▶use Linux::Event::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 26 ▶use Linux::Event::_Socket::Stream ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 26 ▶use Linux::Event::IO::Sock::Stream ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 26 ▶use Linux::Event::_ByteStream::Descriptor ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 26 ▶use Linux::Event::_SocketConfig ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 26 require XSLoader;
28 26 XSLoader::load(__PACKAGE__);
29  
30 26 my %CLASS_DESCRIPTOR;
31 26 my @STREAM_CALLBACK = Linux::Event::_ByteStream::_callback_names();
32 26 my %STREAM_CALLBACK = map { $_ => 1 } @STREAM_CALLBACK;
33  
34 47 ▶sub _descriptor_for ($class) {
Subroutine _descriptor_for: called CC=5 SCAR=16.4
35 47 ▶ return $CLASS_DESCRIPTOR{$class} if exists $CLASS_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$class} 21 26 47
36 26 ▶ croak "$class is not a Linux::Event::_Socket::Listener subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 26 26
37 if !$class->isa(__PACKAGE__);
38  
39 26 my $accept_client = $class->can('_accept_client');
40 26 my $on_accept = $class->can('on_accept');
41 26 my $on_error = $class->can('on_error');
42 26 ▶ croak "$class must define _accept_client()" if !$accept_client;
Branch: 1 branch
BranchTrueFalseTotal
unless $accept_client 0 26 26
43 26 ▶ croak "$class must define on_error()" if !$on_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $on_error 0 26 26
44 26 return $CLASS_DESCRIPTOR{$class} = {
45 accept_client => $accept_client,
46 on_accept => $on_accept,
47 on_error => $on_error,
48 };
49 }
50  
51 128 ▶sub _integer ($name, $value, $minimum, $maximum = 2_147_483_647) {
Subroutine _integer: called CC=9 SCAR=22.6
52 128 ▶ croak "new(): $name must be an integer"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or not $value =~ /\A\d+\z/u 1 127 128
Condition66%4/6
not defined $value or ref $value or not $value =~ /\A\d+\z/u
l!l&&r!l&&!r
10127
not defined $value or ref $value
l!l&&r!l&&!r
10127
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
53 if !defined($value) || ref($value) || $value !~ /\A\d+\z/;
54 127 my $digits = "$value";
55 127 $digits =~ s/\A0+(?=\d)//;
56 127 ▶ croak "new(): $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 126 127
Condition66%4/6
length $digits > length "$maximum" or length $digits == length "$maximum" and $digits gt "$maximum"
l!l&&r!l&&!r
01126
length $digits == length "$maximum" and $digits gt "$maximum"
!ll&&!rl&&r
12601
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 table50%2/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
57 if length($digits) > length("$maximum")
58 || (length($digits) == length("$maximum")
59 && $digits gt "$maximum");
60 126 $value = 0 + $value;
61 126 ▶ croak "new(): $name must be at least $minimum" if $value < $minimum;
Branch: 1 branch
BranchTrueFalseTotal
if $value < $minimum 0 126 126
62 126 return $value;
63 }
64  
65 186 ▶sub _boolean ($name, $value) {
Subroutine _boolean: called CC=5 SCAR=19.2
66 186 ▶ croak "new(): $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 186 186
Condition33%2/6
not defined $value or ref $value or not $value =~ /\A[01]\z/u
l!l&&r!l&&!r
00186
not defined $value or ref $value
l!l&&r!l&&!r
00186
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
67 if !defined($value) || ref($value) || $value !~ /\A[01]\z/;
68 186 ▶ return $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 48 138 186
69 }
70  
71 0 ▶sub _message ($errno) {
Subroutine _message: not called CC=1 SCAR=6.9
72 0 local $! = $errno;
73 0 return "$!";
74 }
75  
76 37 ▶sub _family_name ($family) {
Subroutine _family_name: called CC=4 SCAR=14.9
77 37 ▶ return 'inet' if $family == AF_INET;
Branch: 1 branch
BranchTrueFalseTotal
if $family == 2 35 2 37
78 2 ▶ return 'inet6' if $family == AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
if $family == 10 0 2 2
79 2 ▶ return 'unix' if $family == AF_UNIX;
Branch: 1 branch
BranchTrueFalseTotal
if $family == 1 2 0 2
80 0 return 'unknown';
81 }
82  
83 0 ▶sub _setup_error (%arg) {
Subroutine _setup_error: not called CC=1 SCAR=6.9
84 0 die Linux::Event::Error->new(
85 type => 'setup',
86 fatal => 1,
87 %arg,
88 );
89 }
90  
91 4 ▶sub _set_adopted_flags ($fh) {
Subroutine _set_adopted_flags: called CC=5 SCAR=17.0
92 4 my $status = fcntl($fh, F_GETFL, 0);
93 4 ▶ _setup_error(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 0 4 4
94 operation => 'fcntl', errno => 0 + $!, message => _message(0 + $!),
95 ) if !defined $status;
96 4 ▶ fcntl($fh, F_SETFL, $status | O_NONBLOCK) or _setup_error(
Branch: 1 branch
BranchTrueFalseTotal
fcntl $fh, 4, $status | 2048 or _setup_error("operation", "fcntl", "errno", 0 + $!, "message", _message(0 + $!)) 4 0 4
97 operation => 'fcntl', errno => 0 + $!, message => _message(0 + $!),
98 );
99  
100 4 my $fd_status = fcntl($fh, F_GETFD, 0);
101 4 ▶ _setup_error(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fd_status 0 4 4
102 operation => 'fcntl', errno => 0 + $!, message => _message(0 + $!),
103 ) if !defined $fd_status;
104 4 ▶ fcntl($fh, F_SETFD, $fd_status | FD_CLOEXEC) or _setup_error(
Branch: 1 branch
BranchTrueFalseTotal
fcntl $fh, 2, $fd_status | 1 or _setup_error("operation", "fcntl", "errno", 0 + $!, "message", _message(0 + $!)) 4 0 4
105 operation => 'fcntl', errno => 0 + $!, message => _message(0 + $!),
106 );
107 4 return;
108 }
109  
110 32 ▶sub _create_inet_listener ($host, $port, $backlog, $reuseaddr, $reuseport,
Subroutine _create_inet_listener: called CC=28 SCAR=52.4
111 $v6only, $bind_device) {
112 32 ▶ my $node = $host eq '*' ? undef : $host;
Branch: 1 branch
BranchTrueFalseTotal
$host eq '*' ? : 0 32 32
113 32 my ($resolver_error, @result) = getaddrinfo(
114 $node, $port, { socktype => SOCK_STREAM, flags => AI_PASSIVE },
115 );
116 32 ▶ _setup_error(
Branch: 1 branch
BranchTrueFalseTotal
if $resolver_error 0 32 32
117 operation => 'resolve',
118 message => "$resolver_error",
119 host => $host,
120 port => $port,
121 ) if $resolver_error;
122  
123 32 my ($last_errno, $last_operation);
124 32 my $compatible = 0;
125 32 for my $candidate (@result) {
126 32 ▶ next if !defined($candidate->{family}) || !defined($candidate->{addr});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $candidate->{"family"} and defined $candidate->{"addr"} 0 32 32
Condition33%1/3
defined $candidate->{"family"} and defined $candidate->{"addr"}
!ll&&!rl&&r
0032
MC/DC0%0/2
defined $candidate->{"family"} and defined $candidate->{"addr"}
defined $candidate->{"family"} defined $candidate->{"addr"}
Truth table33%1/3
A and B
A= defined $candidate->{"family"}B= defined $candidate->{"addr"}
ABresult
0X0
100
111
127 next if $candidate->{family} != AF_INET
128 32 ▶ && $candidate->{family} != AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->{"family"} != 2 and $candidate->{"family"} != 10 0 32 32
Condition33%1/3
$candidate->{"family"} != 2 and $candidate->{"family"} != 10
!ll&&!rl&&r
3200
MC/DC0%0/2
$candidate->{"family"} != 2 and $candidate->{"family"} != 10
$candidate->{"family"} != 2 $candidate->{"family"} != 10
Truth table33%1/3
A and B
A= $candidate->{"family"} != 2B= $candidate->{"family"} != 10
ABresult
0X0
100
111
129 32 ▶ next if defined($v6only) && $candidate->{family} != AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v6only and $candidate->{"family"} != 10 1 31 32
Condition66%2/3
defined $v6only and $candidate->{"family"} != 10
!ll&&!rl&&r
3101
MC/DC50%1/2
defined $v6only and $candidate->{"family"} != 10
defined $v6only $candidate->{"family"} != 10
Truth table66%2/3
A and B
A= defined $v6onlyB= $candidate->{"family"} != 10
ABresult
0X0
100
111
130 31 $compatible = 1;
131 31 my $fh;
132 31 ▶ if (!socket(
Branch: 1 branch
BranchTrueFalseTotal
unless (socket $fh, $candidate->{"family"}, 526337, $candidate->{"protocol"} // 0) 0 31 31
Condition50%1/2
$candidate->{"protocol"} // 0
l!l
310
MC/DC0%0/1
$candidate->{"protocol"} // 0
$candidate->{"protocol"}
Truth table50%1/2
A
A= $candidate->{"protocol"}
Aresult
11
00
133 $fh,
134 $candidate->{family},
135 SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
136 $candidate->{protocol} // 0,
137 )) {
138 0 ($last_errno, $last_operation) = (0 + $!, 'socket');
139 0 next;
140 }
141 31 ▶ if ($reuseaddr
Branch: 1 branch
BranchTrueFalseTotal
if ($reuseaddr and not setsockopt($fh, 1, 2, "\1\0\0\0")) 0 31 31
Condition33%1/3
$reuseaddr and not setsockopt($fh, 1, 2, "\1\0\0\0")
!ll&&!rl&&r
0310
MC/DC0%0/2
$reuseaddr and not setsockopt($fh, 1, 2, "\1\0\0\0")
$reuseaddr not setsockopt($fh, 1, 2, "\1\0\0\0")
Truth table33%1/3
A and not(B)
A= $reuseaddrB= not setsockopt($fh, 1, 2, "\1\0\0\0")
ABresult
0X0
100
111
142 && !setsockopt($fh, SOL_SOCKET, SO_REUSEADDR, pack('i', 1))) {
143 0 ($last_errno, $last_operation) = (0 + $!, 'setsockopt');
144 0 close $fh;
145 0 next;
146 }
147 31 ▶ if ($reuseport
Branch: 1 branch
BranchTrueFalseTotal
if ($reuseport and not setsockopt($fh, 1, 15, "\1\0\0\0")) 0 31 31
Condition33%1/3
$reuseport and not setsockopt($fh, 1, 15, "\1\0\0\0")
!ll&&!rl&&r
3100
MC/DC0%0/2
$reuseport and not setsockopt($fh, 1, 15, "\1\0\0\0")
$reuseport not setsockopt($fh, 1, 15, "\1\0\0\0")
Truth table33%1/3
A and not(B)
A= $reuseportB= not setsockopt($fh, 1, 15, "\1\0\0\0")
ABresult
0X0
100
111
148 && !setsockopt($fh, SOL_SOCKET, SO_REUSEPORT, pack('i', 1))) {
149 0 ($last_errno, $last_operation) = (0 + $!, 'setsockopt');
150 0 close $fh;
151 0 next;
152 }
153 31 ▶ if (defined($v6only) && $candidate->{family} == AF_INET6
Branch: 2 branches
BranchTrueFalseTotal
if (defined $v6only and $candidate->{"family"} == 10 and not setsockopt($fh, 41, 26, pack("i", $v6only ? 1 : 0))) 0 31 31
$v6only ? : 0 0 0
Condition33%2/6
defined $v6only and $candidate->{"family"} == 10 and not setsockopt($fh, 41, 26, pack("i", $v6only ? 1 : 0))
!ll&&!rl&&r
3100
defined $v6only and $candidate->{"family"} == 10
!ll&&!rl&&r
3100
MC/DC0%0/3
defined $v6only and $candidate->{"family"} == 10 and not setsockopt($fh, 41, 26, pack("i", $v6only ? 1 : 0))
defined $v6only $candidate->{"family"} == 10 not setsockopt($fh, 41, 26, pack("i", $v6only ? 1 : 0))
Truth table25%1/4
A and B and not(C)
A= defined $v6onlyB= $candidate->{"family"} == 10C= not setsockopt($fh, 41, 26, pack("i", $v6only ? 1 : 0))
ABCresult
0XX0
10X0
1100
1111
154 && !setsockopt(
155 $fh, IPPROTO_IPV6, IPV6_V6ONLY, pack('i', $v6only ? 1 : 0),
156 )) {
157 0 ($last_errno, $last_operation) = (0 + $!, 'setsockopt');
158 0 close $fh;
159 0 next;
160 }
161 31 ▶ if (defined $bind_device) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bind_device) 0 31 31
162 0 my $ok = eval {
163 0 Linux::Event::_SocketConfig::bind_device($fh, $bind_device);
164 0 1;
165 };
166 0 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
167 0 my $error = $@;
168 0 close $fh;
169 0 die $error;
170 }
171 }
172 31 ▶ if (!bind($fh, $candidate->{addr})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (bind $fh, $candidate->{"addr"}) 0 31 31
173 0 ($last_errno, $last_operation) = (0 + $!, 'bind');
174 0 close $fh;
175 0 next;
176 }
177 31 ▶ if (!listen($fh, $backlog)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (listen $fh, $backlog) 0 31 31
178 0 ($last_errno, $last_operation) = (0 + $!, 'listen');
179 0 close $fh;
180 0 next;
181 }
182 31 return ($fh, $candidate->{family});
183 }
184  
185 1 ▶ die Linux::Event::Error->new(
Branch: 1 branch
BranchTrueFalseTotal
if defined $v6only and not $compatible 1 0 1
Condition33%1/3
defined $v6only and not $compatible
!ll&&!rl&&r
001
MC/DC0%0/2
defined $v6only and not $compatible
defined $v6only not $compatible
Truth table33%1/3
A and not(B)
A= defined $v6onlyB= not $compatible
ABresult
0X0
100
111
186 type => 'socket_configuration',
187 operation => 'setsockopt',
188 option => 'v6only',
189 message => 'v6only requires an IPv6 bind address',
190 host => $host,
191 port => $port,
192 ) if defined($v6only) && !$compatible;
193  
194 0 ▶ $last_errno //= Errno::EADDRNOTAVAIL();
Condition0%0/2
$last_errno //= 99
l!l
00
MC/DC0%0/1
$last_errno //= 99
$last_errno
Truth table0%0/2
A
A= $last_errno
Aresult
11
00
195 0 ▶ $last_operation //= 'bind';
Condition0%0/2
$last_operation //= "bind"
l!l
00
MC/DC0%0/1
$last_operation //= "bind"
$last_operation
Truth table0%0/2
A
A= $last_operation
Aresult
11
00
196 0 _setup_error(
197 operation => $last_operation,
198 errno => $last_errno,
199 message => _message($last_errno),
200 host => $host,
201 port => $port,
202 );
203 }
204  
205 2 ▶sub _create_unix_listener ($path, $backlog, $unlink_existing, $permissions) {
Subroutine _create_unix_listener: called CC=11 SCAR=38.5
206 2 ▶ if (-e $path || -l $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $path or -l $path) 0 2 2
Condition33%1/3
-e $path or -l $path
l!l&&r!l&&!r
002
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
207 0 ▶ croak "new(): Unix path already exists: $path" if !$unlink_existing;
Branch: 1 branch
BranchTrueFalseTotal
unless $unlink_existing 0 0 0
208 0 ▶ croak "new(): refusing to unlink non-socket path: $path" if !-S $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -S $path 0 0 0
209 0 ▶ unlink($path) or _setup_error(
Branch: 1 branch
BranchTrueFalseTotal
unlink $path or _setup_error("operation", "unlink", "errno", 0 + $!, "message", _message(0 + $!), "path", $path) 0 0 0
210 operation => 'unlink',
211 errno => 0 + $!,
212 message => _message(0 + $!),
213 path => $path,
214 );
215 }
216  
217 2 ▶ socket(my $fh, AF_UNIX,
Branch: 1 branch
BranchTrueFalseTotal
socket my $fh, 1, 526337, 0 or _setup_error("operation", "socket", "errno", 0 + $!, "message", _message(0 + $!), "path", $path) 2 0 2
218 SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0) or _setup_error(
219 operation => 'socket',
220 errno => 0 + $!,
221 message => _message(0 + $!),
222 path => $path,
223 );
224 2 ▶ if (!bind($fh, pack_sockaddr_un($path))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (bind $fh, pack_sockaddr_un($path)) 0 2 2
225 0 my $errno = 0 + $!;
226 0 close $fh;
227 0 _setup_error(
228 operation => 'bind', errno => $errno, message => _message($errno),
229 path => $path,
230 );
231 }
232 2 ▶ if (defined($permissions) && !chmod($permissions, $path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $permissions and not chmod($permissions, $path)) 0 2 2
Condition66%2/3
defined $permissions and not chmod($permissions, $path)
!ll&&!rl&&r
110
MC/DC0%0/2
defined $permissions and not chmod($permissions, $path)
defined $permissions not chmod($permissions, $path)
Truth table66%2/3
A and not(B)
A= defined $permissionsB= not chmod($permissions, $path)
ABresult
0X0
100
111
233 0 my $errno = 0 + $!;
234 0 close $fh;
235 0 unlink $path;
236 0 _setup_error(
237 operation => 'chmod', errno => $errno,
238 message => _message($errno), path => $path,
239 );
240 }
241 2 ▶ if (!listen($fh, $backlog)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (listen $fh, $backlog) 0 2 2
242 0 my $errno = 0 + $!;
243 0 close $fh;
244 0 unlink $path;
245 0 _setup_error(
246 operation => 'listen', errno => $errno,
247 message => _message($errno), path => $path,
248 );
249 }
250 2 return ($fh, AF_UNIX);
251 }
252  
253 50 ▶sub _stream_recipe ($recipe) {
Subroutine _stream_recipe: called CC=24 SCAR=34.9
254 50 ▶ croak 'new(): stream must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if ref $recipe ne "HASH" 0 50 50
255 if ref($recipe) ne 'HASH';
256 50 my %stream = %$recipe;
257 my $stream_class = delete($stream{class})
258 50 ▶ // 'Linux::Event::IO::Sock::Stream';
Condition100%2/2
delete $stream{"class"} // "Linux::Event::IO::Sock::Stream"
l!l
482
MC/DC100%1/1
delete $stream{"class"} // "Linux::Event::IO::Sock::Stream"
delete $stream{"class"}
Truth table100%2/2
A
A= delete $stream{"class"}
Aresult
11
00
259 50 ▶ croak 'new(): stream class must name a Linux::Event::_Socket::Stream subclass'
Branch: 1 branch
BranchTrueFalseTotal
if ref $stream_class or not $stream_class->isa("Linux::Event::_Socket::Stream") 0 50 50
Condition33%1/3
ref $stream_class or not $stream_class->isa("Linux::Event::_Socket::Stream")
l!l&&r!l&&!r
0050
MC/DC0%0/2
ref $stream_class or not $stream_class->isa("Linux::Event::_Socket::Stream")
ref $stream_class not $stream_class->isa("Linux::Event::_Socket::Stream")
Truth table33%1/3
A or not(B)
A= ref $stream_classB= not $stream_class->isa("Linux::Event::_Socket::Stream")
ABresult
1X1
011
000
260 if ref($stream_class)
261 || !$stream_class->isa('Linux::Event::_Socket::Stream');
262  
263 50 ▶ my $tuning = delete($stream{tuning}) // {};
Condition100%2/2
delete $stream{"tuning"} // {}
l!l
149
MC/DC100%1/1
delete $stream{"tuning"} // {}
delete $stream{"tuning"}
Truth table100%2/2
A
A= delete $stream{"tuning"}
Aresult
11
00
264 50 ▶ croak 'new(): stream tuning must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if ref $tuning ne "HASH" 0 50 50
265 if ref($tuning) ne 'HASH';
266 50 my $data = delete $stream{data};
267 50 my $tls_enabled = exists $stream{tls};
268 50 my $tls = delete $stream{tls};
269 50 ▶ croak 'new(): stream tls must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if $tls_enabled and ref $tls ne "HASH" 0 50 50
Condition66%2/3
$tls_enabled and ref $tls ne "HASH"
!ll&&!rl&&r
4640
MC/DC0%0/2
$tls_enabled and ref $tls ne "HASH"
$tls_enabled ref $tls ne "HASH"
Truth table66%2/3
A and B
A= $tls_enabledB= ref $tls ne "HASH"
ABresult
0X0
100
111
270 if $tls_enabled && ref($tls) ne 'HASH';
271  
272 50 my %callback;
273 50 for my $name (@STREAM_CALLBACK) {
274 450 ▶ next if !exists $stream{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $stream{$name} 442 8 450
275 8 my $value = delete $stream{$name};
276 8 ▶ croak "new(): stream $name must be a coderef"
Branch: 1 branch
BranchTrueFalseTotal
if ref $value ne "CODE" 0 8 8
277 if ref($value) ne 'CODE';
278 8 $callback{$name} = $value;
279 }
280 50 ▶ croak 'new(): stream has unknown options: '
Branch: 1 branch
BranchTrueFalseTotal
if %stream 0 50 50
281 . join(', ', sort keys %stream) if %stream;
282  
283 50 my $prepared = Linux::Event::_ByteStream::Descriptor::prepared(
284 $stream_class, $tuning, \%callback,
285 );
286 Linux::Event::_ByteStream::Descriptor::validate_modes(
287 49 'new(): stream', $prepared, $prepared->{options}, \%callback,
288 );
289 my $input = Linux::Event::_ByteStream::Descriptor::effective_input_callback(
290 49 $prepared, $prepared->{options}, \%callback,
291 );
292 49 ▶ if (!$prepared->{consumer} && !$input) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prepared->{"consumer"} or $input) 0 49 49
Condition33%1/3
$prepared->{"consumer"} or $input
l!l&&r!l&&!r
0490
MC/DC0%0/2
$prepared->{"consumer"} or $input
$prepared->{"consumer"} $input
Truth table33%1/3
A or B
A= $prepared->{"consumer"}B= $input
ABresult
1X1
011
000
293 croak $prepared->{framer}
294 0 ▶ ? 'new(): accepted framed Stream requires on_message or on_messages'
Branch: 1 branch
BranchTrueFalseTotal
$prepared->{'framer'} ? : 0 0 0
295 : 'new(): accepted raw Stream requires on_data callback';
296 }
297  
298 my %constructor_callback = map {
299 49 ▶ exists($callback{$_}) ? ($_ => $callback{$_}) : ()
Branch: 1 branch
BranchTrueFalseTotal
exists $callback{$_} ? : 2 292 294
300 } qw(on_drain on_eof on_error on_close on_ready on_transport_ready);
301 49 ▶ if (!$prepared->{consumer}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prepared->{"consumer"}) 49 0 49
302 49 ▶ if (!$prepared->{framer}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $prepared->{'framer'}) { } 46 3 49
elsif ($prepared->{'options'}{'message_batch_size'}) { } 0 3 3
303 $constructor_callback{on_data} = $input
304 46 ▶ if exists $callback{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $callback{"on_data"} 4 42 46
305 } elsif ($prepared->{options}{message_batch_size}) {
306 $constructor_callback{on_messages} = $input
307 0 ▶ if exists $callback{on_messages};
Branch: 1 branch
BranchTrueFalseTotal
if exists $callback{"on_messages"} 0 0 0
308 } else {
309 $constructor_callback{on_message} = $input
310 3 ▶ if exists $callback{on_message};
Branch: 1 branch
BranchTrueFalseTotal
if exists $callback{"on_message"} 1 2 3
311 }
312 }
313  
314 49 my $tls_template;
315 49 ▶ if ($tls_enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tls_enabled) 4 45 49
316 4 require Linux::Event::TLS;
317 4 $tls_template = Linux::Event::TLS->_prepare_listener_server(
318 $stream_class, $tls,
319 );
320 }
321  
322 return {
323 class => $stream_class,
324 descriptor => $prepared,
325 data => $data,
326 tuning => $prepared->{options},
327 47 callbacks => \%callback,
328 constructor_callbacks => \%constructor_callback,
329 tls_template => $tls_template,
330 };
331 }
332  
333 1111 ▶sub _construct_prepared_stream ($stream_class, @arg) {
Subroutine _construct_prepared_stream: called CC=1 SCAR=0.0
334 1111 return $stream_class->new(@arg);
335 }
336  
337 50 ▶sub new ($class, %opt) {
Subroutine new: called CC=64 SCAR=48.3
Pod undocumented
338 50 ▶ croak 'new(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 50 50
339 50 my $loop = delete $opt{loop};
340 50 ▶ croak 'new(): 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 50 50
Condition44%4/9
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch")
!ll&&!rl&&r
18320
ref $loop && $loop->can('add') && $loop->can('watch')
!ll&&!rl&&r
0032
ref $loop and $loop->can("add")
!ll&&!rl&&r
0032
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
341 if defined($loop) && (!ref($loop) || !$loop->can('add')
342 || !$loop->can('watch'));
343  
344 50 ▶ my $recipe = _stream_recipe(delete($opt{stream}) // {});
Condition50%1/2
delete $opt{"stream"} // {}
l!l
500
MC/DC0%0/1
delete $opt{"stream"} // {}
delete $opt{"stream"}
Truth table50%1/2
A
A= delete $opt{"stream"}
Aresult
11
00
345 47 my $descriptor = _descriptor_for($class);
346 47 my %listener_callback;
347 47 for my $name (qw(on_accept on_error)) {
348 94 ▶ next if !exists $opt{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt{$name} 90 4 94
349 4 my $value = delete $opt{$name};
350 4 ▶ croak "new(): $name must be a coderef" if ref($value) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value ne "CODE" 0 4 4
351 4 $listener_callback{$name} = $value;
352 }
353 47 ▶ $listener_callback{on_accept} //= $descriptor->{on_accept};
Condition100%3/3
$listener_callback{"on_accept"} //= $descriptor->{"on_accept"}
l!l&&r!l&&!r
2441
MC/DC100%2/2
$listener_callback{"on_accept"} //= $descriptor->{"on_accept"}
$listener_callback{"on_accept"} $descriptor->{"on_accept"}
Truth table100%3/3
A //= B
A= $listener_callback{"on_accept"}B= $descriptor->{"on_accept"}
ABresult
1X1
011
000
354 47 ▶ $listener_callback{on_error} //= $descriptor->{on_error};
Condition66%2/3
$listener_callback{"on_error"} //= $descriptor->{"on_error"}
l!l&&r!l&&!r
2450
MC/DC0%0/2
$listener_callback{"on_error"} //= $descriptor->{"on_error"}
$listener_callback{"on_error"} $descriptor->{"on_error"}
Truth table66%2/3
A //= B
A= $listener_callback{"on_error"}B= $descriptor->{"on_error"}
ABresult
1X1
011
000
355  
356 47 my %known = map { $_ => 1 } qw(
357 backlog max_accept_per_tick edge_triggered
358 reuseaddr reuseport v6only unlink unlink_on_close permissions
359 fh owns_socket host port unix bind_device
360 );
361 47 my @unknown = sort grep { !$known{$_} } keys %opt;
362 47 ▶ croak 'new(): unknown options: ' . join(', ', @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 46 47
363 46 my %supplied = map { $_ => exists $opt{$_} } keys %opt;
364 46 ▶ my $backlog = _integer('backlog', delete($opt{backlog}) // 4096, 1);
Condition50%1/2
delete $opt{"backlog"} // 4096
l!l
046
MC/DC0%0/1
delete $opt{"backlog"} // 4096
delete $opt{"backlog"}
Truth table50%1/2
A
A= delete $opt{"backlog"}
Aresult
11
00
365 my $maximum = _integer(
366 46 ▶ 'max_accept_per_tick', delete($opt{max_accept_per_tick}) // 256, 0,
Condition100%2/2
delete $opt{"max_accept_per_tick"} // 256
l!l
244
MC/DC100%1/1
delete $opt{"max_accept_per_tick"} // 256
delete $opt{"max_accept_per_tick"}
Truth table100%2/2
A
A= delete $opt{"max_accept_per_tick"}
Aresult
11
00
367 );
368 my $edge = _boolean(
369 46 ▶ 'edge_triggered', delete($opt{edge_triggered}) // 0,
Condition100%2/2
delete $opt{"edge_triggered"} // 0
l!l
145
MC/DC100%1/1
delete $opt{"edge_triggered"} // 0
delete $opt{"edge_triggered"}
Truth table100%2/2
A
A= delete $opt{"edge_triggered"}
Aresult
11
00
370 );
371 46 ▶ croak 'new(): edge_triggered requires max_accept_per_tick => 0'
Branch: 1 branch
BranchTrueFalseTotal
if $edge and $maximum 1 45 46
Condition66%2/3
$edge and $maximum
!ll&&!rl&&r
4501
MC/DC50%1/2
$edge and $maximum
$edge $maximum
Truth table66%2/3
A and B
A= $edgeB= $maximum
ABresult
0X0
100
111
372 if $edge && $maximum;
373 my $reuseaddr = _boolean(
374 45 ▶ 'reuseaddr', exists($opt{reuseaddr}) ? delete($opt{reuseaddr}) : 1,
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{'reuseaddr'} ? : 0 45 45
375 );
376 45 ▶ my $reuseport = _boolean('reuseport', delete($opt{reuseport}) // 0);
Condition50%1/2
delete $opt{"reuseport"} // 0
l!l
045
MC/DC0%0/1
delete $opt{"reuseport"} // 0
delete $opt{"reuseport"}
Truth table50%1/2
A
A= delete $opt{"reuseport"}
Aresult
11
00
377 45 my $v6only = delete $opt{v6only};
378 45 ▶ $v6only = _boolean('v6only', $v6only) if defined $v6only;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v6only 1 44 45
379 45 ▶ my $unlink_existing = _boolean('unlink', delete($opt{unlink}) // 0);
Condition50%1/2
delete $opt{"unlink"} // 0
l!l
045
MC/DC0%0/1
delete $opt{"unlink"} // 0
delete $opt{"unlink"}
Truth table50%1/2
A
A= delete $opt{"unlink"}
Aresult
11
00
380 my $unlink_on_close = exists($opt{unlink_on_close})
381 45 ▶ ? _boolean('unlink_on_close', delete($opt{unlink_on_close})) : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{'unlink_on_close'} ? : 0 45 45
382 45 my $permissions = delete $opt{permissions};
383 45 ▶ $permissions = _integer('permissions', $permissions, 0, 07777)
Branch: 1 branch
BranchTrueFalseTotal
if defined $permissions 2 43 45
384 if defined $permissions;
385 45 my $bind_device = delete $opt{bind_device};
386 45 ▶ croak 'new(): bind_device must be a non-empty interface name'
Branch: 1 branch
BranchTrueFalseTotal
if defined $bind_device and ref $bind_device || $bind_device eq "" || $bind_device =~ /\0/u 0 45 45
Condition11%1/9
defined $bind_device and ref $bind_device || $bind_device eq "" || $bind_device =~ /\0/u
!ll&&!rl&&r
4500
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
387 if defined($bind_device)
388 && (ref($bind_device) || $bind_device eq '' || $bind_device =~ /\0/);
389  
390 45 my $fh_mode = exists $opt{fh};
391 45 ▶ my $host_mode = exists($opt{host}) || exists($opt{port});
Condition66%2/3
exists $opt{'host'} || exists $opt{'port'}
l!l&&r!l&&!r
3708
MC/DC50%1/2
exists $opt{'host'} || exists $opt{'port'}
exists $opt{'host'} exists $opt{'port'}
Truth table66%2/3
A || B
A= exists $opt{'host'}B= exists $opt{'port'}
ABresult
1X1
011
000
392 45 my $unix_mode = exists $opt{unix};
393 45 ▶ my $mode_count = ($fh_mode ? 1 : 0) + ($host_mode ? 1 : 0)
Branch: 3 branches
BranchTrueFalseTotal
$fh_mode ? : 4 41 45
$host_mode ? : 37 8 45
$unix_mode ? : 4 41 45
394 + ($unix_mode ? 1 : 0);
395 45 ▶ croak 'new(): exactly one socket source is required '
Branch: 1 branch
BranchTrueFalseTotal
if $mode_count != 1 2 43 45
396 . '(fh, host/port, or unix)' if $mode_count != 1;
397  
398 43 my @inapplicable;
399 43 ▶ if ($fh_mode) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fh_mode) { } 4 39 43
elsif ($host_mode) { } 36 3 39
400 4 @inapplicable = grep { $supplied{$_} }
401 qw(backlog reuseaddr reuseport v6only unlink unlink_on_close
402 permissions);
403 } elsif ($host_mode) {
404 36 @inapplicable = grep { $supplied{$_} }
405 qw(owns_socket unlink unlink_on_close permissions);
406 } else {
407 3 @inapplicable = grep { $supplied{$_} }
408 qw(owns_socket reuseaddr reuseport v6only bind_device);
409 }
410 43 ▶ croak 'new(): options not valid for this socket source: '
Branch: 1 branch
BranchTrueFalseTotal
if @inapplicable 1 42 43
411 . join(', ', @inapplicable) if @inapplicable;
412  
413 42 my ($fh, $host, $port, $path, $family, $owns_socket);
414 42 ▶ if ($fh_mode) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fh_mode) { } 4 38 42
elsif ($host_mode) { } 35 3 38
415 4 $fh = delete $opt{fh};
416 4 ▶ croak 'new(): fh must be a filehandle'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh and defined fileno $fh 0 4 4
Condition33%1/3
defined $fh and defined fileno $fh
!ll&&!rl&&r
004
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
417 if !defined($fh) || !defined(fileno($fh));
418 4 my $accepting = getsockopt($fh, SOL_SOCKET, SO_ACCEPTCONN);
419 4 ▶ croak 'new(): fh is not a listening socket'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $accepting and unpack "i", $accepting 0 4 4
Condition33%1/3
defined $accepting and unpack "i", $accepting
!ll&&!rl&&r
004
MC/DC0%0/2
defined $accepting and unpack "i", $accepting
defined $accepting unpack "i", $accepting
Truth table33%1/3
A and B
A= defined $acceptingB= unpack "i", $accepting
ABresult
0X0
100
111
420 if !defined($accepting) || !unpack('i', $accepting);
421 $owns_socket = _boolean(
422 4 ▶ 'owns_socket', delete($opt{owns_socket}) // 0,
Condition100%2/2
delete $opt{"owns_socket"} // 0
l!l
13
MC/DC100%1/1
delete $opt{"owns_socket"} // 0
delete $opt{"owns_socket"}
Truth table100%2/2
A
A= delete $opt{"owns_socket"}
Aresult
11
00
423 );
424 4 my $local = Linux::Event::Address->new(getsockname($fh));
425 4 $family = $local->family_number;
426 4 ▶ 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 4 4
Condition33%3/9
not defined $family or $family != 2 and $family != 10 and $family != 1
l!l&&r!l&&!r
004
$family != 2 and $family != 10 and $family != 1
!ll&&!rl&&r
400
$family != 2 and $family != 10
!ll&&!rl&&r
400
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
427 if !defined($family) || ($family != AF_INET
428 && $family != AF_INET6 && $family != AF_UNIX);
429 4 ▶ croak 'new(): bind_device is valid only for TCP listeners'
Branch: 1 branch
BranchTrueFalseTotal
if defined $bind_device and $family != 2 and $family != 10 0 4 4
Condition33%2/6
defined $bind_device and $family != 2 and $family != 10
!ll&&!rl&&r
400
defined $bind_device and $family != 2
!ll&&!rl&&r
400
MC/DC0%0/3
defined $bind_device and $family != 2 and $family != 10
defined $bind_device $family != 2 $family != 10
Truth table25%1/4
A and B and C
A= defined $bind_deviceB= $family != 2C= $family != 10
ABCresult
0XX0
10X0
1100
1111
430 if defined($bind_device)
431 && $family != AF_INET && $family != AF_INET6;
432 4 _set_adopted_flags($fh);
433 4 ▶ Linux::Event::_SocketConfig::bind_device($fh, $bind_device)
Branch: 1 branch
BranchTrueFalseTotal
if defined $bind_device 0 4 4
434 if defined $bind_device;
435 4 $host = $local->host;
436 4 $port = $local->port;
437 } elsif ($host_mode) {
438 35 $host = delete $opt{host};
439 35 $port = delete $opt{port};
440 35 ▶ croak 'new(): host is required' if !defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 35 35
441 35 ▶ 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 34 35
Condition50%3/6
ref $host or $host eq "" or $host =~ /\0/u
l!l&&r!l&&!r
0134
ref $host or $host eq ""
l!l&&r!l&&!r
0035
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
442 if ref($host) || $host eq '' || $host =~ /\0/;
443 34 $port = _integer('port', $port, 0, 65535);
444 32 ($fh, $family) = _create_inet_listener(
445 $host, $port, $backlog, $reuseaddr, $reuseport, $v6only,
446 $bind_device,
447 );
448 31 my $local = Linux::Event::Address->new(getsockname($fh));
449 31 $host = $local->host;
450 31 $port = $local->port;
451 31 $owns_socket = 1;
452 } else {
453 3 $path = delete $opt{unix};
454 3 ▶ 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 2 3
Condition44%4/9
not defined $path or ref $path or $path eq "" or $path =~ /\0/u
l!l&&r!l&&!r
012
not defined $path or ref $path or $path eq ""
l!l&&r!l&&!r
003
not defined $path or ref $path
l!l&&r!l&&!r
003
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
455 if !defined($path) || ref($path) || $path eq '' || $path =~ /\0/;
456 2 ($fh, $family) = _create_unix_listener(
457 $path, $backlog, $unlink_existing, $permissions,
458 );
459 2 $owns_socket = 1;
460 }
461 37 ▶ croak 'new(): unknown options: ' . join(', ', sort keys %opt) if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 37 37
462  
463 37 ▶ my $self = bless {
Branch: 2 branches
BranchTrueFalseTotal
$owns_socket ? : 34 3 37
defined $path && $unlink_on_close ? : 2 35 37
Condition66%2/3
defined $path and $unlink_on_close
!ll&&!rl&&r
3502
MC/DC50%1/2
defined $path and $unlink_on_close
defined $path $unlink_on_close
Truth table66%2/3
A and B
A= defined $pathB= $unlink_on_close
ABresult
0X0
100
111
464 descriptor => $descriptor,
465 stream_recipe => $recipe,
466 listener_callbacks => \%listener_callback,
467 loop => undef,
468 data => undef,
469 fh => $fh,
470 family => _family_name($family),
471 family_number => $family,
472 host => $host,
473 port => $port,
474 unix => $path,
475 backlog => $backlog,
476 max_accept_per_tick => $maximum,
477 edge_triggered => $edge,
478 owns_socket => $owns_socket ? 1 : 0,
479 unlink_on_close => (defined($path) && $unlink_on_close) ? 1 : 0,
480 state => 'unattached',
481 watcher => undef,
482 accepted => 0,
483 last_error => undef,
484 }, $class;
485  
486 37 ▶ $self->_attach_to_loop($loop) if $loop;
Branch: 1 branch
BranchTrueFalseTotal
if $loop 23 14 37
487 37 return $self;
488 }
489  
490 1111 ▶sub _accept_client ($self, $fh, $peer) {
Subroutine _accept_client: called CC=13 SCAR=26.0
491 1111 my $recipe = $self->{stream_recipe};
492 1111 my $stream_class = $recipe->{class};
493 1111 my $stream;
494 1111 my $prepared = eval {
495 1111 my $transport;
496 1111 ▶ if (defined $recipe->{tls_template}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $recipe->{"tls_template"}) 1 1110 1111
497 1 require Linux::Event::TLS;
498 $transport = Linux::Event::TLS->_listener_server_connection(
499 $recipe->{tls_template},
500 1 );
501 }
502 $stream = Linux::Event::_ByteStream::Descriptor::with_prepared(
503 $stream_class,
504 $recipe->{descriptor},
505 \&_construct_prepared_stream,
506 fh => $fh,
507 peer => $peer,
508 data => $recipe->{data},
509 _accepted => 1,
510 transport => $transport,
511 1111 %{ $recipe->{constructor_callbacks} },
512 );
513 1111 $stream->{_effective_tuning} = $recipe->{tuning};
514 1111 $stream->{_recipe_input_callbacks} = $recipe->{callbacks};
515 1111 $stream->_attach_to_loop($self->loop);
516 1110 1;
517 };
518 1111 ▶ if (!$prepared) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prepared) 1 1110 1111
519 1 my $failure = $@;
520 1 ▶ eval { $stream->_close_now(1); 1 } if $stream;
Branch: 1 branch
BranchTrueFalseTotal
if $stream 1 0 1
521 1 ▶ CORE::close($fh) if !$stream && defined fileno($fh);
Branch: 1 branch
BranchTrueFalseTotal
if not $stream and defined fileno $fh 0 1 1
Condition33%1/3
not $stream and defined fileno $fh
!ll&&!rl&&r
100
MC/DC0%0/2
not $stream and defined fileno $fh
not $stream defined fileno $fh
Truth table33%1/3
not(A) and B
A= not $streamB= defined fileno $fh
ABresult
0X0
100
111
522 1 ▶ my $error = blessed($failure)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($failure) && $failure->isa('Linux::Event::Error') ? : 0 1 1
Condition40%2/5
builtin::blessed($failure) and $failure->isa("Linux::Event::Error")
!ll&&!rl&&r
100
"$failure" || 'accepted Socket setup failed'
l!l
10
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" || 'accepted Socket setup failed'
"$failure"
Truth table33%1/3
A and B
A= builtin::blessed($failure)B= $failure->isa("Linux::Event::Error")
ABresult
0X0
100
111
Truth table50%1/2
A
A= "$failure"
Aresult
11
00
523 && $failure->isa('Linux::Event::Error')
524 ? $failure
525 : Linux::Event::Error->new(
526 type => 'setup',
527 operation => 'accepted_socket',
528 message => "$failure" || 'accepted Socket setup failed',
529 fatal => 0,
530 host => $self->host,
531 port => $self->port,
532 family => $self->family,
533 );
534 1 $self->{last_error} = $error;
535 1 $self->{listener_callbacks}{on_error}->($self, $error);
536 1 return;
537 }
538 1110 ▶ if (my $callback = $self->{listener_callbacks}{on_accept}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $callback = $self->{"listener_callbacks"}{"on_accept"}) 6 1104 1110
539 6 my $ok = eval { $callback->($self, $stream); 1 };
540 6 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 5 6
541 1 my $message = "$@";
542 1 $message =~ s/\s+\z//;
543 1 ▶ $message = 'on_accept callback failed' if $message eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $message eq "" 0 1 1
544 1 eval { $stream->_close_now(1); 1 };
545 1 my $error = Linux::Event::Error->new(
546 type => 'callback',
547 operation => 'on_accept',
548 message => $message,
549 fatal => 0,
550 host => $self->host,
551 port => $self->port,
552 path => $self->path,
553 family => $self->family,
554 );
555 1 $self->{last_error} = $error;
556 1 $self->{listener_callbacks}{on_error}->($self, $error);
557 1 return;
558 }
559 }
560 1109 ▶ $stream->_fire_ready if !$stream->transport;
Branch: 1 branch
BranchTrueFalseTotal
unless $stream->transport 1108 1 1109
561 1109 return;
562 }
563  
564 2 ▶sub on_error ($self, $error) {
Subroutine on_error: called CC=1 SCAR=0.0
Pod undocumented
565 2 die "listener failed: $error\n";
566 }
567  
568 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
569  
570 2 ▶sub _fork_preflight ($self, $mode, $loop) {
Subroutine _fork_preflight: called CC=7 SCAR=23.7
571 croak "fork(): Listener is not active in this Loop"
572 2 ▶ if !$self->{loop} || Scalar::Util::refaddr($self->{loop}) != Scalar::Util::refaddr($loop)
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"loop"} or builtin::refaddr($self->{"loop"}) != builtin::refaddr($loop) or not $self->is_running 0 2 2
Condition33%2/6
not $self->{"loop"} or builtin::refaddr($self->{"loop"}) != builtin::refaddr($loop) or not $self->is_running
l!l&&r!l&&!r
002
not $self->{"loop"} or builtin::refaddr($self->{"loop"}) != builtin::refaddr($loop)
l!l&&r!l&&!r
002
MC/DC0%0/3
not $self->{"loop"} or builtin::refaddr($self->{"loop"}) != builtin::refaddr($loop) or not $self->is_running
not $self->{"loop"} builtin::refaddr($self->{"loop"}) != builtin::refaddr($loop) not $self->is_running
Truth table25%1/4
not(A) or B or not(C)
A= not $self->{"loop"}B= builtin::refaddr($self->{"loop"}) != builtin::refaddr($loop)C= not $self->is_running
ABCresult
1XX1
01X1
0011
0000
573 || !$self->is_running;
574 2 ▶ croak "fork(): Listener does not support '$mode'"
Branch: 1 branch
BranchTrueFalseTotal
if $mode ne "drop" and $mode ne "share" and $mode ne "move" 0 2 2
Condition66%4/6
$mode ne "drop" and $mode ne "share" and $mode ne "move"
!ll&&!rl&&r
110
$mode ne "drop" and $mode ne "share"
!ll&&!rl&&r
011
MC/DC0%0/3
$mode ne "drop" and $mode ne "share" and $mode ne "move"
$mode ne "drop" $mode ne "share" $mode ne "move"
Truth table50%2/4
A and B and C
A= $mode ne "drop"B= $mode ne "share"C= $mode ne "move"
ABCresult
0XX0
10X0
1100
1111
575 if $mode ne 'drop' && $mode ne 'share' && $mode ne 'move';
576 2 return 1;
577 }
578  
579 0 ▶sub _fork_child_rebind ($self, $loop, $mode) {
Subroutine _fork_child_rebind: not called CC=3 SCAR=24.8
580 0 my $paused = $self->{state} eq 'paused';
581 0 $self->{watcher} = undef;
582 0 $self->{loop} = undef;
583 0 $self->{state} = 'unattached';
584 0 $self->_attach_to_loop($loop);
585 0 ▶ $self->pause if $paused;
Branch: 1 branch
BranchTrueFalseTotal
if $paused 0 0 0
586 0 ▶ $self->{unlink_on_close} = 0 if $mode eq 'share';
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "share" 0 0 0
587 0 return;
588 }
589  
590 0 ▶sub _fork_child_share ($self, $loop) {
Subroutine _fork_child_share: not called CC=1 SCAR=6.9
591 0 $self->_fork_child_rebind($loop, 'share');
592 }
593  
594 0 ▶sub _fork_child_move ($self, $loop) {
Subroutine _fork_child_move: not called CC=1 SCAR=6.9
595 0 $self->_fork_child_rebind($loop, 'move');
596 }
597  
598 0 ▶sub _fork_child_drop ($self, $loop) {
Subroutine _fork_child_drop: not called CC=3 SCAR=24.8
599 0 $self->{watcher} = undef;
600 0 my $fh = delete $self->{fh};
601 0 ▶ close $fh if defined($fh) && $self->{owns_socket};
Branch: 1 branch
BranchTrueFalseTotal
if defined $fh and $self->{"owns_socket"} 0 0 0
Condition0%0/3
defined $fh and $self->{"owns_socket"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $fh and $self->{"owns_socket"}
defined $fh $self->{"owns_socket"}
Truth table0%0/3
A and B
A= defined $fhB= $self->{"owns_socket"}
ABresult
0X0
100
111
602 0 $self->{unlink_on_close} = 0;
603 0 $self->{loop} = undef;
604 0 $self->{state} = 'not_inherited';
605 0 return;
606 }
607  
608 1 ▶sub _fork_parent_move ($self, $child_pid) {
Subroutine _fork_parent_move: called CC=4 SCAR=14.6
609 1 ▶ if (my $watcher = delete $self->{watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $self->{"watcher"}) 1 0 1
610 1 $watcher->cancel;
611 }
612 1 my $fh = delete $self->{fh};
613 1 ▶ close $fh if defined($fh) && $self->{owns_socket};
Branch: 1 branch
BranchTrueFalseTotal
if defined $fh and $self->{"owns_socket"} 1 0 1
Condition33%1/3
defined $fh and $self->{"owns_socket"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $fh and $self->{"owns_socket"}
defined $fh $self->{"owns_socket"}
Truth table33%1/3
A and B
A= defined $fhB= $self->{"owns_socket"}
ABresult
0X0
100
111
614 1 $self->{unlink_on_close} = 0;
615 1 $self->{loop} = undef;
616 1 $self->{state} = 'moved';
617 1 return;
618 }
619  
620 35 ▶sub _attach_to_loop ($self, $loop) {
Subroutine _attach_to_loop: called CC=8 SCAR=21.6
621 croak 'add(): Listener is not unattached'
622 35 ▶ if $self->{state} ne 'unattached' || $self->{loop};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "unattached" or $self->{"loop"} 1 34 35
Condition66%2/3
$self->{"state"} ne "unattached" or $self->{"loop"}
l!l&&r!l&&!r
1034
MC/DC50%1/2
$self->{"state"} ne "unattached" or $self->{"loop"}
$self->{"state"} ne "unattached" $self->{"loop"}
Truth table66%2/3
A or B
A= $self->{"state"} ne "unattached"B= $self->{"loop"}
ABresult
1X1
011
000
623 34 my $watcher = eval {
624 $loop->watch(
625 fh => $self->{fh},
626 _internal => 1,
627 data => $self,
628 read => \&_accept_ready,
629 error => \&_listener_error_ready,
630 34 ▶ edge_triggered => $self->{edge_triggered} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$self->{'edge_triggered'} ? : 0 34 34
631 _callback_data_arg => 1,
632 );
633 };
634 34 ▶ if (!$watcher) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($watcher) 1 33 34
635 1 ▶ my $failure = $@ || 'could not register Listener socket';
Condition50%1/2
$@ || 'could not register Listener socket'
l!l
10
MC/DC0%0/1
$@ || 'could not register Listener socket'
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
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 die Linux::Event::Error->new(
639 type => 'setup',
640 operation => 'watch',
641 fatal => 0,
642 message => "$failure",
643 host => $self->{host},
644 port => $self->{port},
645 path => $self->{unix},
646 family => $self->{family},
647 1 );
648 }
649 33 $self->{loop} = $loop;
650 33 $self->{watcher} = $watcher;
651 33 $self->{state} = 'listening';
652 33 return $self;
653 }
654  
655 1154 ▶sub loop ($self) { $self->{loop} }
Subroutine loop: called CC=1 SCAR=0.0
Pod undocumented
656 0 ▶sub fh ($self) { $self->{fh} }
Subroutine fh: not called CC=1 SCAR=6.9
Pod undocumented
657 9 ▶sub fd ($self) { defined($self->{fh}) ? fileno($self->{fh}) : undef }
Subroutine fd: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'fh'} ? : 5 4 9
658 6 ▶sub host ($self) { $self->{host} }
Subroutine host: called CC=1 SCAR=0.0
Pod undocumented
659 38 ▶sub port ($self) { $self->{port} }
Subroutine port: called CC=1 SCAR=0.0
Pod undocumented
660 4 ▶sub path ($self) { $self->{unix} }
Subroutine path: called CC=1 SCAR=0.0
Pod undocumented
661 7 ▶sub family ($self) { $self->{family} }
Subroutine family: called CC=1 SCAR=0.0
Pod undocumented
662 2 ▶sub family_number ($self) { $self->{family_number} }
Subroutine family_number: called CC=1 SCAR=0.0
Pod undocumented
663 2 ▶sub is_tcp ($self) {
Subroutine is_tcp: called CC=2 SCAR=7.2
Pod undocumented
664 2 ▶ return $self->{family} eq 'inet' || $self->{family} eq 'inet6';
Condition66%2/3
$self->{'family'} eq 'inet' || $self->{'family'} eq 'inet6'
l!l&&r!l&&!r
101
MC/DC50%1/2
$self->{'family'} eq 'inet' || $self->{'family'} eq 'inet6'
$self->{'family'} eq 'inet' $self->{'family'} eq 'inet6'
Truth table66%2/3
A || B
A= $self->{'family'} eq 'inet'B= $self->{'family'} eq 'inet6'
ABresult
1X1
011
000
665 }
666 2 ▶sub is_unix ($self) { return $self->{family} eq 'unix' }
Subroutine is_unix: called CC=1 SCAR=0.0
Pod undocumented
667 15 ▶sub state ($self) { $self->{state} }
Subroutine state: called CC=1 SCAR=0.0
Pod undocumented
668 5 ▶sub accepted ($self) { $self->{accepted} }
Subroutine accepted: called CC=1 SCAR=0.0
Pod undocumented
669 1 ▶sub last_error ($self) { $self->{last_error} }
Subroutine last_error: called CC=1 SCAR=0.0
Pod undocumented
670 4 ▶sub is_paused ($self) { $self->{state} eq 'paused' }
Subroutine is_paused: called CC=1 SCAR=0.0
Pod undocumented
671 5 ▶sub is_running ($self) {
Subroutine is_running: called CC=2 SCAR=9.2
Pod undocumented
672 5 ▶ return $self->{state} eq 'listening' || $self->{state} eq 'paused';
Condition33%1/3
$self->{'state'} eq 'listening' || $self->{'state'} eq 'paused'
l!l&&r!l&&!r
500
MC/DC0%0/2
$self->{'state'} eq 'listening' || $self->{'state'} eq 'paused'
$self->{'state'} eq 'listening' $self->{'state'} eq 'paused'
Truth table33%1/3
A || B
A= $self->{'state'} eq 'listening'B= $self->{'state'} eq 'paused'
ABresult
1X1
011
000
673 }
674 108 ▶sub is_terminal ($self) {
Subroutine is_terminal: called CC=5 SCAR=16.1
Pod undocumented
675 return $self->{state} eq 'closed' || $self->{state} eq 'failed'
676 || $self->{state} eq 'detached' || $self->{state} eq 'moved'
677 108 ▶ || $self->{state} eq 'not_inherited';
Condition91%11/12
$self->{'state'} eq 'closed' || $self->{'state'} eq 'failed' || $self->{'state'} eq 'detached' || $self->{'state'} eq 'moved' || $self->{'state'} eq 'not_inherited'
l!l&&r!l&&!r
37071
$self->{"state"} eq "closed" or $self->{"state"} eq "failed" or $self->{"state"} eq "detached" or $self->{"state"} eq "moved"
l!l&&r!l&&!r
36171
$self->{"state"} eq "closed" or $self->{"state"} eq "failed" or $self->{"state"} eq "detached"
l!l&&r!l&&!r
35172
$self->{"state"} eq "closed" or $self->{"state"} eq "failed"
l!l&&r!l&&!r
33273
MC/DC80%4/5
$self->{'state'} eq 'closed' || $self->{'state'} eq 'failed' || $self->{'state'} eq 'detached' || $self->{'state'} eq 'moved' || $self->{'state'} eq 'not_inherited'
$self->{"state"} eq "closed" $self->{"state"} eq "failed" $self->{"state"} eq "detached" $self->{"state"} eq "moved" $self->{'state'} eq 'not_inherited'
Truth table83%5/6
A or B or C or D || E
A= $self->{"state"} eq "closed"B= $self->{"state"} eq "failed"C= $self->{"state"} eq "detached"D= $self->{"state"} eq "moved"E= $self->{'state'} eq 'not_inherited'
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
678 }
679  
680 0 ▶sub data ($self, @arg) {
Subroutine data: not called CC=2 SCAR=17.9
Pod undocumented
681 0 ▶ $self->{data} = $arg[0] if @arg;
Branch: 1 branch
BranchTrueFalseTotal
if @arg 0 0 0
682 0 return $self->{data};
683 }
684  
685 1 ▶sub pause ($self) {
Subroutine pause: called CC=3 SCAR=11.4
Pod undocumented
686 1 ▶ return $self if $self->{state} ne 'listening';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "listening" 0 1 1
687 1 ▶ $self->{watcher}->disable_read if $self->{watcher};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"watcher"} 1 0 1
688 1 $self->{state} = 'paused';
689 1 return $self;
690 }
691  
692 1 ▶sub resume ($self) {
Subroutine resume: called CC=3 SCAR=11.4
Pod undocumented
693 1 ▶ return $self if $self->{state} ne 'paused';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "paused" 0 1 1
694 1 ▶ $self->{watcher}->enable_read if $self->{watcher};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"watcher"} 1 0 1
695 1 $self->{state} = 'listening';
696 1 return $self;
697 }
698  
699 0 ▶sub _close_batch_tail ($batch, $at) {
Subroutine _close_batch_tail: not called CC=2 SCAR=17.9
700 0 ▶ while ($at < @$batch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at < @$batch) 0 0 0
701 0 my $fd = $batch->[$at];
702 0 __PACKAGE__->_close_fd($fd);
703 0 $at += 2;
704 }
705 0 return;
706 }
707  
708 119 ▶sub _accept_ready ($self) {
Subroutine _accept_ready: called CC=8 SCAR=24.6
709 119 ▶ return if $self->{state} ne 'listening';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "listening" 0 119 119
710 my $batch = __PACKAGE__->_accept4_batch(
711 fileno($self->{fh}), $self->{max_accept_per_tick},
712 119 );
713 119 my $errno = $batch->[0];
714 119 my $at = 1;
715 119 ▶ while ($at < @$batch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at < @$batch) 1111 119 1230
716 1111 my $fd = $batch->[$at++];
717 1111 my $sockaddr = $batch->[$at++];
718 1111 ▶ if ($self->{state} ne 'listening') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"state"} ne "listening") 0 1111 1111
719 0 __PACKAGE__->_close_fd($fd);
720 0 _close_batch_tail($batch, $at);
721 0 return;
722 }
723  
724 1111 ▶ open(my $client, '+<&=', $fd) or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $client, "+<&=", $fd or do { my $open_errno = 0 + $!; __PACKAGE__->_close_fd($fd); _close_batch_tail($batch, $at); die 'failed to create accepted filehandle: ' . _message($open_errno) } 1111 0 1111
725 0 my $open_errno = 0 + $!;
726 0 __PACKAGE__->_close_fd($fd);
727 0 _close_batch_tail($batch, $at);
728 0 die "failed to create accepted filehandle: "
729 . _message($open_errno);
730 };
731 1111 my $peer = Linux::Event::Address->new($sockaddr);
732 1111 $self->{accepted}++;
733 1111 my $callback = $self->{descriptor}{accept_client};
734 1111 my $ok = eval { $callback->($self, $client, $peer); 1 };
735 1111 my $callback_error = $@;
736 1111 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 1111 1111
737 0 close $client;
738 0 _close_batch_tail($batch, $at);
739 0 die $callback_error;
740 }
741 }
742  
743 119 ▶ $self->_accept_error($errno) if $errno && $self->{state} eq 'listening';
Branch: 1 branch
BranchTrueFalseTotal
if $errno and $self->{"state"} eq "listening" 0 119 119
Condition33%1/3
$errno and $self->{"state"} eq "listening"
!ll&&!rl&&r
11900
MC/DC0%0/2
$errno and $self->{"state"} eq "listening"
$errno $self->{"state"} eq "listening"
Truth table33%1/3
A and B
A= $errnoB= $self->{"state"} eq "listening"
ABresult
0X0
100
111
744 119 return;
745 }
746  
747 0 ▶sub _accept_error ($self, $errno) {
Subroutine _accept_error: not called CC=6 SCAR=37.4
748 0 ▶ my $resource = $errno == Errno::EMFILE() || $errno == Errno::ENFILE()
Condition0%0/9
$errno == 24 || $errno == 23 || $errno == 105 || $errno == 12
l!l&&r!l&&!r
000
$errno == 24 or $errno == 23 or $errno == 105
l!l&&r!l&&!r
000
$errno == 24 or $errno == 23
l!l&&r!l&&!r
000
MC/DC0%0/4
$errno == 24 || $errno == 23 || $errno == 105 || $errno == 12
$errno == 24 $errno == 23 $errno == 105 $errno == 12
Truth table0%0/5
A or B or C || D
A= $errno == 24B= $errno == 23C= $errno == 105D= $errno == 12
ABCDresult
1XXX1
01XX1
001X1
00011
00000
749 || $errno == Errno::ENOBUFS() || $errno == Errno::ENOMEM();
750 my $error = Linux::Event::Error->new(
751 type => $resource ? 'resource' : 'accept',
752 operation => 'accept',
753 errno => $errno,
754 message => _message($errno),
755 fatal => 0,
756 host => $self->{host},
757 port => $self->{port},
758 path => $self->{unix},
759 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$resource ? : 0 0 0
760 0 $self->{last_error} = $error;
761 0 ▶ $self->pause if $resource;
Branch: 1 branch
BranchTrueFalseTotal
if $resource 0 0 0
762 0 $self->{listener_callbacks}{on_error}->($self, $error);
763 0 return;
764 }
765  
766 2 ▶sub _listener_error_ready ($self) {
Subroutine _listener_error_ready: called CC=7 SCAR=20.2
767 2 ▶ return if !$self->is_running;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_running 0 2 2
768 2 my $raw = getsockopt($self->{fh}, SOL_SOCKET, SO_ERROR);
769 2 ▶ my $errno = defined($raw) && length($raw) >= 4 ? unpack('i', $raw) : 0 + $!;
Branch: 1 branch
BranchTrueFalseTotal
defined $raw && length $raw >= 4 ? : 2 0 2
Condition33%1/3
defined $raw and length $raw >= 4
!ll&&!rl&&r
002
MC/DC0%0/2
defined $raw and length $raw >= 4
defined $raw length $raw >= 4
Truth table33%1/3
A and B
A= defined $rawB= length $raw >= 4
ABresult
0X0
100
111
770 my $error = Linux::Event::Error->new(
771 type => 'listener',
772 operation => 'watch',
773 errno => $errno || undef,
774 message => $errno ? _message($errno) : 'listener socket closed',
775 fatal => 1,
776 host => $self->{host},
777 port => $self->{port},
778 path => $self->{unix},
779 2 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$errno ? : 0 2 2
Condition50%1/2
$errno || undef
l!l
02
MC/DC0%0/1
$errno || undef
$errno
Truth table50%1/2
A
A= $errno
Aresult
11
00
780 2 $self->{last_error} = $error;
781 2 my $on_error = $self->{listener_callbacks}{on_error};
782 2 $self->_shutdown('failed', 1);
783 2 my $reported = eval {
784 2 $on_error->($self, $error);
785 1 1;
786 };
787 2 my $failure = $@;
788 2 $self->{loop} = undef;
789 2 ▶ die $failure if !$reported;
Branch: 1 branch
BranchTrueFalseTotal
unless $reported 1 1 2
790 1 return;
791 }
792  
793 73 ▶sub _shutdown ($self, $state, $retain_loop = 0) {
Subroutine _shutdown: called CC=10 SCAR=23.1
794 73 ▶ return if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 37 36 73
795 36 $self->{state} = $state;
796 36 ▶ if (my $watcher = delete $self->{watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $self->{"watcher"}) 32 4 36
797 32 $watcher->cancel;
798 }
799 36 ▶ if (defined(my $fh = delete $self->{fh})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $fh = delete $self->{"fh"})) 36 0 36
800 36 ▶ close $fh if $self->{owns_socket};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"owns_socket"} 32 4 36
801 }
802 36 ▶ if (defined($self->{unix}) && $self->{unlink_on_close}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"unix"} and $self->{"unlink_on_close"}) 2 34 36
Condition66%2/3
defined $self->{"unix"} and $self->{"unlink_on_close"}
!ll&&!rl&&r
3402
MC/DC50%1/2
defined $self->{"unix"} and $self->{"unlink_on_close"}
defined $self->{"unix"} $self->{"unlink_on_close"}
Truth table66%2/3
A and B
A= defined $self->{"unix"}B= $self->{"unlink_on_close"}
ABresult
0X0
100
111
803 2 ▶ unlink $self->{unix} if -S $self->{unix};
Branch: 1 branch
BranchTrueFalseTotal
if -S $self->{"unix"} 2 0 2
804 }
805 36 delete $self->{stream_recipe};
806 36 delete $self->{listener_callbacks};
807 36 ▶ $self->{loop} = undef if !$retain_loop;
Branch: 1 branch
BranchTrueFalseTotal
unless $retain_loop 34 2 36
808 36 return;
809 }
810  
811 70 ▶sub close ($self) {
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
812 70 $self->_shutdown('closed');
813 70 return $self;
814 }
815  
816 1 ▶sub detach ($self) {
Subroutine detach: called CC=2 SCAR=7.0
Pod undocumented
817 1 ▶ return undef if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 1 1
818 1 my $fh = $self->{fh};
819 1 $self->{owns_socket} = 0;
820 1 $self->{unlink_on_close} = 0;
821 1 $self->_shutdown('detached');
822 1 $self->{fh} = undef;
823 1 return $fh;
824 }
825  
826 37 ▶sub DESTROY ($self) {
Subroutine DESTROY: called CC=1 SCAR=0.0
827 37 eval { $self->close };
828 37 return;
829 }
830  
831 26 1;
« bench/run-reactor-comparison.pl ↑ Summary blib/lib/Linux/Event/_IO.pm »