blib/lib/Linux/Event/Listener.pm

filter: Statementstmt 80.8% 291 / 360 Branchbran 63.8% 138 / 216 Conditioncond 44.1% 79 / 179 MC/DCmcdc 17.3% 17 / 98 Subroutinesub 86.7% 46 / 53 Podpod 95.8% 23 / 24 totaltotal 63.8% 594 / 930 CC 176 SCAR 41.5
CC
176
Cov
67%
_create_inet_listener
188.0
new
127.5
_create_unix_listener
46.9
CRAP 63.7
« blib/lib/Linux/Event/Stream/_Connection.pm ↑ Summary bench/run-reactor-comparison.pl »
1 package Linux::Event::Listener;
2 19 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 our $VERSION = '0.105';
7  
8 19 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Fcntl qw(F_GETFD F_GETFL F_SETFD F_SETFL FD_CLOEXEC O_NONBLOCK);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 ▶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 19 );
19  
20 19 ▶use Linux::Event::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 19 ▶use Linux::Event::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 ▶use Linux::Event::_SocketConfig ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 19 require XSLoader;
25 19 XSLoader::load(__PACKAGE__, $VERSION);
26  
27 19 my %CLASS_DESCRIPTOR;
28  
29 36 ▶sub _descriptor_for ($class) {
Subroutine _descriptor_for: called CC=5 SCAR=16.4
30 36 ▶ return $CLASS_DESCRIPTOR{$class} if exists $CLASS_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$class} 16 20 36
31 20 ▶ croak "$class is not a Linux::Event::Listener subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 20 20
32 if !$class->isa(__PACKAGE__);
33  
34 20 my $accept_client = $class->can('_accept_client');
35 20 my $on_accept = $class->can('on_accept');
36 20 my $on_error = $class->can('on_error');
37 20 ▶ croak "$class must define _accept_client()" if !$accept_client;
Branch: 1 branch
BranchTrueFalseTotal
unless $accept_client 0 20 20
38 20 ▶ croak "$class must define on_error()" if !$on_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $on_error 0 20 20
39 20 return $CLASS_DESCRIPTOR{$class} = {
40 accept_client => $accept_client,
41 on_accept => $on_accept,
42 on_error => $on_error,
43 };
44 }
45  
46 95 ▶sub _integer ($name, $value, $minimum, $maximum = 2_147_483_647) {
Subroutine _integer: called CC=9 SCAR=22.6
47 95 ▶ 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 94 95
Condition66%4/6
not defined $value or ref $value or not $value =~ /\A\d+\z/u
l!l&&r!l&&!r
1094
not defined $value or ref $value
l!l&&r!l&&!r
1094
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
48 if !defined($value) || ref($value) || $value !~ /\A\d+\z/;
49 94 my $digits = "$value";
50 94 $digits =~ s/\A0+(?=\d)//;
51 94 ▶ 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 93 94
Condition66%4/6
length $digits > length "$maximum" or length $digits == length "$maximum" and $digits gt "$maximum"
l!l&&r!l&&!r
0193
length $digits == length "$maximum" and $digits gt "$maximum"
!ll&&!rl&&r
9301
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
52 if length($digits) > length("$maximum")
53 || (length($digits) == length("$maximum")
54 && $digits gt "$maximum");
55 93 $value = 0 + $value;
56 93 ▶ croak "new(): $name must be at least $minimum" if $value < $minimum;
Branch: 1 branch
BranchTrueFalseTotal
if $value < $minimum 0 93 93
57 93 return $value;
58 }
59  
60 142 ▶sub _boolean ($name, $value) {
Subroutine _boolean: called CC=5 SCAR=19.2
61 142 ▶ 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 142 142
Condition33%2/6
not defined $value or ref $value or not $value =~ /\A[01]\z/u
l!l&&r!l&&!r
00142
not defined $value or ref $value
l!l&&r!l&&!r
00142
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
62 if !defined($value) || ref($value) || $value !~ /\A[01]\z/;
63 142 ▶ return $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 37 105 142
64 }
65  
66 0 ▶sub _message ($errno) {
Subroutine _message: not called CC=1 SCAR=6.9
67 0 local $! = $errno;
68 0 return "$!";
69 }
70  
71 26 ▶sub _family_name ($family) {
Subroutine _family_name: called CC=4 SCAR=14.9
72 26 ▶ return 'inet' if $family == AF_INET;
Branch: 1 branch
BranchTrueFalseTotal
if $family == 2 24 2 26
73 2 ▶ return 'inet6' if $family == AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
if $family == 10 0 2 2
74 2 ▶ return 'unix' if $family == AF_UNIX;
Branch: 1 branch
BranchTrueFalseTotal
if $family == 1 2 0 2
75 0 return 'unknown';
76 }
77  
78 0 ▶sub _setup_error (%arg) {
Subroutine _setup_error: not called CC=1 SCAR=6.9
79 0 die Linux::Event::Error->new(
80 type => 'setup',
81 fatal => 1,
82 %arg,
83 );
84 }
85  
86 4 ▶sub _set_adopted_flags ($fh) {
Subroutine _set_adopted_flags: called CC=5 SCAR=17.0
87 4 my $status = fcntl($fh, F_GETFL, 0);
88 4 ▶ _setup_error(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 0 4 4
89 operation => 'fcntl', errno => 0 + $!, message => _message(0 + $!),
90 ) if !defined $status;
91 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
92 operation => 'fcntl', errno => 0 + $!, message => _message(0 + $!),
93 );
94  
95 4 my $fd_status = fcntl($fh, F_GETFD, 0);
96 4 ▶ _setup_error(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fd_status 0 4 4
97 operation => 'fcntl', errno => 0 + $!, message => _message(0 + $!),
98 ) if !defined $fd_status;
99 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
100 operation => 'fcntl', errno => 0 + $!, message => _message(0 + $!),
101 );
102 4 return;
103 }
104  
105 21 ▶sub _create_inet_listener ($host, $port, $backlog, $reuseaddr, $reuseport,
Subroutine _create_inet_listener: called CC=28 SCAR=52.4
106 $v6only, $bind_device) {
107 21 ▶ my $node = $host eq '*' ? undef : $host;
Branch: 1 branch
BranchTrueFalseTotal
$host eq '*' ? : 0 21 21
108 21 my ($resolver_error, @result) = getaddrinfo(
109 $node, $port, { socktype => SOCK_STREAM, flags => AI_PASSIVE },
110 );
111 21 ▶ _setup_error(
Branch: 1 branch
BranchTrueFalseTotal
if $resolver_error 0 21 21
112 operation => 'resolve',
113 message => "$resolver_error",
114 host => $host,
115 port => $port,
116 ) if $resolver_error;
117  
118 21 my ($last_errno, $last_operation);
119 21 my $compatible = 0;
120 21 for my $candidate (@result) {
121 21 ▶ next if !defined($candidate->{family}) || !defined($candidate->{addr});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $candidate->{"family"} and defined $candidate->{"addr"} 0 21 21
Condition33%1/3
defined $candidate->{"family"} and defined $candidate->{"addr"}
!ll&&!rl&&r
0021
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
122 next if $candidate->{family} != AF_INET
123 21 ▶ && $candidate->{family} != AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->{"family"} != 2 and $candidate->{"family"} != 10 0 21 21
Condition33%1/3
$candidate->{"family"} != 2 and $candidate->{"family"} != 10
!ll&&!rl&&r
2100
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
124 21 ▶ next if defined($v6only) && $candidate->{family} != AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v6only and $candidate->{"family"} != 10 1 20 21
Condition66%2/3
defined $v6only and $candidate->{"family"} != 10
!ll&&!rl&&r
2001
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
125 20 $compatible = 1;
126 20 my $fh;
127 20 ▶ if (!socket(
Branch: 1 branch
BranchTrueFalseTotal
unless (socket $fh, $candidate->{"family"}, 526337, $candidate->{"protocol"} // 0) 0 20 20
Condition50%1/2
$candidate->{"protocol"} // 0
l!l
200
MC/DC0%0/1
$candidate->{"protocol"} // 0
$candidate->{"protocol"}
Truth table50%1/2
A
A= $candidate->{"protocol"}
Aresult
11
00
128 $fh,
129 $candidate->{family},
130 SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
131 $candidate->{protocol} // 0,
132 )) {
133 0 ($last_errno, $last_operation) = (0 + $!, 'socket');
134 0 next;
135 }
136 20 ▶ if ($reuseaddr
Branch: 1 branch
BranchTrueFalseTotal
if ($reuseaddr and not setsockopt($fh, 1, 2, "\1\0\0\0")) 0 20 20
Condition33%1/3
$reuseaddr and not setsockopt($fh, 1, 2, "\1\0\0\0")
!ll&&!rl&&r
0200
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
137 && !setsockopt($fh, SOL_SOCKET, SO_REUSEADDR, pack('i', 1))) {
138 0 ($last_errno, $last_operation) = (0 + $!, 'setsockopt');
139 0 close $fh;
140 0 next;
141 }
142 20 ▶ if ($reuseport
Branch: 1 branch
BranchTrueFalseTotal
if ($reuseport and not setsockopt($fh, 1, 15, "\1\0\0\0")) 0 20 20
Condition33%1/3
$reuseport and not setsockopt($fh, 1, 15, "\1\0\0\0")
!ll&&!rl&&r
2000
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
143 && !setsockopt($fh, SOL_SOCKET, SO_REUSEPORT, pack('i', 1))) {
144 0 ($last_errno, $last_operation) = (0 + $!, 'setsockopt');
145 0 close $fh;
146 0 next;
147 }
148 20 ▶ 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 20 20
$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
2000
defined $v6only and $candidate->{"family"} == 10
!ll&&!rl&&r
2000
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
149 && !setsockopt(
150 $fh, IPPROTO_IPV6, IPV6_V6ONLY, pack('i', $v6only ? 1 : 0),
151 )) {
152 0 ($last_errno, $last_operation) = (0 + $!, 'setsockopt');
153 0 close $fh;
154 0 next;
155 }
156 20 ▶ if (defined $bind_device) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bind_device) 0 20 20
157 0 my $ok = eval {
158 0 Linux::Event::_SocketConfig::bind_device($fh, $bind_device);
159 0 1;
160 };
161 0 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
162 0 my $error = $@;
163 0 close $fh;
164 0 die $error;
165 }
166 }
167 20 ▶ if (!bind($fh, $candidate->{addr})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (bind $fh, $candidate->{"addr"}) 0 20 20
168 0 ($last_errno, $last_operation) = (0 + $!, 'bind');
169 0 close $fh;
170 0 next;
171 }
172 20 ▶ if (!listen($fh, $backlog)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (listen $fh, $backlog) 0 20 20
173 0 ($last_errno, $last_operation) = (0 + $!, 'listen');
174 0 close $fh;
175 0 next;
176 }
177 20 return ($fh, $candidate->{family});
178 }
179  
180 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
181 type => 'socket_configuration',
182 operation => 'setsockopt',
183 option => 'v6only',
184 message => 'v6only requires an IPv6 bind address',
185 host => $host,
186 port => $port,
187 ) if defined($v6only) && !$compatible;
188  
189 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
190 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
191 0 _setup_error(
192 operation => $last_operation,
193 errno => $last_errno,
194 message => _message($last_errno),
195 host => $host,
196 port => $port,
197 );
198 }
199  
200 2 ▶sub _create_unix_listener ($path, $backlog, $unlink_existing, $permissions) {
Subroutine _create_unix_listener: called CC=11 SCAR=38.5
201 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
202 0 ▶ croak "new(): Unix path already exists: $path" if !$unlink_existing;
Branch: 1 branch
BranchTrueFalseTotal
unless $unlink_existing 0 0 0
203 0 ▶ croak "new(): refusing to unlink non-socket path: $path" if !-S $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -S $path 0 0 0
204 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
205 operation => 'unlink',
206 errno => 0 + $!,
207 message => _message(0 + $!),
208 path => $path,
209 );
210 }
211  
212 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
213 SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0) or _setup_error(
214 operation => 'socket',
215 errno => 0 + $!,
216 message => _message(0 + $!),
217 path => $path,
218 );
219 2 ▶ if (!bind($fh, pack_sockaddr_un($path))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (bind $fh, pack_sockaddr_un($path)) 0 2 2
220 0 my $errno = 0 + $!;
221 0 close $fh;
222 0 _setup_error(
223 operation => 'bind', errno => $errno, message => _message($errno),
224 path => $path,
225 );
226 }
227 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
228 0 my $errno = 0 + $!;
229 0 close $fh;
230 0 unlink $path;
231 0 _setup_error(
232 operation => 'chmod', errno => $errno,
233 message => _message($errno), path => $path,
234 );
235 }
236 2 ▶ if (!listen($fh, $backlog)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (listen $fh, $backlog) 0 2 2
237 0 my $errno = 0 + $!;
238 0 close $fh;
239 0 unlink $path;
240 0 _setup_error(
241 operation => 'listen', errno => $errno,
242 message => _message($errno), path => $path,
243 );
244 }
245 2 return ($fh, AF_UNIX);
246 }
247  
248 38 ▶sub new ($class, %opt) {
Subroutine new: called CC=61 SCAR=48.5
Pod undocumented
249 38 ▶ croak 'new(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 38 38
250 38 my $loop = delete $opt{loop};
251 38 ▶ 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 38 38
Condition44%4/9
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch")
!ll&&!rl&&r
16220
ref $loop && $loop->can('add') && $loop->can('watch')
!ll&&!rl&&r
0022
ref $loop and $loop->can("add")
!ll&&!rl&&r
0022
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
252 if defined($loop) && (!ref($loop) || !$loop->can('add')
253 || !$loop->can('watch'));
254 my $stream_class = delete $opt{stream_class}
255 38 ▶ // croak 'new(): missing stream_class';
Condition50%1/2
delete $opt{"stream_class"} // croak("new(): missing stream_class")
l!l
380
MC/DC0%0/1
delete $opt{"stream_class"} // croak("new(): missing stream_class")
delete $opt{"stream_class"}
Truth table50%1/2
A
A= delete $opt{"stream_class"}
Aresult
11
00
256 38 ▶ croak 'new(): stream_class must name a Linux::Event::Stream subclass'
Branch: 1 branch
BranchTrueFalseTotal
if ref $stream_class or not $stream_class->isa("Linux::Event::Stream") 0 38 38
Condition33%1/3
ref $stream_class or not $stream_class->isa("Linux::Event::Stream")
l!l&&r!l&&!r
0038
MC/DC0%0/2
ref $stream_class or not $stream_class->isa("Linux::Event::Stream")
ref $stream_class not $stream_class->isa("Linux::Event::Stream")
Truth table33%1/3
A or not(B)
A= ref $stream_classB= not $stream_class->isa("Linux::Event::Stream")
ABresult
1X1
011
000
257 if ref($stream_class) || !$stream_class->isa('Linux::Event::Stream');
258 38 $stream_class->_validate_accepted_configuration;
259  
260 36 my $descriptor = _descriptor_for($class);
261 36 my %known = map { $_ => 1 } qw(
262 loop data backlog max_accept_per_tick edge_triggered
263 reuseaddr reuseport v6only unlink unlink_on_close permissions
264 fh owns_socket host port unix bind_device
265 );
266 36 my @unknown = sort grep { !$known{$_} } keys %opt;
267 36 ▶ croak 'new(): unknown options: ' . join(', ', @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 35 36
268 35 my %supplied = map { $_ => exists $opt{$_} } keys %opt;
269 35 my $data = delete $opt{data};
270 35 ▶ my $backlog = _integer('backlog', delete($opt{backlog}) // 4096, 1);
Condition50%1/2
delete $opt{"backlog"} // 4096
l!l
035
MC/DC0%0/1
delete $opt{"backlog"} // 4096
delete $opt{"backlog"}
Truth table50%1/2
A
A= delete $opt{"backlog"}
Aresult
11
00
271 my $maximum = _integer(
272 35 ▶ 'max_accept_per_tick', delete($opt{max_accept_per_tick}) // 256, 0,
Condition100%2/2
delete $opt{"max_accept_per_tick"} // 256
l!l
233
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
273 );
274 my $edge = _boolean(
275 35 ▶ 'edge_triggered', delete($opt{edge_triggered}) // 0,
Condition100%2/2
delete $opt{"edge_triggered"} // 0
l!l
134
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
276 );
277 35 ▶ croak 'new(): edge_triggered requires max_accept_per_tick => 0'
Branch: 1 branch
BranchTrueFalseTotal
if $edge and $maximum 1 34 35
Condition66%2/3
$edge and $maximum
!ll&&!rl&&r
3401
MC/DC50%1/2
$edge and $maximum
$edge $maximum
Truth table66%2/3
A and B
A= $edgeB= $maximum
ABresult
0X0
100
111
278 if $edge && $maximum;
279 my $reuseaddr = _boolean(
280 34 ▶ 'reuseaddr', exists($opt{reuseaddr}) ? delete($opt{reuseaddr}) : 1,
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{'reuseaddr'} ? : 0 34 34
281 );
282 34 ▶ my $reuseport = _boolean('reuseport', delete($opt{reuseport}) // 0);
Condition50%1/2
delete $opt{"reuseport"} // 0
l!l
034
MC/DC0%0/1
delete $opt{"reuseport"} // 0
delete $opt{"reuseport"}
Truth table50%1/2
A
A= delete $opt{"reuseport"}
Aresult
11
00
283 34 my $v6only = delete $opt{v6only};
284 34 ▶ $v6only = _boolean('v6only', $v6only) if defined $v6only;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v6only 1 33 34
285 34 ▶ my $unlink_existing = _boolean('unlink', delete($opt{unlink}) // 0);
Condition50%1/2
delete $opt{"unlink"} // 0
l!l
034
MC/DC0%0/1
delete $opt{"unlink"} // 0
delete $opt{"unlink"}
Truth table50%1/2
A
A= delete $opt{"unlink"}
Aresult
11
00
286 my $unlink_on_close = exists($opt{unlink_on_close})
287 34 ▶ ? _boolean('unlink_on_close', delete($opt{unlink_on_close})) : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{'unlink_on_close'} ? : 0 34 34
288 34 my $permissions = delete $opt{permissions};
289 34 ▶ $permissions = _integer('permissions', $permissions, 0, 07777)
Branch: 1 branch
BranchTrueFalseTotal
if defined $permissions 2 32 34
290 if defined $permissions;
291 34 my $bind_device = delete $opt{bind_device};
292 34 ▶ 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 34 34
Condition11%1/9
defined $bind_device and ref $bind_device || $bind_device eq "" || $bind_device =~ /\0/u
!ll&&!rl&&r
3400
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
293 if defined($bind_device)
294 && (ref($bind_device) || $bind_device eq '' || $bind_device =~ /\0/);
295  
296 34 my $fh_mode = exists $opt{fh};
297 34 ▶ my $host_mode = exists($opt{host}) || exists($opt{port});
Condition66%2/3
exists $opt{'host'} || exists $opt{'port'}
l!l&&r!l&&!r
2608
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
298 34 my $unix_mode = exists $opt{unix};
299 34 ▶ my $mode_count = ($fh_mode ? 1 : 0) + ($host_mode ? 1 : 0)
Branch: 3 branches
BranchTrueFalseTotal
$fh_mode ? : 4 30 34
$host_mode ? : 26 8 34
$unix_mode ? : 4 30 34
300 + ($unix_mode ? 1 : 0);
301 34 ▶ croak 'new(): exactly one socket source is required '
Branch: 1 branch
BranchTrueFalseTotal
if $mode_count != 1 2 32 34
302 . '(fh, host/port, or unix)' if $mode_count != 1;
303  
304 32 my @inapplicable;
305 32 ▶ if ($fh_mode) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fh_mode) { } 4 28 32
elsif ($host_mode) { } 25 3 28
306 4 @inapplicable = grep { $supplied{$_} }
307 qw(backlog reuseaddr reuseport v6only unlink unlink_on_close
308 permissions);
309 } elsif ($host_mode) {
310 25 @inapplicable = grep { $supplied{$_} }
311 qw(owns_socket unlink unlink_on_close permissions);
312 } else {
313 3 @inapplicable = grep { $supplied{$_} }
314 qw(owns_socket reuseaddr reuseport v6only bind_device);
315 }
316 32 ▶ croak 'new(): options not valid for this socket source: '
Branch: 1 branch
BranchTrueFalseTotal
if @inapplicable 1 31 32
317 . join(', ', @inapplicable) if @inapplicable;
318  
319 31 my ($fh, $host, $port, $path, $family, $owns_socket);
320 31 ▶ if ($fh_mode) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fh_mode) { } 4 27 31
elsif ($host_mode) { } 24 3 27
321 4 $fh = delete $opt{fh};
322 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
323 if !defined($fh) || !defined(fileno($fh));
324 4 my $accepting = getsockopt($fh, SOL_SOCKET, SO_ACCEPTCONN);
325 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
326 if !defined($accepting) || !unpack('i', $accepting);
327 $owns_socket = _boolean(
328 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
329 );
330 4 my $local = Linux::Event::Address->new(getsockname($fh));
331 4 $family = $local->family_number;
332 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
333 if !defined($family) || ($family != AF_INET
334 && $family != AF_INET6 && $family != AF_UNIX);
335 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
336 if defined($bind_device)
337 && $family != AF_INET && $family != AF_INET6;
338 4 _set_adopted_flags($fh);
339 4 ▶ Linux::Event::_SocketConfig::bind_device($fh, $bind_device)
Branch: 1 branch
BranchTrueFalseTotal
if defined $bind_device 0 4 4
340 if defined $bind_device;
341 4 $host = $local->host;
342 4 $port = $local->port;
343 } elsif ($host_mode) {
344 24 $host = delete $opt{host};
345 24 $port = delete $opt{port};
346 24 ▶ croak 'new(): host is required' if !defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 24 24
347 24 ▶ 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 23 24
Condition50%3/6
ref $host or $host eq "" or $host =~ /\0/u
l!l&&r!l&&!r
0123
ref $host or $host eq ""
l!l&&r!l&&!r
0024
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
348 if ref($host) || $host eq '' || $host =~ /\0/;
349 23 $port = _integer('port', $port, 0, 65535);
350 21 ($fh, $family) = _create_inet_listener(
351 $host, $port, $backlog, $reuseaddr, $reuseport, $v6only,
352 $bind_device,
353 );
354 20 my $local = Linux::Event::Address->new(getsockname($fh));
355 20 $host = $local->host;
356 20 $port = $local->port;
357 20 $owns_socket = 1;
358 } else {
359 3 $path = delete $opt{unix};
360 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
361 if !defined($path) || ref($path) || $path eq '' || $path =~ /\0/;
362 2 ($fh, $family) = _create_unix_listener(
363 $path, $backlog, $unlink_existing, $permissions,
364 );
365 2 $owns_socket = 1;
366 }
367 26 ▶ croak 'new(): unknown options: ' . join(', ', sort keys %opt) if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 26 26
368  
369 26 ▶ my $self = bless {
Branch: 2 branches
BranchTrueFalseTotal
$owns_socket ? : 23 3 26
defined $path && $unlink_on_close ? : 2 24 26
Condition66%2/3
defined $path and $unlink_on_close
!ll&&!rl&&r
2402
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
370 descriptor => $descriptor,
371 stream_class => $stream_class,
372 loop => undef,
373 data => $data,
374 fh => $fh,
375 family => _family_name($family),
376 family_number => $family,
377 host => $host,
378 port => $port,
379 unix => $path,
380 backlog => $backlog,
381 max_accept_per_tick => $maximum,
382 edge_triggered => $edge,
383 owns_socket => $owns_socket ? 1 : 0,
384 unlink_on_close => (defined($path) && $unlink_on_close) ? 1 : 0,
385 state => 'unattached',
386 watcher => undef,
387 accepted => 0,
388 last_error => undef,
389 }, $class;
390  
391 26 ▶ $self->_attach_to_loop($loop) if $loop;
Branch: 1 branch
BranchTrueFalseTotal
if $loop 13 13 26
392 26 return $self;
393 }
394  
395 0 ▶sub stream_class ($self) { $self->{stream_class} }
Subroutine stream_class: not called CC=1 SCAR=6.9
Pod documented
396  
397 1038 ▶sub _accept_client ($self, $fh, $peer) {
Subroutine _accept_client: called CC=10 SCAR=23.2
398 1038 my $class = $self->{stream_class};
399 1038 my $stream;
400 1038 my $prepared = eval {
401 1038 $stream = $class->new(
402 fh => $fh,
403 peer => $peer,
404 data => $self->data,
405 _accepted => 1,
406 );
407 1038 $stream->_attach_to_loop($self->loop);
408 1037 1;
409 };
410 1038 ▶ if (!$prepared) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prepared) 1 1037 1038
411 1 my $failure = $@;
412 1 ▶ eval { $stream->close; 1 } if $stream;
Branch: 1 branch
BranchTrueFalseTotal
if $stream 1 0 1
413 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 Stream 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 Stream 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
414 && $failure->isa('Linux::Event::Error')
415 ? $failure
416 : Linux::Event::Error->new(
417 type => 'setup',
418 operation => 'accepted_stream',
419 message => "$failure" || 'accepted Stream setup failed',
420 fatal => 0,
421 host => $self->host,
422 port => $self->port,
423 family => $self->family,
424 );
425 1 $self->{last_error} = $error;
426 1 $self->{descriptor}{on_error}->($self, $error);
427 1 return;
428 }
429 1037 ▶ if (my $callback = $self->{descriptor}{on_accept}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $callback = $self->{"descriptor"}{"on_accept"}) 4 1033 1037
430 4 my $ok = eval { $callback->($self, $stream); 1 };
431 4 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 3 4
432 1 my $message = "$@";
433 1 $message =~ s/\s+\z//;
434 1 ▶ $message = 'on_accept callback failed' if $message eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $message eq "" 0 1 1
435 1 eval { $stream->close; 1 };
436 1 my $error = Linux::Event::Error->new(
437 type => 'callback',
438 operation => 'on_accept',
439 message => $message,
440 fatal => 0,
441 host => $self->host,
442 port => $self->port,
443 path => $self->path,
444 family => $self->family,
445 );
446 1 $self->{last_error} = $error;
447 1 $self->{descriptor}{on_error}->($self, $error);
448 1 return;
449 }
450 }
451 1036 ▶ $stream->_fire_ready if !$stream->transport;
Branch: 1 branch
BranchTrueFalseTotal
unless $stream->transport 1035 1 1036
452 1036 return;
453 }
454  
455 2 ▶sub on_error ($self, $error) {
Subroutine on_error: called CC=1 SCAR=0.0
Pod documented
456 2 die "listener failed: $error\n";
457 }
458  
459 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
460  
461 24 ▶sub _attach_to_loop ($self, $loop) {
Subroutine _attach_to_loop: called CC=8 SCAR=21.6
462 croak 'add(): Listener is not unattached'
463 24 ▶ if $self->{state} ne 'unattached' || $self->{loop};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "unattached" or $self->{"loop"} 1 23 24
Condition66%2/3
$self->{"state"} ne "unattached" or $self->{"loop"}
l!l&&r!l&&!r
1023
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
464 23 my $watcher = eval {
465 $loop->watch(
466 fh => $self->{fh},
467 _internal => 1,
468 data => $self,
469 read => \&_accept_ready,
470 error => \&_listener_error_ready,
471 23 ▶ edge_triggered => $self->{edge_triggered} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$self->{'edge_triggered'} ? : 0 23 23
472 _callback_data_arg => 1,
473 );
474 };
475 23 ▶ if (!$watcher) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($watcher) 1 22 23
476 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
477 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
478 && $failure->isa('Linux::Event::Error');
479 die Linux::Event::Error->new(
480 type => 'setup',
481 operation => 'watch',
482 fatal => 0,
483 message => "$failure",
484 host => $self->{host},
485 port => $self->{port},
486 path => $self->{unix},
487 family => $self->{family},
488 1 );
489 }
490 22 $self->{loop} = $loop;
491 22 $self->{watcher} = $watcher;
492 22 $self->{state} = 'listening';
493 22 return $self;
494 }
495  
496 1065 ▶sub loop ($self) { $self->{loop} }
Subroutine loop: called CC=1 SCAR=0.0
Pod documented
497 0 ▶sub fh ($self) { $self->{fh} }
Subroutine fh: not called CC=1 SCAR=6.9
Pod documented
498 8 ▶sub fd ($self) { defined($self->{fh}) ? fileno($self->{fh}) : undef }
Subroutine fd: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'fh'} ? : 5 3 8
499 6 ▶sub host ($self) { $self->{host} }
Subroutine host: called CC=1 SCAR=0.0
Pod documented
500 28 ▶sub port ($self) { $self->{port} }
Subroutine port: called CC=1 SCAR=0.0
Pod documented
501 4 ▶sub path ($self) { $self->{unix} }
Subroutine path: called CC=1 SCAR=0.0
Pod documented
502 7 ▶sub family ($self) { $self->{family} }
Subroutine family: called CC=1 SCAR=0.0
Pod documented
503 2 ▶sub family_number ($self) { $self->{family_number} }
Subroutine family_number: called CC=1 SCAR=0.0
Pod documented
504 2 ▶sub is_tcp ($self) {
Subroutine is_tcp: called CC=2 SCAR=7.2
Pod documented
505 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
506 }
507 2 ▶sub is_unix ($self) { return $self->{family} eq 'unix' }
Subroutine is_unix: called CC=1 SCAR=0.0
Pod documented
508 14 ▶sub state ($self) { $self->{state} }
Subroutine state: called CC=1 SCAR=0.0
Pod documented
509 5 ▶sub accepted ($self) { $self->{accepted} }
Subroutine accepted: called CC=1 SCAR=0.0
Pod documented
510 1 ▶sub last_error ($self) { $self->{last_error} }
Subroutine last_error: called CC=1 SCAR=0.0
Pod documented
511 4 ▶sub is_paused ($self) { $self->{state} eq 'paused' }
Subroutine is_paused: called CC=1 SCAR=0.0
Pod documented
512 2 ▶sub is_running ($self) {
Subroutine is_running: called CC=2 SCAR=9.2
Pod documented
513 2 ▶ 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
200
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
514 }
515 71 ▶sub is_terminal ($self) {
Subroutine is_terminal: called CC=3 SCAR=11.0
Pod documented
516 return $self->{state} eq 'closed' || $self->{state} eq 'failed'
517 71 ▶ || $self->{state} eq 'detached';
Condition100%6/6
$self->{'state'} eq 'closed' || $self->{'state'} eq 'failed' || $self->{'state'} eq 'detached'
l!l&&r!l&&!r
25145
$self->{"state"} eq "closed" or $self->{"state"} eq "failed"
l!l&&r!l&&!r
23246
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
518 }
519  
520 1042 ▶sub data ($self, @arg) {
Subroutine data: called CC=2 SCAR=7.2
Pod documented
521 1042 ▶ $self->{data} = $arg[0] if @arg;
Branch: 1 branch
BranchTrueFalseTotal
if @arg 0 1042 1042
522 1042 return $self->{data};
523 }
524  
525 1 ▶sub pause ($self) {
Subroutine pause: called CC=3 SCAR=11.4
Pod documented
526 1 ▶ return $self if $self->{state} ne 'listening';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "listening" 0 1 1
527 1 ▶ $self->{watcher}->disable_read if $self->{watcher};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"watcher"} 1 0 1
528 1 $self->{state} = 'paused';
529 1 return $self;
530 }
531  
532 1 ▶sub resume ($self) {
Subroutine resume: called CC=3 SCAR=11.4
Pod documented
533 1 ▶ return $self if $self->{state} ne 'paused';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "paused" 0 1 1
534 1 ▶ $self->{watcher}->enable_read if $self->{watcher};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"watcher"} 1 0 1
535 1 $self->{state} = 'listening';
536 1 return $self;
537 }
538  
539 0 ▶sub _close_batch_tail ($batch, $at) {
Subroutine _close_batch_tail: not called CC=2 SCAR=17.9
540 0 ▶ while ($at < @$batch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at < @$batch) 0 0 0
541 0 my $fd = $batch->[$at];
542 0 __PACKAGE__->_close_fd($fd);
543 0 $at += 2;
544 }
545 0 return;
546 }
547  
548 81 ▶sub _accept_ready ($self) {
Subroutine _accept_ready: called CC=8 SCAR=24.6
549 81 ▶ return if $self->{state} ne 'listening';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} ne "listening" 0 81 81
550 my $batch = __PACKAGE__->_accept4_batch(
551 fileno($self->{fh}), $self->{max_accept_per_tick},
552 81 );
553 81 my $errno = $batch->[0];
554 81 my $at = 1;
555 81 ▶ while ($at < @$batch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at < @$batch) 1038 81 1119
556 1038 my $fd = $batch->[$at++];
557 1038 my $sockaddr = $batch->[$at++];
558 1038 ▶ if ($self->{state} ne 'listening') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"state"} ne "listening") 0 1038 1038
559 0 __PACKAGE__->_close_fd($fd);
560 0 _close_batch_tail($batch, $at);
561 0 return;
562 }
563  
564 1038 ▶ 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) } 1038 0 1038
565 0 my $open_errno = 0 + $!;
566 0 __PACKAGE__->_close_fd($fd);
567 0 _close_batch_tail($batch, $at);
568 0 die "failed to create accepted filehandle: "
569 . _message($open_errno);
570 };
571 1038 my $peer = Linux::Event::Address->new($sockaddr);
572 1038 $self->{accepted}++;
573 1038 my $callback = $self->{descriptor}{accept_client};
574 1038 my $ok = eval { $callback->($self, $client, $peer); 1 };
575 1038 my $callback_error = $@;
576 1038 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 1038 1038
577 0 close $client;
578 0 _close_batch_tail($batch, $at);
579 0 die $callback_error;
580 }
581 }
582  
583 81 ▶ $self->_accept_error($errno) if $errno && $self->{state} eq 'listening';
Branch: 1 branch
BranchTrueFalseTotal
if $errno and $self->{"state"} eq "listening" 0 81 81
Condition33%1/3
$errno and $self->{"state"} eq "listening"
!ll&&!rl&&r
8100
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
584 81 return;
585 }
586  
587 0 ▶sub _accept_error ($self, $errno) {
Subroutine _accept_error: not called CC=6 SCAR=37.4
588 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
589 || $errno == Errno::ENOBUFS() || $errno == Errno::ENOMEM();
590 my $error = Linux::Event::Error->new(
591 type => $resource ? 'resource' : 'accept',
592 operation => 'accept',
593 errno => $errno,
594 message => _message($errno),
595 fatal => 0,
596 host => $self->{host},
597 port => $self->{port},
598 path => $self->{unix},
599 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$resource ? : 0 0 0
600 0 $self->{last_error} = $error;
601 0 ▶ $self->pause if $resource;
Branch: 1 branch
BranchTrueFalseTotal
if $resource 0 0 0
602 0 $self->{descriptor}{on_error}->($self, $error);
603 0 return;
604 }
605  
606 2 ▶sub _listener_error_ready ($self) {
Subroutine _listener_error_ready: called CC=7 SCAR=20.3
607 2 ▶ return if !$self->is_running;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_running 0 2 2
608 2 my $raw = getsockopt($self->{fh}, SOL_SOCKET, SO_ERROR);
609 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
610 my $error = Linux::Event::Error->new(
611 type => 'listener',
612 operation => 'watch',
613 errno => $errno || undef,
614 message => $errno ? _message($errno) : 'listener socket closed',
615 fatal => 1,
616 host => $self->{host},
617 port => $self->{port},
618 path => $self->{unix},
619 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
620 2 $self->{last_error} = $error;
621 2 $self->_shutdown('failed', 1);
622 2 my $reported = eval {
623 2 $self->{descriptor}{on_error}->($self, $error);
624 1 1;
625 };
626 2 my $failure = $@;
627 2 $self->{loop} = undef;
628 2 ▶ die $failure if !$reported;
Branch: 1 branch
BranchTrueFalseTotal
unless $reported 1 1 2
629 1 return;
630 }
631  
632 52 ▶sub _shutdown ($self, $state, $retain_loop = 0) {
Subroutine _shutdown: called CC=10 SCAR=23.1
633 52 ▶ return if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 26 26 52
634 26 $self->{state} = $state;
635 26 ▶ if (my $watcher = delete $self->{watcher}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher = delete $self->{"watcher"}) 22 4 26
636 22 $watcher->cancel;
637 }
638 26 ▶ if (defined(my $fh = delete $self->{fh})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $fh = delete $self->{"fh"})) 26 0 26
639 26 ▶ close $fh if $self->{owns_socket};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"owns_socket"} 22 4 26
640 }
641 26 ▶ if (defined($self->{unix}) && $self->{unlink_on_close}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"unix"} and $self->{"unlink_on_close"}) 2 24 26
Condition66%2/3
defined $self->{"unix"} and $self->{"unlink_on_close"}
!ll&&!rl&&r
2402
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
642 2 ▶ unlink $self->{unix} if -S $self->{unix};
Branch: 1 branch
BranchTrueFalseTotal
if -S $self->{"unix"} 2 0 2
643 }
644 26 ▶ $self->{loop} = undef if !$retain_loop;
Branch: 1 branch
BranchTrueFalseTotal
unless $retain_loop 24 2 26
645 26 return;
646 }
647  
648 49 ▶sub close ($self) {
Subroutine close: called CC=1 SCAR=0.0
Pod documented
649 49 $self->_shutdown('closed');
650 49 return $self;
651 }
652  
653 1 ▶sub detach ($self) {
Subroutine detach: called CC=2 SCAR=7.0
Pod documented
654 1 ▶ return undef if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 1 1
655 1 my $fh = $self->{fh};
656 1 $self->{owns_socket} = 0;
657 1 $self->{unlink_on_close} = 0;
658 1 $self->_shutdown('detached');
659 1 $self->{fh} = undef;
660 1 return $fh;
661 }
662  
663 26 ▶sub DESTROY ($self) {
Subroutine DESTROY: called CC=1 SCAR=0.0
664 26 eval { $self->close };
665 26 return;
666 }
667  
668 19 1;
669  
670 __END__
« blib/lib/Linux/Event/Stream/_Connection.pm ↑ Summary bench/run-reactor-comparison.pl »