MCE/Util.pm

filter: Statementstmt 49.7% 113 / 227 Branchbran 22.8% 38 / 166 Conditioncond 37.5% 9 / 24 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 73.9% 17 / 23 Podpod 100% 1 / 1 totaltotal 39.5% 180 / 455 CC 96 SCAR 50.7
CC
96
Cov
38%
get_ncpu
510.1
_sock_ready
132.0
_sysread2
110.0
CRAP 159.8
« MCE/Stream.pm ↑ Summary MCE/Signal.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Utility functions.
4 ##
5 ###############################################################################
6  
7 package MCE::Util;
8  
9 113 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 113 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 113 ▶no warnings qw( threads recursion uninitialized numeric );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 113 our $VERSION = '1.904';
15  
16 ## no critic (BuiltinFunctions::ProhibitStringyEval)
17  
18 113 ▶use IO::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 113 ▶use Socket qw( AF_UNIX SOL_SOCKET SO_SNDBUF SO_RCVBUF );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 113 ▶use Time::HiRes qw( sleep time );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 113 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 113 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 113 my ($_is_winenv, $_zero_bytes, %_sock_ready);
25  
26 113 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.2
27 113 ▶ $_is_winenv = ( $^O =~ /mswin|mingw|msys|cygwin/i ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin|mingw|msys|cygwin/i ? : 0 113 113
28 113 $_zero_bytes = pack('L', 0);
29 }
30  
31 0 ▶sub CLONE {
Subroutine CLONE: not called CC=1 SCAR=6.9
32 0 %_sock_ready = ();
33 }
34  
35 113 our $LF = "\012"; Internals::SvREADONLY($LF, 1);
36  
37 113 our @EXPORT_OK = qw( $LF get_ncpu );
38 113 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
39  
40 ###############################################################################
41 ## ----------------------------------------------------------------------------
42 ## The get_ncpu subroutine, largely adopted from Test::Smoke::Util.pm,
43 ## returns the number of logical (online/active/enabled) CPU cores;
44 ## never smaller than one.
45 ##
46 ## A warning is emitted to STDERR when it cannot recognize the operating
47 ## system or the external command failed.
48 ##
49 ###############################################################################
50  
51 113 my $g_ncpu;
52  
53 81 ▶sub get_ncpu {
Subroutine get_ncpu: called CC=30 SCAR=62.3
Pod documented
54 81 ▶ return $g_ncpu if (defined $g_ncpu);
Branch: 1 branch
BranchTrueFalseTotal
if defined $g_ncpu 5 76 81
55  
56 76 local $ENV{PATH} = "/usr/sbin:/sbin:/usr/bin:/bin:$ENV{PATH}";
57 76 $ENV{PATH} =~ /(.*)/; $ENV{PATH} = $1; ## Remove tainted'ness
58  
59 76 my $ncpu = 1;
60  
61 OS_CHECK: {
62 76 local $_ = lc $^O;
63  
64 76 ▶ /linux|android/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/linux|android/ and do { my($count, $fh); if (open $fh, "<", "/proc/stat") { $count = grep({/^cpu\d/;} readline $fh); close $fh; } elsif (open $fh, "<", "/proc/cpuinfo") { $count = grep({/^processor/;} readline $fh); close $fh; } ; $ncpu = $count if $count; last OS_CHECK } 76 0 76
65 76 my ( $count, $fh );
66 76 ▶ if ( open $fh, '<', '/proc/stat' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (open $fh, '<', '/proc/stat') { } 76 0 76
elsif (open $fh, '<', '/proc/cpuinfo') { } 0 0 0
67 76 $count = grep { /^cpu\d/ } <$fh>;
68 76 close $fh;
69 }
70 elsif ( open $fh, '<', '/proc/cpuinfo' ) {
71 0 $count = grep { /^processor/ } <$fh>;
72 0 close $fh;
73 }
74 76 ▶ $ncpu = $count if $count;
Branch: 1 branch
BranchTrueFalseTotal
if $count 76 0 76
75 76 last OS_CHECK;
76 };
77  
78 0 ▶ /bsd|darwin|dragonfly/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/bsd|darwin|dragonfly/ and do { chomp(my(@output) = `sysctl -n hw.ncpu 2>/dev/null`); $ncpu = $output[0] if @output; last OS_CHECK } 0 0 0
79 0 chomp( my @output = `sysctl -n hw.ncpu 2>/dev/null` );
80 0 ▶ $ncpu = $output[0] if @output;
Branch: 1 branch
BranchTrueFalseTotal
if @output 0 0 0
81 0 last OS_CHECK;
82 };
83  
84 0 ▶ /aix/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/aix/ and do { my(@output) = `lparstat -i 2>/dev/null | grep "^Online Virtual CPUs"`; if (@output) { $output[0] =~ /(\d+)\n$/; $ncpu = $1 if $1; } ; unless ($ncpu) { @output = `pmcycles -m 2>/dev/null`; if (@output) { $ncpu = scalar @output; } else { @output = `lsdev -Cc processor -S Available 2>/dev/null`; $ncpu = scalar @output if @output; } ; } ; last OS_CHECK } 0 0 0
85 0 my @output = `lparstat -i 2>/dev/null | grep "^Online Virtual CPUs"`;
86 0 ▶ if ( @output ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@output) 0 0 0
87 0 $output[0] =~ /(\d+)\n$/;
88 0 ▶ $ncpu = $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
89 }
90 0 ▶ if ( !$ncpu ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ncpu) 0 0 0
91 0 @output = `pmcycles -m 2>/dev/null`;
92 0 ▶ if ( @output ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@output) { } 0 0 0
93 0 $ncpu = scalar @output;
94 } else {
95 0 @output = `lsdev -Cc processor -S Available 2>/dev/null`;
96 0 ▶ $ncpu = scalar @output if @output;
Branch: 1 branch
BranchTrueFalseTotal
if @output 0 0 0
97 }
98 }
99 0 last OS_CHECK;
100 };
101  
102 0 ▶ /gnu/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/gnu/ and do { chomp(my(@output) = `nproc 2>/dev/null`); $ncpu = $output[0] if @output; last OS_CHECK } 0 0 0
103 0 chomp( my @output = `nproc 2>/dev/null` );
104 0 ▶ $ncpu = $output[0] if @output;
Branch: 1 branch
BranchTrueFalseTotal
if @output 0 0 0
105 0 last OS_CHECK;
106 };
107  
108 0 ▶ /haiku/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/haiku/ and do { my(@output) = `sysinfo -cpu 2>/dev/null | grep "^CPU #"`; $ncpu = scalar @output if @output; last OS_CHECK } 0 0 0
109 0 my @output = `sysinfo -cpu 2>/dev/null | grep "^CPU #"`;
110 0 ▶ $ncpu = scalar @output if @output;
Branch: 1 branch
BranchTrueFalseTotal
if @output 0 0 0
111 0 last OS_CHECK;
112 };
113  
114 0 ▶ /hp-?ux/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/hp-?ux/ and do { my $count = grep({/^processor/;} `ioscan -fkC processor 2>/dev/null`); $ncpu = $count if $count; last OS_CHECK } 0 0 0
115 0 my $count = grep { /^processor/ } `ioscan -fkC processor 2>/dev/null`;
116 0 ▶ $ncpu = $count if $count;
Branch: 1 branch
BranchTrueFalseTotal
if $count 0 0 0
117 0 last OS_CHECK;
118 };
119  
120 0 ▶ /irix/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/irix/ and do { my(@out) = grep({/\s+processors?$/i;} `hinv -c processor 2>/dev/null`); $ncpu = (split(' ', $out[0], 0))[0] if @out; last OS_CHECK } 0 0 0
121 0 my @out = grep { /\s+processors?$/i } `hinv -c processor 2>/dev/null`;
122 0 ▶ $ncpu = (split ' ', $out[0])[0] if @out;
Branch: 1 branch
BranchTrueFalseTotal
if @out 0 0 0
123 0 last OS_CHECK;
124 };
125  
126 0 ▶ /osf|solaris|sunos|svr5|sco/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/osf|solaris|sunos|svr5|sco/ and do { if (-x "/usr/sbin/psrinfo") { my $count = grep({/on-?line/;} `psrinfo 2>/dev/null`); $ncpu = $count if $count; } else { my(@output) = grep({/^NumCPU = \d+/;} `uname -X 2>/dev/null`); $ncpu = (split(' ', $output[0], 0))[2] if @output; } ; last OS_CHECK } 0 0 0
127 0 ▶ if (-x '/usr/sbin/psrinfo') {
Branch: 1 branch
BranchTrueFalseTotal
if (-x '/usr/sbin/psrinfo') { } 0 0 0
128 0 my $count = grep { /on-?line/ } `psrinfo 2>/dev/null`;
129 0 ▶ $ncpu = $count if $count;
Branch: 1 branch
BranchTrueFalseTotal
if $count 0 0 0
130 }
131 else {
132 0 my @output = grep { /^NumCPU = \d+/ } `uname -X 2>/dev/null`;
133 0 ▶ $ncpu = (split ' ', $output[0])[2] if @output;
Branch: 1 branch
BranchTrueFalseTotal
if @output 0 0 0
134 }
135 0 last OS_CHECK;
136 };
137  
138 0 ▶ /mswin|mingw|msys|cygwin/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/mswin|mingw|msys|cygwin/ and do { if (exists $ENV{"NUMBER_OF_PROCESSORS"}) { $ncpu = $ENV{"NUMBER_OF_PROCESSORS"}; } ; last OS_CHECK } 0 0 0
139 0 ▶ if (exists $ENV{NUMBER_OF_PROCESSORS}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"NUMBER_OF_PROCESSORS"}) 0 0 0
140 0 $ncpu = $ENV{NUMBER_OF_PROCESSORS};
141 }
142 0 last OS_CHECK;
143 };
144  
145 0 warn "MCE::Util::get_ncpu: command failed or unknown operating system\n";
146 }
147  
148 76 ▶ $ncpu = 1 if (!$ncpu || $ncpu < 1);
Branch: 1 branch
BranchTrueFalseTotal
if not $ncpu or $ncpu < 1 0 76 76
Condition33%1/3
not $ncpu or $ncpu < 1
l!l&&r!l&&!r
0076
MC/DC0%0/2
not $ncpu or $ncpu < 1
not $ncpu $ncpu < 1
Truth table33%1/3
not(A) or B
A= not $ncpuB= $ncpu < 1
ABresult
1X1
011
000
149  
150 76 return $g_ncpu = $ncpu;
151 }
152  
153 ###############################################################################
154 ## ----------------------------------------------------------------------------
155 ## Private methods for pipes and sockets.
156 ##
157 ###############################################################################
158  
159 211 ▶sub _destroy_pipes {
Subroutine _destroy_pipes: called CC=8 SCAR=27.7
160 211 my ($_obj, @_params) = @_;
161 211 local ($!,$?); local $SIG{__DIE__};
162  
163 211 for my $_p (@_params) {
164 422 ▶ next unless (defined $_obj->{$_p});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_obj->{$_p} 0 422 422
165  
166 422 ▶ if (ref $_obj->{$_p} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_obj->{$_p} eq 'ARRAY') { } 0 422 422
167 0 for my $_i (0 .. @{ $_obj->{$_p} } - 1) {
168 0 ▶ next unless (defined $_obj->{$_p}[$_i]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_obj->{$_p}[$_i] 0 0 0
169 0 ▶ close $_obj->{$_p}[$_i] if (fileno $_obj->{$_p}[$_i]);
Branch: 1 branch
BranchTrueFalseTotal
if fileno $_obj->{$_p}[$_i] 0 0 0
170 0 undef $_obj->{$_p}[$_i];
171 }
172 }
173 else {
174 422 ▶ close $_obj->{$_p} if (fileno $_obj->{$_p});
Branch: 1 branch
BranchTrueFalseTotal
if fileno $_obj->{$_p} 422 0 422
175 422 undef $_obj->{$_p};
176 }
177 }
178  
179 211 return;
180 }
181  
182 110 ▶sub _destroy_socks {
Subroutine _destroy_socks: called CC=10 SCAR=23.3
183 110 my ($_obj, @_params) = @_;
184 110 local ($!,$?,$@); local $SIG{__DIE__};
185  
186 110 for my $_p (@_params) {
187 814 ▶ next unless (defined $_obj->{$_p});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_obj->{$_p} 172 642 814
188  
189 642 ▶ if (ref $_obj->{$_p} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_obj->{$_p} eq 'ARRAY') { } 166 476 642
190 166 for my $_i (0 .. @{ $_obj->{$_p} } - 1) {
191 538 ▶ next unless (defined $_obj->{$_p}[$_i]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_obj->{$_p}[$_i] 0 538 538
192 538 ▶ if (fileno $_obj->{$_p}[$_i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (fileno $_obj->{$_p}[$_i]) 538 0 538
193 538 ▶ syswrite($_obj->{$_p}[$_i], '0') if $_is_winenv;
Branch: 1 branch
BranchTrueFalseTotal
if $_is_winenv 0 538 538
194 538 eval q{ CORE::shutdown($_obj->{$_p}[$_i], 2) };
195 538 close $_obj->{$_p}[$_i];
196 }
197 538 undef $_obj->{$_p}[$_i];
198 }
199 }
200 else {
201 476 ▶ if (fileno $_obj->{$_p}) {
Branch: 1 branch
BranchTrueFalseTotal
if (fileno $_obj->{$_p}) 476 0 476
202 476 ▶ syswrite($_obj->{$_p}, '0') if $_is_winenv;
Branch: 1 branch
BranchTrueFalseTotal
if $_is_winenv 0 476 476
203 476 eval q{ CORE::shutdown($_obj->{$_p}, 2) };
204 476 close $_obj->{$_p};
205 }
206 476 undef $_obj->{$_p};
207 }
208 }
209  
210 110 return;
211 }
212  
213 473 ▶sub _pipe_pair {
Subroutine _pipe_pair: called CC=4 SCAR=17.3
214 473 my ($_obj, $_r_sock, $_w_sock, $_i) = @_;
215 473 local $!;
216  
217 473 ▶ if (defined $_i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_i) { } 0 473 473
218 # remove tainted'ness
219 0 ($_i) = $_i =~ /(.*)/;
220 0 ▶ pipe($_obj->{$_r_sock}[$_i], $_obj->{$_w_sock}[$_i]) or die "pipe: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
pipe $_obj->{$_r_sock}[$_i], $_obj->{$_w_sock}[$_i] or die "pipe: $!\n" 0 0 0
221 0 $_obj->{$_w_sock}[$_i]->autoflush(1);
222 }
223 else {
224 473 ▶ pipe($_obj->{$_r_sock}, $_obj->{$_w_sock}) or die "pipe: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
pipe $_obj->{$_r_sock}, $_obj->{$_w_sock} or die "pipe: $!\n" 473 0 473
225 473 $_obj->{$_w_sock}->autoflush(1);
226 }
227  
228 473 return;
229 }
230  
231 1111 ▶sub _sock_pair {
Subroutine _sock_pair: called CC=16 SCAR=34.3
232 1111 my ($_obj, $_r_sock, $_w_sock, $_i, $_seq) = @_;
233 1111 my $_size = 16384; local ($!, $@);
234  
235 1111 ▶ if (defined $_i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_i) { } 587 524 1111
236 # remove tainted'ness
237 587 ($_i) = $_i =~ /(.*)/;
238  
239 587 ▶ if ($_seq && $^O eq 'linux' && eval q{ Socket::SOCK_SEQPACKET() }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_seq and $^O eq 'linux' and eval ' Socket::SOCK_SEQPACKET() ') { } 447 140 587
Condition66%4/6
$_seq and $^O eq "linux" and eval " Socket::SOCK_SEQPACKET() "
!ll&&!rl&&r
1400447
$_seq and $^O eq "linux"
!ll&&!rl&&r
1400447
MC/DC33%1/3
$_seq and $^O eq "linux" and eval " Socket::SOCK_SEQPACKET() "
$_seq $^O eq "linux" eval " Socket::SOCK_SEQPACKET() "
Truth table50%2/4
A and B and C
A= $_seqB= $^O eq "linux"C= eval " Socket::SOCK_SEQPACKET() "
ABCresult
0XX0
10X0
1100
1111
240 socketpair( $_obj->{$_r_sock}[$_i], $_obj->{$_w_sock}[$_i],
241 447 ▶ AF_UNIX, Socket::SOCK_SEQPACKET(), 0 ) or do {
Branch: 1 branch
BranchTrueFalseTotal
socketpair $_obj->{$_r_sock}[$_i], $_obj->{$_w_sock}[$_i], 1, 5, 0 or do { socketpair $_obj->{$_r_sock}[$_i], $_obj->{$_w_sock}[$_i], 1, 1, 0 or die "socketpair: $!\n" } 447 0 447
242 0 ▶ socketpair( $_obj->{$_r_sock}[$_i], $_obj->{$_w_sock}[$_i],
Branch: 1 branch
BranchTrueFalseTotal
socketpair $_obj->{$_r_sock}[$_i], $_obj->{$_w_sock}[$_i], 1, 1, 0 or die "socketpair: $!\n" 0 0 0
243 AF_UNIX, Socket::SOCK_STREAM(), 0 ) or die "socketpair: $!\n";
244 };
245 }
246 else {
247 140 ▶ socketpair( $_obj->{$_r_sock}[$_i], $_obj->{$_w_sock}[$_i],
Branch: 1 branch
BranchTrueFalseTotal
socketpair $_obj->{$_r_sock}[$_i], $_obj->{$_w_sock}[$_i], 1, 1, 0 or die "socketpair: $!\n" 140 0 140
248 AF_UNIX, Socket::SOCK_STREAM(), 0 ) or die "socketpair: $!\n";
249 }
250  
251 587 ▶ if ($^O !~ /aix|linux|android/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($^O =~ /aix|linux|android/) 0 587 587
252 0 setsockopt($_obj->{$_r_sock}[$_i], SOL_SOCKET, SO_SNDBUF, int $_size);
253 0 setsockopt($_obj->{$_r_sock}[$_i], SOL_SOCKET, SO_RCVBUF, int $_size);
254 0 setsockopt($_obj->{$_w_sock}[$_i], SOL_SOCKET, SO_SNDBUF, int $_size);
255 0 setsockopt($_obj->{$_w_sock}[$_i], SOL_SOCKET, SO_RCVBUF, int $_size);
256 }
257  
258 587 $_obj->{$_r_sock}[$_i]->autoflush(1);
259 587 $_obj->{$_w_sock}[$_i]->autoflush(1);
260 }
261 else {
262 524 ▶ if ($_seq && $^O eq 'linux' && eval q{ Socket::SOCK_SEQPACKET() }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_seq and $^O eq 'linux' and eval ' Socket::SOCK_SEQPACKET() ') { } 501 23 524
Condition66%4/6
$_seq and $^O eq "linux" and eval " Socket::SOCK_SEQPACKET() "
!ll&&!rl&&r
230501
$_seq and $^O eq "linux"
!ll&&!rl&&r
230501
MC/DC33%1/3
$_seq and $^O eq "linux" and eval " Socket::SOCK_SEQPACKET() "
$_seq $^O eq "linux" eval " Socket::SOCK_SEQPACKET() "
Truth table50%2/4
A and B and C
A= $_seqB= $^O eq "linux"C= eval " Socket::SOCK_SEQPACKET() "
ABCresult
0XX0
10X0
1100
1111
263 socketpair( $_obj->{$_r_sock}, $_obj->{$_w_sock},
264 501 ▶ AF_UNIX, Socket::SOCK_SEQPACKET(), 0 ) or do {
Branch: 1 branch
BranchTrueFalseTotal
socketpair $_obj->{$_r_sock}, $_obj->{$_w_sock}, 1, 5, 0 or do { socketpair $_obj->{$_r_sock}, $_obj->{$_w_sock}, 1, 1, 0 or die "socketpair: $!\n" } 501 0 501
265 0 ▶ socketpair( $_obj->{$_r_sock}, $_obj->{$_w_sock},
Branch: 1 branch
BranchTrueFalseTotal
socketpair $_obj->{$_r_sock}, $_obj->{$_w_sock}, 1, 1, 0 or die "socketpair: $!\n" 0 0 0
266 AF_UNIX, Socket::SOCK_STREAM(), 0 ) or die "socketpair: $!\n";
267 };
268 }
269 else {
270 23 ▶ socketpair( $_obj->{$_r_sock}, $_obj->{$_w_sock},
Branch: 1 branch
BranchTrueFalseTotal
socketpair $_obj->{$_r_sock}, $_obj->{$_w_sock}, 1, 1, 0 or die "socketpair: $!\n" 23 0 23
271 AF_UNIX, Socket::SOCK_STREAM(), 0 ) or die "socketpair: $!\n";
272 }
273  
274 524 ▶ if ($^O !~ /aix|linux|android/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($^O =~ /aix|linux|android/) 0 524 524
275 0 setsockopt($_obj->{$_r_sock}, SOL_SOCKET, SO_SNDBUF, int $_size);
276 0 setsockopt($_obj->{$_r_sock}, SOL_SOCKET, SO_RCVBUF, int $_size);
277 0 setsockopt($_obj->{$_w_sock}, SOL_SOCKET, SO_SNDBUF, int $_size);
278 0 setsockopt($_obj->{$_w_sock}, SOL_SOCKET, SO_RCVBUF, int $_size);
279 }
280  
281 524 $_obj->{$_r_sock}->autoflush(1);
282 524 $_obj->{$_w_sock}->autoflush(1);
283 }
284  
285 1111 return;
286 }
287  
288 0 ▶sub _sock_ready {
Subroutine _sock_ready: not called CC=11 SCAR=48.8
289 0 my ($_socket, $_timeout) = @_;
290 0 ▶ return '' if !defined $_timeout && $_sock_ready{"$_socket"} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_timeout and $_sock_ready{"$_socket"} > 1 0 0 0
Condition0%0/3
not defined $_timeout and $_sock_ready{"$_socket"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $_timeout and $_sock_ready{"$_socket"} > 1
not defined $_timeout $_sock_ready{"$_socket"} > 1
Truth table0%0/3
not(A) and B
A= not defined $_timeoutB= $_sock_ready{"$_socket"} > 1
ABresult
0X0
100
111
291  
292 0 my ($_val_bytes, $_delay, $_start) = (pack('L', 0), 0, time);
293  
294 0 ▶ if (!defined $_timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_timeout) { } 0 0 0
295 0 $_sock_ready{"$_socket"}++;
296 }
297 else {
298 0 ▶ $_timeout = undef if $_timeout < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_timeout < 0 0 0 0
299 0 ▶ $_timeout += $_start if $_timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $_timeout 0 0 0
300 }
301  
302 0 while (1) {
303 # MSWin32 FIONREAD - from winsock2.h macro
304 0 ioctl($_socket, 0x4004667f, $_val_bytes);
305  
306 0 ▶ return '' if $_val_bytes ne $_zero_bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $_val_bytes ne $_zero_bytes 0 0 0
307 0 ▶ return 1 if $_timeout && time > $_timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $_timeout and &MCE::Util::time() > $_timeout 0 0 0
Condition0%0/3
$_timeout and &MCE::Util::time() > $_timeout
!ll&&!rl&&r
000
MC/DC0%0/2
$_timeout and &MCE::Util::time() > $_timeout
$_timeout &MCE::Util::time() > $_timeout
Truth table0%0/3
A and B
A= $_timeoutB= &MCE::Util::time() > $_timeout
ABresult
0X0
100
111
308  
309 # delay after a while to not consume a CPU core
310 0 ▶ sleep(0.015), next if $_delay;
Branch: 1 branch
BranchTrueFalseTotal
if $_delay 0 0 0
311 0 ▶ $_delay = 1 if time - $_start > 0.030;
Branch: 1 branch
BranchTrueFalseTotal
if &MCE::Util::time() - $_start > "0.03" 0 0 0
312 }
313 }
314  
315 0 ▶sub _sock_ready_w {
Subroutine _sock_ready_w: not called CC=3 SCAR=24.8
316 0 my ($_socket) = @_;
317 0 ▶ return if $_sock_ready{"${_socket}_w"} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $_sock_ready{"${_socket}_w"} > 1 0 0 0
318  
319 0 my $_vec = '';
320 0 $_sock_ready{"${_socket}_w"}++;
321  
322 0 while (1) {
323 0 vec($_vec, fileno($_socket), 1) = 1;
324 0 ▶ return if select(undef, $_vec, undef, 0) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if select(undef, $_vec, undef, 0) > 0 0 0 0
325 0 sleep 0.045;
326 }
327  
328 0 return;
329 }
330  
331 1315 ▶sub _sysread {
Subroutine _sysread: called CC=4 SCAR=20.7
332 ( @_ == 3
333 ? CORE::sysread($_[0], $_[1], $_[2])
334 : CORE::sysread($_[0], $_[1], $_[2], $_[3])
335 )
336 1315 ▶ or do {
Branch: 2 branches
BranchTrueFalseTotal
@_ == 3 ? sysread($_[0], $_[1], $_[2]) : sysread($_[0], $_[1], $_[2], $_[3]) or do { goto \&MCE::Util::_sysread if $! == 4 } 1315 0 1315
@_ == 3 ? : 1315 0 1315
337 0 ▶ goto \&_sysread if ($! == Errno::EINTR());
Branch: 1 branch
BranchTrueFalseTotal
if $! == 4 0 0 0
338 };
339 }
340  
341 0 ▶sub _sysread2 {
Subroutine _sysread2: not called CC=10 SCAR=47.0
342 0 my ($_bytes, $_delay, $_start);
343 # called by MCE/Core/Manager.pm
344  
345 SYSREAD: $_bytes = ( @_ == 3
346 ? CORE::sysread($_[0], $_[1], $_[2])
347 : CORE::sysread($_[0], $_[1], $_[2], $_[3])
348 )
349 0 ▶ or do {
Branch: 2 branches
BranchTrueFalseTotal
$_bytes = @_ == 3 ? sysread($_[0], $_[1], $_[2]) : sysread($_[0], $_[1], $_[2], $_[3]) or do { unless (defined $_bytes) { goto SYSREAD if $! == 4; if ($! == 11 or $! == 11) { &MCE::Util::sleep("0.015"), goto SYSREAD if $_delay; $_start = &MCE::Util::time() unless $_start; $_delay = 1 if &MCE::Util::time() - $_start > "0.03"; goto SYSREAD; } ; } } 0 0 0
@_ == 3 ? : 0 0 0
350 0 ▶ unless ( defined $_bytes ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_bytes) 0 0 0
351 0 ▶ goto SYSREAD if ($! == Errno::EINTR());
Branch: 1 branch
BranchTrueFalseTotal
if $! == 4 0 0 0
352  
353 # non-blocking operation could not be completed
354 0 ▶ if ( $! == Errno::EWOULDBLOCK() || $! == Errno::EAGAIN() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! == 11 or $! == 11) 0 0 0
Condition0%0/3
$! == 11 or $! == 11
l!l&&r!l&&!r
000
MC/DC0%0/2
$! == 11 or $! == 11
$! == 11 $! == 11
Truth table0%0/3
A or B
A= $! == 11B= $! == 11
ABresult
1X1
011
000
355 0 ▶ sleep(0.015), goto SYSREAD if $_delay;
Branch: 1 branch
BranchTrueFalseTotal
if $_delay 0 0 0
356  
357 # delay after a while to not consume a CPU core
358 0 ▶ $_start = time unless $_start;
Branch: 1 branch
BranchTrueFalseTotal
unless $_start 0 0 0
359 0 ▶ $_delay = 1 if time - $_start > 0.030;
Branch: 1 branch
BranchTrueFalseTotal
if &MCE::Util::time() - $_start > "0.03" 0 0 0
360  
361 0 goto SYSREAD;
362 }
363 }
364 };
365  
366 0 return $_bytes;
367 }
368  
369 1646 ▶sub _nonblocking {
Subroutine _nonblocking: called CC=4 SCAR=17.1
370 1646 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 1646 1646
371 # MSWin32 FIONBIO - from winsock2.h macro
372 0 ▶ my $nonblocking = $_[1] ? pack('L', 1) : pack('L', 0);
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
373 0 ioctl($_[0], 0x8004667e, $nonblocking);
374 }
375 else {
376 1646 ▶ $_[0]->blocking( $_[1] ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 823 823 1646
377 }
378  
379 1646 return;
380 }
381  
382 ###############################################################################
383 ## ----------------------------------------------------------------------------
384 ## Private methods, providing high-resolution time, for MCE->yield,
385 ## MCE::Child->yield, and MCE::Hobo->yield.
386 ##
387 ###############################################################################
388  
389 ## Use monotonic clock if available.
390  
391 113 ▶use constant CLOCK_MONOTONIC => eval {
Subroutine BEGIN: called CC=1 SCAR=0.0
392 113 Time::HiRes::clock_gettime( Time::HiRes::CLOCK_MONOTONIC() );
393 113 1;
394 113 };
395  
396 0 ▶sub _sleep {
Subroutine _sleep: not called CC=5 SCAR=34.0
397 0 my ( $seconds ) = @_;
398 0 ▶ return if ( $seconds < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $seconds < 0 0 0 0
399  
400 0 ▶ if ( $INC{'Coro/AnyEvent.pm'} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($INC{'Coro/AnyEvent.pm'}) { } 0 0 0
elsif (&Time::HiRes::d_nanosleep) { } 0 0 0
elsif (&Time::HiRes::d_usleep) { } 0 0 0
401 0 Coro::AnyEvent::sleep( $seconds );
402 }
403 elsif ( &Time::HiRes::d_nanosleep ) {
404 0 Time::HiRes::nanosleep( $seconds * 1e9 );
405 }
406 elsif ( &Time::HiRes::d_usleep ) {
407 0 Time::HiRes::usleep( $seconds * 1e6 );
408 }
409 else {
410 0 Time::HiRes::sleep( $seconds );
411 }
412  
413 0 return;
414 }
415  
416 0 ▶sub _time {
Subroutine _time: not called CC=1 SCAR=6.9
417 0 return ( CLOCK_MONOTONIC )
418 ? Time::HiRes::clock_gettime( Time::HiRes::CLOCK_MONOTONIC() )
419 : Time::HiRes::time();
420 }
421  
422 113 1;
423  
424 __END__
« MCE/Stream.pm ↑ Summary MCE/Signal.pm »