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

filter: Statementstmt 86.4% 224 / 259 Branchbran 64.9% 100 / 154 Conditioncond 47.3% 63 / 133 MC/DCmcdc 18.0% 13 / 72 Subroutinesub 91.4% 43 / 47 Podpod 0.0% 0 / 21 totaltotal 64.5% 443 / 686 CC 126 SCAR 30.9
CC
126
Cov
71%
close_read
56.0
new
53.2
sendfile
38.8
CRAP 22.0
« blib/lib/Linux/Event/Kernel/Process.pm ↑ Summary blib/lib/Linux/Event/Framer/LengthPrefix.pm »
1 package Linux::Event::_Socket::Stream;
2 120 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 120 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 120 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 120 ▶use parent 'Linux::Event::_ByteStream';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 120 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 120 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 120 ▶use Socket qw(SOL_SOCKET SO_ERROR SO_TYPE SOCK_STREAM SHUT_RD SHUT_WR);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 120 ▶use Linux::Event::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 120 ▶use Linux::Event::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 120 ▶use Linux::Event::_Socket::Connection ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 120 ▶use Linux::Event::_Socket::Descriptor ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 120 ▶use Linux::Event::_SocketConfig ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # Constructors and class lifecycle
19  
20 102042 ▶sub new ($class, %opt) {
Subroutine new: called CC=27 SCAR=39.7
Pod undocumented
21 102042 ▶ croak 'new(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 102042 102042
22 102042 my $loop = delete $opt{loop};
23 102042 ▶ croak 'new(): loop must be an object implementing add() and watch_fd()'
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch_fd") 0 102042 102042
Condition44%4/9
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch_fd")
!ll&&!rl&&r
1016424000
ref $loop && $loop->can('add') && $loop->can('watch_fd')
!ll&&!rl&&r
00400
ref $loop and $loop->can("add")
!ll&&!rl&&r
00400
MC/DC0%0/4
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch_fd")
defined $loop ref $loop $loop->can("add") $loop->can('watch_fd')
Truth table40%2/5
A and not(B and C && D)
A= defined $loopB= ref $loopC= $loop->can("add")D= $loop->can('watch_fd')
ABCDresult
0XXX0
11110
10XX1
110X1
11101
24 if defined($loop) && (!ref($loop) || !$loop->can('add')
25 || !$loop->can('watch_fd'));
26 102042 my $fh = delete $opt{fh};
27 102042 ▶ croak 'new(): Socket requires fh' if !defined($fh) || !defined(fileno($fh));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh and defined fileno $fh 0 102042 102042
Condition33%1/3
defined $fh and defined fileno $fh
!ll&&!rl&&r
00102042
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
28 croak 'new(): Socket does not accept read_fh or write_fh'
29 102042 ▶ if exists($opt{read_fh}) || exists($opt{write_fh});
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"read_fh"} or exists $opt{"write_fh"} 0 102042 102042
Condition33%1/3
exists $opt{"read_fh"} or exists $opt{"write_fh"}
l!l&&r!l&&!r
00102042
MC/DC0%0/2
exists $opt{"read_fh"} or exists $opt{"write_fh"}
exists $opt{"read_fh"} exists $opt{"write_fh"}
Truth table33%1/3
A or B
A= exists $opt{"read_fh"}B= exists $opt{"write_fh"}
ABresult
1X1
011
000
30 102042 ▶ my $accepted = delete($opt{_accepted}) // 0;
Condition100%2/2
delete $opt{"_accepted"} // 0
l!l
1111100931
MC/DC100%1/1
delete $opt{"_accepted"} // 0
delete $opt{"_accepted"}
Truth table100%2/2
A
A= delete $opt{"_accepted"}
Aresult
11
00
31 102042 my $peer = delete $opt{peer};
32 102042 my $tls_role = delete $opt{tls_role};
33 102042 my $transport = delete $opt{transport};
34 102042 ▶ croak 'new(): transport must be an object implementing _stream_transport_bind()'
Branch: 1 branch
BranchTrueFalseTotal
if defined $transport and not builtin::blessed($transport) && $transport->can("_stream_transport_bind") 0 102042 102042
Condition50%3/6
defined $transport and not builtin::blessed($transport) && $transport->can("_stream_transport_bind")
!ll&&!rl&&r
102018240
builtin::blessed($transport) && $transport->can('_stream_transport_bind')
!ll&&!rl&&r
0024
MC/DC0%0/3
defined $transport and not builtin::blessed($transport) && $transport->can("_stream_transport_bind")
defined $transport builtin::blessed($transport) $transport->can('_stream_transport_bind')
Truth table50%2/4
A and not(B && C)
A= defined $transportB= builtin::blessed($transport)C= $transport->can('_stream_transport_bind')
ABCresult
0XX0
1110
10X1
1101
35 if defined($transport)
36 && (!blessed($transport) || !$transport->can('_stream_transport_bind'));
37 102042 ▶ croak 'new(): tls_role cannot be combined with accepted mode'
Branch: 1 branch
BranchTrueFalseTotal
if $accepted and defined $tls_role 0 102042 102042
Condition66%2/3
$accepted and defined $tls_role
!ll&&!rl&&r
10093111110
MC/DC0%0/2
$accepted and defined $tls_role
$accepted defined $tls_role
Truth table66%2/3
A and B
A= $acceptedB= defined $tls_role
ABresult
0X0
100
111
38 if $accepted && defined $tls_role;
39 102042 my $override = Linux::Event::_SocketConfig::extract('new', \%opt);
40 102042 my $socket_descriptor = Linux::Event::_Socket::Descriptor::for_class($class);
41 102041 my ($local, $resolved_peer, $policy) = _socket_setup(
42 $fh, $socket_descriptor, $override, $peer,
43 );
44 102037 ▶ if (my $tls = $socket_descriptor->{tls}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $tls = $socket_descriptor->{'tls'}) { } 1 102036 102037
elsif (defined $tls_role) { } 0 102036 102036
45 1 ▶ if (!$accepted) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accepted) 1 0 1
46 1 ▶ croak 'new(): transport cannot be supplied for a TLS-declared Socket'
Branch: 1 branch
BranchTrueFalseTotal
if defined $transport 0 1 1
47 if defined $transport;
48 1 require Linux::Event::TLS;
49 1 ▶ croak 'new(): a TLS-declared adopted fh requires tls_role'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tls_role 1 0 1
50 if !defined $tls_role;
51 0 ▶ croak 'new(): tls_role must be client or server'
Branch: 1 branch
BranchTrueFalseTotal
if $tls_role ne "client" and $tls_role ne "server" 0 0 0
Condition0%0/3
$tls_role ne "client" and $tls_role ne "server"
!ll&&!rl&&r
000
MC/DC0%0/2
$tls_role ne "client" and $tls_role ne "server"
$tls_role ne "client" $tls_role ne "server"
Truth table0%0/3
A and B
A= $tls_role ne "client"B= $tls_role ne "server"
ABresult
0X0
100
111
52 if $tls_role ne 'client' && $tls_role ne 'server';
53 0 ▶ $transport = $tls_role eq 'server'
Branch: 1 branch
BranchTrueFalseTotal
$tls_role eq 'server' ? : 0 0 0
54 ? Linux::Event::TLS->_server_from_declaration($tls)
55 : Linux::Event::TLS->_client_from_declaration($tls);
56 }
57 # Accepted sockets acquire TLS only from the Listener recipe.
58 # A class declaration/default never activates TLS by itself.
59 } elsif (defined $tls_role) {
60 0 croak 'new(): tls_role requires a Socket subclass declaring TLS';
61 }
62 102036 my $self = $class->SUPER::new(fh => $fh, _transport => $transport, %opt);
63 101987 $self->{socket_descriptor} = $socket_descriptor;
64 101987 $self->{socket_policy} = $policy;
65 101987 $self->{local} = $local;
66 101987 $self->{peer} = $resolved_peer;
67 101987 my $configured = eval {
68 101987 ▶ $self->_configure_socket(
Branch: 1 branch
BranchTrueFalseTotal
$accepted ? : 1111 100876 101987
69 $fh, $accepted ? 'accepted' : 'adopted', $resolved_peer,
70 );
71 101986 ▶ $self->_attach_to_loop($loop) if $loop;
Branch: 1 branch
BranchTrueFalseTotal
if $loop 370 101616 101986
72 101986 1;
73 };
74 101987 ▶ if (!$configured) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($configured) 1 101986 101987
75 1 my $failure = $@;
76 1 eval { $self->_close_now(1); 1 };
77 1 die $failure;
78 }
79 101986 return $self;
80 }
81  
82 1119 ▶sub connect ($class, %opt) {
Subroutine connect: called CC=15 SCAR=27.2
Pod undocumented
83 1119 ▶ croak 'connect(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1119 1119
84 1119 my %stream;
85 1119 for my $name (qw(loop data transport idle_timeout read_timeout write_timeout deadline),
86 Linux::Event::_ByteStream::_callback_names()) {
87 17904 ▶ $stream{$name} = delete $opt{$name} if exists $opt{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{$name} 1188 16716 17904
88 }
89 1119 my $loop = delete $stream{loop};
90 1119 ▶ croak 'connect(): loop must be an object implementing add() and watch_fd()'
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch_fd") 1 1118 1119
Condition77%7/9
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch_fd")
!ll&&!rl&&r
1033851
ref $loop && $loop->can('add') && $loop->can('watch_fd')
!ll&&!rl&&r
1085
ref $loop and $loop->can("add")
!ll&&!rl&&r
1085
MC/DC50%2/4
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch_fd")
defined $loop ref $loop $loop->can("add") $loop->can('watch_fd')
Truth table60%3/5
A and not(B and C && D)
A= defined $loopB= ref $loopC= $loop->can("add")D= $loop->can('watch_fd')
ABCDresult
0XXX0
11110
10XX1
110X1
11101
91 if defined($loop) && (!ref($loop) || !$loop->can('add')
92 || !$loop->can('watch_fd'));
93 1118 my $override = Linux::Event::_SocketConfig::extract('connect', \%opt);
94 1118 my $socket_descriptor = Linux::Event::_Socket::Descriptor::for_class($class);
95 my %policy = map {
96 1118 $_ => exists($override->{$_}) ? $override->{$_}
97 8944 ▶ : $socket_descriptor->{options}{$_}
Branch: 1 branch
BranchTrueFalseTotal
exists $override->{$_} ? : 1 8943 8944
98 } Linux::Event::_SocketConfig::names();
99 1118 my $transport = delete $stream{transport};
100 1118 ▶ croak 'connect(): transport must be an object implementing _stream_transport_bind()'
Branch: 1 branch
BranchTrueFalseTotal
if defined $transport and not builtin::blessed($transport) && $transport->can("_stream_transport_bind") 1 1117 1118
Condition83%5/6
defined $transport and not builtin::blessed($transport) && $transport->can("_stream_transport_bind")
!ll&&!rl&&r
111611
builtin::blessed($transport) && $transport->can('_stream_transport_bind')
!ll&&!rl&&r
101
MC/DC66%2/3
defined $transport and not builtin::blessed($transport) && $transport->can("_stream_transport_bind")
defined $transport builtin::blessed($transport) $transport->can('_stream_transport_bind')
Truth table75%3/4
A and not(B && C)
A= defined $transportB= builtin::blessed($transport)C= $transport->can('_stream_transport_bind')
ABCresult
0XX0
1110
10X1
1101
101 if defined($transport)
102 && (!blessed($transport) || !$transport->can('_stream_transport_bind'));
103 1117 ▶ if (my $tls = $socket_descriptor->{tls}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tls = $socket_descriptor->{"tls"}) 2 1115 1117
104 2 ▶ croak 'connect(): transport cannot be supplied for a TLS-declared Socket'
Branch: 1 branch
BranchTrueFalseTotal
if defined $transport 0 2 2
105 if defined $transport;
106 2 require Linux::Event::TLS;
107 $transport = Linux::Event::TLS->_client_from_declaration(
108 $tls, $opt{host},
109 2 );
110 }
111 1117 my $self = $class->SUPER::new(
112 %stream, _pending => 1, _transport => $transport,
113 );
114 1117 $self->{socket_descriptor} = $socket_descriptor;
115 1117 $self->{socket_policy} = \%policy;
116 1117 $self->{preconnect_output} = [];
117 1117 $self->{preconnect_bytes} = 0;
118 1117 $self->{read_capable} = 1;
119 1117 $self->{write_capable} = 1;
120 1117 $self->{write_ended} = 0;
121 1117 $self->{read_closed} = 0;
122 1117 $self->{connection} = Linux::Event::_Socket::Connection->new(
123 %opt, stream => $self, socket_policy => \%policy,
124 );
125 1106 ▶ $self->_attach_to_loop($loop) if $loop;
Branch: 1 branch
BranchTrueFalseTotal
if $loop 75 1031 1106
126 1106 return $self;
127 }
128  
129 0 ▶sub CLONE ($class) {
Subroutine CLONE: not called CC=1 SCAR=6.9
130 0 Linux::Event::_Socket::Descriptor::clear_cache();
131 0 return;
132 }
133  
134 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
135  
136 # Accessors
137  
138 10 ▶sub local ($self) { $self->{local} }
Subroutine local: called CC=1 SCAR=0.0
Pod undocumented
139 9 ▶sub peer ($self) { $self->{peer} }
Subroutine peer: called CC=1 SCAR=0.0
Pod undocumented
140 6 ▶sub fd ($self) { $self->read_fd }
Subroutine fd: called CC=1 SCAR=0.0
Pod undocumented
141  
142 3 ▶sub tcp_nodelay ($self, @arg) {
Subroutine tcp_nodelay: called CC=1 SCAR=0.0
Pod undocumented
143 3 $self->_socket_option('tcp_nodelay', @arg);
144 }
145  
146 1 ▶sub keepalive ($self, @arg) {
Subroutine keepalive: called CC=1 SCAR=0.0
Pod undocumented
147 1 $self->_socket_option('keepalive', @arg);
148 }
149  
150 1 ▶sub keepalive_idle ($self, @arg) {
Subroutine keepalive_idle: called CC=1 SCAR=0.0
Pod undocumented
151 1 $self->_socket_option('keepalive_idle', @arg);
152 }
153  
154 1 ▶sub keepalive_interval ($self, @arg) {
Subroutine keepalive_interval: called CC=1 SCAR=0.0
Pod undocumented
155 1 $self->_socket_option('keepalive_interval', @arg);
156 }
157  
158 1 ▶sub keepalive_count ($self, @arg) {
Subroutine keepalive_count: called CC=1 SCAR=0.0
Pod undocumented
159 1 $self->_socket_option('keepalive_count', @arg);
160 }
161  
162 1 ▶sub tcp_user_timeout ($self, @arg) {
Subroutine tcp_user_timeout: called CC=1 SCAR=0.0
Pod undocumented
163 1 $self->_socket_option('tcp_user_timeout', @arg);
164 }
165  
166 2 ▶sub send_buffer ($self, @arg) {
Subroutine send_buffer: called CC=1 SCAR=0.0
Pod undocumented
167 2 $self->_socket_option('send_buffer', @arg);
168 }
169  
170 2 ▶sub receive_buffer ($self, @arg) {
Subroutine receive_buffer: called CC=1 SCAR=0.0
Pod undocumented
171 2 $self->_socket_option('receive_buffer', @arg);
172 }
173  
174 1 ▶sub selected_alpn ($self) {
Subroutine selected_alpn: called CC=3 SCAR=13.1
Pod undocumented
175 1 my $transport = $self->{transport};
176 1 ▶ return $transport && $transport->can('selected_alpn')
Branch: 1 branch
BranchTrueFalseTotal
$transport && $transport->can('selected_alpn') ? : 1 0 1
Condition33%1/3
$transport and $transport->can("selected_alpn")
!ll&&!rl&&r
001
MC/DC0%0/2
$transport and $transport->can("selected_alpn")
$transport $transport->can("selected_alpn")
Truth table33%1/3
A and B
A= $transportB= $transport->can("selected_alpn")
ABresult
0X0
100
111
177 ? $transport->selected_alpn : undef;
178 }
179  
180 1 ▶sub tls_protocol ($self) {
Subroutine tls_protocol: called CC=3 SCAR=13.1
Pod undocumented
181 1 my $transport = $self->{transport};
182 1 ▶ return $transport && $transport->can('protocol')
Branch: 1 branch
BranchTrueFalseTotal
$transport && $transport->can('protocol') ? : 1 0 1
Condition33%1/3
$transport and $transport->can("protocol")
!ll&&!rl&&r
001
MC/DC0%0/2
$transport and $transport->can("protocol")
$transport $transport->can("protocol")
Truth table33%1/3
A and B
A= $transportB= $transport->can("protocol")
ABresult
0X0
100
111
183 ? $transport->protocol : undef;
184 }
185  
186 1 ▶sub tls_cipher ($self) {
Subroutine tls_cipher: called CC=3 SCAR=13.1
Pod undocumented
187 1 my $transport = $self->{transport};
188 1 ▶ return $transport && $transport->can('cipher')
Branch: 1 branch
BranchTrueFalseTotal
$transport && $transport->can('cipher') ? : 1 0 1
Condition33%1/3
$transport and $transport->can("cipher")
!ll&&!rl&&r
001
MC/DC0%0/2
$transport and $transport->can("cipher")
$transport $transport->can("cipher")
Truth table33%1/3
A and B
A= $transportB= $transport->can("cipher")
ABresult
0X0
100
111
189 ? $transport->cipher : undef;
190 }
191  
192 1 ▶sub tls_stats ($self) {
Subroutine tls_stats: called CC=3 SCAR=13.1
Pod undocumented
193 1 my $transport = $self->{transport};
194 1 ▶ return $transport && $transport->can('stats')
Branch: 1 branch
BranchTrueFalseTotal
$transport && $transport->can('stats') ? : 1 0 1
Condition33%1/3
$transport and $transport->can("stats")
!ll&&!rl&&r
001
MC/DC0%0/2
$transport and $transport->can("stats")
$transport $transport->can("stats")
Truth table33%1/3
A and B
A= $transportB= $transport->can("stats")
ABresult
0X0
100
111
195 ? $transport->stats : undef;
196 }
197  
198 # Methods
199  
200 # The native queue duplicates the source descriptor and owns it until the
201 # queued file range completes or the Stream closes. Raw bytes, like write().
202 31 ▶sub sendfile ($self, $fh, %opt) {
Subroutine sendfile: called CC=27 SCAR=36.6
Pod undocumented
203 31 ▶ croak 'sendfile(): stream is closed' if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 31 31
204 croak 'sendfile(): writable side has ended'
205 31 ▶ if $self->{write_ending} || $self->{write_ended};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"write_ending"} or $self->{"write_ended"} 0 31 31
Condition33%1/3
$self->{"write_ending"} or $self->{"write_ended"}
l!l&&r!l&&!r
0031
MC/DC0%0/2
$self->{"write_ending"} or $self->{"write_ended"}
$self->{"write_ending"} $self->{"write_ended"}
Truth table33%1/3
A or B
A= $self->{"write_ending"}B= $self->{"write_ended"}
ABresult
1X1
011
000
206 croak 'sendfile(): socket must be established'
207 31 ▶ if !$self->{xs_state} || $self->{connection} && !$self->{write_fh};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"xs_state"} or $self->{"connection"} and not $self->{"write_fh"} 0 31 31
Condition33%2/6
not $self->{"xs_state"} or $self->{"connection"} and not $self->{"write_fh"}
l!l&&r!l&&!r
0031
$self->{"connection"} and not $self->{"write_fh"}
!ll&&!rl&&r
3100
MC/DC0%0/3
not $self->{"xs_state"} or $self->{"connection"} and not $self->{"write_fh"}
not $self->{"xs_state"} $self->{"connection"} not $self->{"write_fh"}
Truth table25%1/4
not(A) or B and not(C)
A= not $self->{"xs_state"}B= $self->{"connection"}C= not $self->{"write_fh"}
ABCresult
1XX1
0111
00X0
0100
208 31 ▶ croak 'sendfile(): requires a plain transport'
Branch: 1 branch
BranchTrueFalseTotal
if ($self->transport_name // "plain") ne "plain" 2 29 31
Condition50%1/2
$self->transport_name // "plain"
l!l
310
MC/DC0%0/1
$self->transport_name // "plain"
$self->transport_name
Truth table50%1/2
A
A= $self->transport_name
Aresult
11
00
209 if ($self->transport_name // 'plain') ne 'plain';
210  
211 29 ▶ my $offset = exists($opt{offset}) ? delete($opt{offset}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{'offset'} ? : 9 20 29
212 29 my $has_length = exists($opt{length});
213 29 my $length = delete $opt{length};
214 29 ▶ croak 'sendfile(): unknown options: ' . join(', ', sort keys %opt)
Branch: 1 branch
BranchTrueFalseTotal
if %opt 1 28 29
215 if %opt;
216 28 ▶ croak 'sendfile(): offset must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $offset or ref $offset or not "$offset" =~ /\A(?:0|[1-9][0-9]*)\z/u 1 27 28
Condition50%3/6
not defined $offset or ref $offset or not "$offset" =~ /\A(?:0|[1-9][0-9]*)\z/u
l!l&&r!l&&!r
0127
not defined $offset or ref $offset
l!l&&r!l&&!r
0028
MC/DC33%1/3
not defined $offset or ref $offset or not "$offset" =~ /\A(?:0|[1-9][0-9]*)\z/u
not defined $offset ref $offset not "$offset" =~ /\A(?:0|[1-9][0-9]*)\z/u
Truth table50%2/4
not(A) or B or not(C)
A= not defined $offsetB= ref $offsetC= not "$offset" =~ /\A(?:0|[1-9][0-9]*)\z/u
ABCresult
1XX1
01X1
0011
0000
217 if !defined($offset) || ref($offset)
218 || "$offset" !~ /\A(?:0|[1-9][0-9]*)\z/;
219 27 ▶ croak 'sendfile(): length must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
if $has_length and !defined($length) || ref $length || !("$length" =~ /\A(?:0|[1-9][0-9]*)\z/u) 1 26 27
Condition66%6/9
$has_length and !defined($length) || ref $length || !("$length" =~ /\A(?:0|[1-9][0-9]*)\z/u)
!ll&&!rl&&r
1881
not defined $length or ref $length or not "$length" =~ /\A(?:0|[1-9][0-9]*)\z/u
l!l&&r!l&&!r
018
not defined $length or ref $length
l!l&&r!l&&!r
009
MC/DC50%2/4
$has_length and !defined($length) || ref $length || !("$length" =~ /\A(?:0|[1-9][0-9]*)\z/u)
$has_length not defined $length ref $length not "$length" =~ /\A(?:0|[1-9][0-9]*)\z/u
Truth table60%3/5
A and not(B) or C or not(D)
A= $has_lengthB= not defined $lengthC= ref $lengthD= not "$length" =~ /\A(?:0|[1-9][0-9]*)\z/u
ABCDresult
0XXX0
10000
11XX1
101X1
10011
220 if $has_length && (!defined($length) || ref($length)
221 || "$length" !~ /\A(?:0|[1-9][0-9]*)\z/);
222  
223 26 ▶ croak 'sendfile(): requires an open regular-file handle'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fh and defined fileno $fh 0 26 26
Condition33%1/3
ref $fh and defined fileno $fh
!ll&&!rl&&r
0026
MC/DC0%0/2
ref $fh and defined fileno $fh
ref $fh defined fileno $fh
Truth table33%1/3
A and B
A= ref $fhB= defined fileno $fh
ABresult
0X0
100
111
224 if !ref($fh) || !defined(fileno($fh));
225 26 my $fd = fileno($fh);
226 26 my $was_pending = $self->pending_bytes;
227 my $status = $self->{xs_state}->_sendfile(
228 26 ▶ $fd, $offset, $has_length ? $length : 0, $has_length,
Branch: 1 branch
BranchTrueFalseTotal
$has_length ? : 8 18 26
229 );
230 22 ▶ $self->_request_write_ready if $status & 0x02;
Branch: 1 branch
BranchTrueFalseTotal
if $status & 2 16 6 22
231 22 ▶ if ($self->{deadline_started} && $self->{timeout}{write_timeout} > 0
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"deadline_started"} and $self->{"timeout"}{"write_timeout"} > 0 and not $was_pending and $self->pending_bytes > 0) 1 21 22
Condition77%7/9
$self->{"deadline_started"} and $self->{"timeout"}{"write_timeout"} > 0 and not $was_pending and $self->pending_bytes > 0
!ll&&!rl&&r
2101
$self->{"deadline_started"} and $self->{"timeout"}{"write_timeout"} > 0 and not $was_pending
!ll&&!rl&&r
2101
$self->{"deadline_started"} and $self->{"timeout"}{"write_timeout"} > 0
!ll&&!rl&&r
7141
MC/DC50%2/4
$self->{"deadline_started"} and $self->{"timeout"}{"write_timeout"} > 0 and not $was_pending and $self->pending_bytes > 0
$self->{"deadline_started"} $self->{"timeout"}{"write_timeout"} > 0 not $was_pending $self->pending_bytes > 0
Truth table60%3/5
A and B and not(C) and D
A= $self->{"deadline_started"}B= $self->{"timeout"}{"write_timeout"} > 0C= not $was_pendingD= $self->pending_bytes > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
232 && !$was_pending && $self->pending_bytes > 0) {
233 $self->{deadline_write_started}
234 1 = Linux::Event::_ByteStream::_deadline_now();
235 1 $self->_rearm_stream_deadline;
236 }
237 22 ▶ return $status & 0x01 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$status & 1 ? : 7 15 22
238 }
239  
240 0 ▶sub close_read ($self) {
Subroutine close_read: not called CC=7 SCAR=40.3
Pod undocumented
241 0 ▶ return $self if $self->{closed} || $self->{read_closed} || $self->{read_eof};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} or $self->{"read_closed"} or $self->{"read_eof"} 0 0 0
Condition0%0/6
$self->{"closed"} or $self->{"read_closed"} or $self->{"read_eof"}
l!l&&r!l&&!r
000
$self->{"closed"} or $self->{"read_closed"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"closed"} or $self->{"read_closed"} or $self->{"read_eof"}
$self->{"closed"} $self->{"read_closed"} $self->{"read_eof"}
Truth table0%0/4
A or B or C
A= $self->{"closed"}B= $self->{"read_closed"}C= $self->{"read_eof"}
ABCresult
1XX1
01X1
0011
0000
242 0 ▶ croak 'close_read(): directional close is unavailable for TLS sockets'
Branch: 1 branch
BranchTrueFalseTotal
if ($self->transport_name // "plain") ne "plain" 0 0 0
Condition0%0/2
$self->transport_name // "plain"
l!l
00
MC/DC0%0/1
$self->transport_name // "plain"
$self->transport_name
Truth table0%0/2
A
A= $self->transport_name
Aresult
11
00
243 if ($self->transport_name // 'plain') ne 'plain';
244 0 ▶ shutdown($self->fh, SHUT_RD) or do {
Branch: 1 branch
BranchTrueFalseTotal
shutdown $self->fh, 0 or do { my $errno = 0 + $!; $self->_fail_io("shutdown_read", $errno); return $self } 0 0 0
245 0 my $errno = 0 + $!;
246 0 $self->_fail_io('shutdown_read', $errno);
247 0 return $self;
248 };
249 0 return $self->SUPER::close_read;
250 }
251  
252 1 ▶sub close_write ($self) {
Subroutine close_write: called CC=6 SCAR=23.5
Pod undocumented
253 1 ▶ return $self if $self->{closed} || $self->{write_ended};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} or $self->{"write_ended"} 0 1 1
Condition33%1/3
$self->{"closed"} or $self->{"write_ended"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{"closed"} or $self->{"write_ended"}
$self->{"closed"} $self->{"write_ended"}
Truth table33%1/3
A or B
A= $self->{"closed"}B= $self->{"write_ended"}
ABresult
1X1
011
000
254 1 ▶ croak 'close_write(): use end() for TLS sockets'
Branch: 1 branch
BranchTrueFalseTotal
if ($self->transport_name // "plain") ne "plain" 0 1 1
Condition50%1/2
$self->transport_name // "plain"
l!l
10
MC/DC0%0/1
$self->transport_name // "plain"
$self->transport_name
Truth table50%1/2
A
A= $self->transport_name
Aresult
11
00
255 if ($self->transport_name // 'plain') ne 'plain';
256 1 ▶ shutdown($self->fh, SHUT_WR) or do {
Branch: 1 branch
BranchTrueFalseTotal
shutdown $self->fh, 1 or do { my $errno = 0 + $!; $self->_fail_io("shutdown_write", $errno); return $self } 1 0 1
257 0 my $errno = 0 + $!;
258 0 $self->_fail_io('shutdown_write', $errno);
259 0 return $self;
260 };
261 1 return $self->SUPER::close_write;
262 }
263  
264 100494 ▶sub detach ($self) {
Subroutine detach: called CC=1 SCAR=0.0
Pod undocumented
265 100494 my $handles = $self->SUPER::detach;
266 100492 return $handles->{read_fh};
267 }
268  
269 # Private helpers and internal overrides
270  
271 0 ▶sub _declare_tls ($base, $target, $definition) {
Subroutine _declare_tls: not called CC=1 SCAR=6.9
272 0 Linux::Event::_Socket::Descriptor::declare_tls($base, $target, $definition);
273 }
274  
275 102041 ▶sub _socket_type ($fh) {
Subroutine _socket_type: called CC=4 SCAR=13.9
276 102041 my $packed = getsockopt($fh, SOL_SOCKET, SO_TYPE);
277 102041 ▶ croak 'new(): fh is not a socket' if !defined($packed) || length($packed) < 4;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $packed or length $packed < 4 2 102039 102041
Condition66%2/3
not defined $packed or length $packed < 4
l!l&&r!l&&!r
20102039
MC/DC50%1/2
not defined $packed or length $packed < 4
not defined $packed length $packed < 4
Truth table66%2/3
not(A) or B
A= not defined $packedB= length $packed < 4
ABresult
1X1
011
000
278 102039 ▶ croak 'new(): fh is not a SOCK_STREAM socket'
Branch: 1 branch
BranchTrueFalseTotal
if unpack("i", $packed) != 1 1 102038 102039
279 if unpack('i', $packed) != SOCK_STREAM;
280 102038 return;
281 }
282  
283 102041 ▶sub _socket_setup ($fh, $descriptor, $override, $peer) {
Subroutine _socket_setup: called CC=6 SCAR=18.3
284 102041 _socket_type($fh);
285 102038 my $packed_local = getsockname($fh);
286 102038 ▶ croak 'new(): could not obtain local socket address'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packed_local 0 102038 102038
287 if !defined $packed_local;
288 102038 my $local = Linux::Event::Address->new($packed_local);
289 my %policy = map {
290 102038 $_ => exists($override->{$_})
291 816304 ▶ ? $override->{$_} : $descriptor->{options}{$_}
Branch: 1 branch
BranchTrueFalseTotal
exists $override->{$_} ? : 0 816304 816304
292 } Linux::Event::_SocketConfig::names();
293 102038 Linux::Event::_SocketConfig::apply_policy(
294 $fh, $local->family_number, \%policy,
295 );
296 102037 ▶ if (!defined $peer) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $peer) 100926 1111 102037
297 100926 my $packed_peer = getpeername($fh);
298 100926 ▶ $peer = Linux::Event::Address->new($packed_peer)
Branch: 1 branch
BranchTrueFalseTotal
if defined $packed_peer 100926 0 100926
299 if defined $packed_peer;
300 }
301 102037 ▶ croak 'new(): fh is not a connected SOCK_STREAM socket' if !defined $peer;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $peer 0 102037 102037
302 102037 return ($local, $peer, \%policy);
303 }
304  
305 1 ▶sub _validate_accepted_configuration ($class) {
Subroutine _validate_accepted_configuration: called CC=2 SCAR=15.1
306 1 my $descriptor = Linux::Event::_Socket::Descriptor::for_class($class);
307 0 ▶ if (my $tls = $descriptor->{tls}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tls = $descriptor->{"tls"}) 0 0 0
308 0 require Linux::Event::TLS;
309 0 Linux::Event::TLS->_server_from_declaration($tls);
310 }
311 0 return;
312 }
313  
314 103086 ▶sub _configure_socket ($self, $fh, $role, $address) {
Subroutine _configure_socket: called CC=4 SCAR=13.9
315 103086 ▶ my $callback = $self->{socket_descriptor}{configure_socket} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $callback = $self->{"socket_descriptor"}{"configure_socket"} or return 3 103083 103086
316 3 my $ok = eval { $callback->($self, $fh, $role, $address); 1 };
317 3 ▶ return if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 2 1 3
318 1 my $message = "$@";
319 1 $message =~ s/\s+\z//;
320 1 ▶ die Linux::Event::Error->new(
Condition50%1/2
$message || 'configure_socket callback failed'
l!l
10
MC/DC0%0/1
$message || 'configure_socket callback failed'
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
321 type => 'socket_configuration', operation => 'configure_socket',
322 message => $message || 'configure_socket callback failed',
323 );
324 }
325  
326 1102 ▶sub _attach_pending ($self, $loop) {
Subroutine _attach_pending: called CC=1 SCAR=0.0
327 1102 $self->{connection}->_attach_to_loop($loop);
328 1102 return;
329 }
330  
331 2590 ▶sub _cancel_pending ($self) {
Subroutine _cancel_pending: called CC=2 SCAR=6.9
332 2590 ▶ if (my $connection = delete $self->{connection}) { $connection->cancel }
Branch: 1 branch
BranchTrueFalseTotal
if (my $connection = delete $self->{"connection"}) 5 2585 2590
333 2590 return;
334 }
335  
336 1095 ▶sub _connect_succeeded ($self, $fh) {
Subroutine _connect_succeeded: called CC=8 SCAR=21.5
337 1095 ▶ return if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 1095 1095
338 1095 delete $self->{connection};
339 1095 my $packed_local = getsockname($fh);
340 1095 $self->{local} = Linux::Event::Address->new($packed_local);
341 1095 my $packed_peer = getpeername($fh);
342 1095 ▶ $self->{peer} = Linux::Event::Address->new($packed_peer)
Branch: 1 branch
BranchTrueFalseTotal
if defined $packed_peer 1095 0 1095
343 if defined $packed_peer;
344 1095 $self->{read_fh} = $fh;
345 1095 $self->{write_fh} = $fh;
346 1095 my $prepared = eval { $self->_prepare_handles; $self->_register_handles; 1 };
347 1095 ▶ if (!$prepared) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prepared) 0 1095 1095
348 0 $self->_fail(Linux::Event::Error->new(
349 type => 'connect', operation => 'attach', message => $@,
350 ));
351 0 return;
352 }
353 1095 my $transport = $self->{transport};
354 1095 ▶ if ($transport && $transport->can('_stream_transport_start')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transport and $transport->can("_stream_transport_start")) 1 1094 1095
Condition66%2/3
$transport and $transport->can("_stream_transport_start")
!ll&&!rl&&r
109401
MC/DC50%1/2
$transport and $transport->can("_stream_transport_start")
$transport $transport->can("_stream_transport_start")
Truth table66%2/3
A and B
A= $transportB= $transport->can("_stream_transport_start")
ABresult
0X0
100
111
355 1 my $started = eval { $transport->_stream_transport_start($self); 1 };
356 1 ▶ if (!$started) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($started) 0 1 1
357 0 $self->_fail(Linux::Event::Error->new(
358 type => 'transport', operation => 'start', message => $@,
359 ));
360 0 return;
361 }
362 }
363 1095 $self->_flush_preconnect_output;
364 1095 ▶ if (!$transport) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($transport) 1094 1 1095
365 1094 $self->_start_stream_deadlines;
366 1094 $self->_fire_ready;
367 }
368 1095 return;
369 }
370  
371 6 ▶sub _connect_failed ($self, $error) {
Subroutine _connect_failed: called CC=2 SCAR=7.1
372 6 ▶ return if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 6 6
373 6 delete $self->{connection};
374 6 $self->_fail($error);
375 }
376  
377 40523 ▶sub _on_read_terminal_ready ($self) {
Subroutine _on_read_terminal_ready: called CC=5 SCAR=19.1
378 40523 ▶ return if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 40523 40523
379 40523 my $packed = getsockopt($self->fh, SOL_SOCKET, SO_ERROR);
380 40523 ▶ if (defined($packed) && length($packed) >= 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packed and length $packed >= 4) 40523 0 40523
Condition33%1/3
defined $packed and length $packed >= 4
!ll&&!rl&&r
0040523
MC/DC0%0/2
defined $packed and length $packed >= 4
defined $packed length $packed >= 4
Truth table33%1/3
A and B
A= defined $packedB= length $packed >= 4
ABresult
0X0
100
111
381 40523 my $errno = unpack('i', $packed);
382 0 ▶ if ($errno) { $self->_fail_io('socket', $errno); return }
Branch: 1 branch
BranchTrueFalseTotal
if ($errno) 0 40523 40523
383 }
384 40523 $self->SUPER::_on_read_terminal_ready;
385 }
386  
387 16 ▶sub _finish_transport_write ($self) {
Subroutine _finish_transport_write: called CC=12 SCAR=33.2
388 16 ▶ if (!$self->{transport_shutdown_started}++ && $self->{transport}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"transport_shutdown_started"}++ and $self->{"transport"} and $self->{"transport"}->can("_stream_transport_begin_shutdown")) 3 13 16
Condition66%4/6
not $self->{"transport_shutdown_started"}++ and $self->{"transport"} and $self->{"transport"}->can("_stream_transport_begin_shutdown")
!ll&&!rl&&r
1303
not $self->{"transport_shutdown_started"}++ and $self->{"transport"}
!ll&&!rl&&r
0133
MC/DC33%1/3
not $self->{"transport_shutdown_started"}++ and $self->{"transport"} and $self->{"transport"}->can("_stream_transport_begin_shutdown")
not $self->{"transport_shutdown_started"}++ $self->{"transport"} $self->{"transport"}->can("_stream_transport_begin_shutdown")
Truth table50%2/4
not(A) and B and C
A= not $self->{"transport_shutdown_started"}++B= $self->{"transport"}C= $self->{"transport"}->can("_stream_transport_begin_shutdown")
ABCresult
0XX0
10X0
1100
1111
389 && $self->{transport}->can('_stream_transport_begin_shutdown')) {
390 3 my $ok = eval {
391 3 $self->{transport}->_stream_transport_begin_shutdown($self); 1;
392 };
393 3 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 3 3
394 0 ▶ $self->_fail(Linux::Event::Error->new(
Condition0%0/2
$@ || 'transport shutdown setup failed'
l!l
00
MC/DC0%0/1
$@ || 'transport shutdown setup failed'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
395 type => $self->transport_name, operation => 'shutdown',
396 message => $@ || 'transport shutdown setup failed',
397 ));
398 0 return 0;
399 }
400 }
401 16 my ($status, $errno, $message) = $self->{xs_state}->_shutdown_write;
402 16 ▶ if ($status == 2) { $self->{read_watcher}->enable_read; return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 2) 1 15 16
403 0 ▶ if ($status == 3) { $self->{write_watcher}->enable_write; return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 3) 0 15 15
404 15 ▶ if ($status == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 5) 0 15 15
405 0 ▶ if (($self->transport_name // 'plain') ne 'plain') {
Branch: 1 branch
BranchTrueFalseTotal
if (($self->transport_name // 'plain') ne 'plain') { } 0 0 0
Condition0%0/2
$self->transport_name // "plain"
l!l
00
MC/DC0%0/1
$self->transport_name // "plain"
$self->transport_name
Truth table0%0/2
A
A= $self->transport_name
Aresult
11
00
406 0 ▶ $self->_fail(Linux::Event::Error->new(
Condition0%0/2
$message || 'transport shutdown failed'
l!l
00
MC/DC0%0/1
$message || 'transport shutdown failed'
$message
Truth table0%0/2
A
A= $message
Aresult
11
00
407 type => $self->transport_name, operation => 'shutdown',
408 message => $message || 'transport shutdown failed',
409 ));
410 } else {
411 0 $self->_fail_io('shutdown', $errno);
412 }
413 0 return 0;
414 }
415 15 return 1;
416 }
417  
418 12 ▶sub _socket_option ($self, $name, @argument) {
Subroutine _socket_option: called CC=5 SCAR=17.2
419 12 ▶ croak "$name(): Socket is not established" if $self->{closed} || !$self->fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} or not $self->fh 0 12 12
Condition33%1/3
$self->{"closed"} or not $self->fh
l!l&&r!l&&!r
0012
MC/DC0%0/2
$self->{"closed"} or not $self->fh
$self->{"closed"} not $self->fh
Truth table33%1/3
A or not(B)
A= $self->{"closed"}B= not $self->fh
ABresult
1X1
011
000
420 12 ▶ croak "$name(): expected zero or one argument" if @argument > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @argument > 1 0 12 12
421 12 my $family = $self->{local}->family_number;
422 12 ▶ Linux::Event::_SocketConfig::set_option(
Branch: 1 branch
BranchTrueFalseTotal
if @argument 3 9 12
423 $self->fh, $family, $name, $argument[0],
424 ) if @argument;
425 12 return Linux::Event::_SocketConfig::get_option($self->fh, $family, $name);
426 }
427  
428 120 1;
« blib/lib/Linux/Event/Kernel/Process.pm ↑ Summary blib/lib/Linux/Event/Framer/LengthPrefix.pm »