| 1 | ############################################################################### | ||||||||||||||||||||||||||||
| 2 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 3 | ## Channel for producer(s) and many consumers supporting processes and threads. | ||||||||||||||||||||||||||||
| 4 | ## | ||||||||||||||||||||||||||||
| 5 | ############################################################################### | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package MCE::Channel::MutexFast; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 10 | ▶ | no warnings qw( uninitialized once ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 10 | our $VERSION = '1.904'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 10 | ▶ | use base 'MCE::Channel'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 10 | ▶ | use MCE::Mutex (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 10 | my $LF = "\012"; Internals::SvREADONLY($LF, 1); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 10 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 10 | my ( $class, %obj ) = ( @_, impl => 'MutexFast' ); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 10 | $obj{init_pid} = MCE::Channel::_pid(); | |||||||||||||||||||||||||||
| 25 | 10 | MCE::Util::_sock_pair( \%obj, 'p_sock', 'c_sock' ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # locking for the consumer side of the channel | ||||||||||||||||||||||||||||
| 28 | 10 | $obj{c_mutex} = MCE::Mutex->new( impl => 'Channel2' ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # optionally, support many-producers writing and reading | ||||||||||||||||||||||||||||
| 31 | 10 | ▶ | $obj{p_mutex} = MCE::Mutex->new( impl => 'Channel2' ) if $obj{mp}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 10 | bless \%obj, $class; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 10 | MCE::Mutex::Channel::_save_for_global_cleanup($obj{c_mutex}); | |||||||||||||||||||||||||||
| 36 | 10 | ▶ | MCE::Mutex::Channel::_save_for_global_cleanup($obj{p_mutex}) if $obj{mp}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 10 | return \%obj; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 10 | ▶ | END { | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 42 | 10 | ▶ | MCE::Child->finish('MCE') if $INC{'MCE/Child.pm'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | ############################################################################### | ||||||||||||||||||||||||||||
| 46 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 47 | ## Queue-like methods. | ||||||||||||||||||||||||||||
| 48 | ## | ||||||||||||||||||||||||||||
| 49 | ############################################################################### | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | sub end { | ||||||||||||||||||||||||||
|
Subroutine
end: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | local $\ = undef if (defined $\); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | print { $self->{p_sock} } pack('i', -1); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | $self->{ended} = 1; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 26 | ▶ | sub enqueue { | ||||||||||||||||||||||||||
|
Subroutine
enqueue: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 26 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 26 | ▶ | return MCE::Channel::_ended('enqueue') if $self->{ended}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 24 | ▶ | local $\ = undef if (defined $\); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 24 | my $p_mutex = $self->{p_mutex}; | |||||||||||||||||||||||||||
| 66 | 24 | ▶ | $p_mutex->lock2 if $p_mutex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 24 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 44 | my $data = ''.shift; | |||||||||||||||||||||||||||
| 70 | 44 | print { $self->{p_sock} } pack('i', length $data), $data; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 24 | ▶ | $p_mutex->unlock2 if $p_mutex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 24 | return 1; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 16 | ▶ | sub dequeue { | ||||||||||||||||||||||||||
|
Subroutine
dequeue: called CC=12 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 16 | my ( $self, $count ) = @_; | |||||||||||||||||||||||||||
| 80 | 16 | ▶ | $count = 1 if ( !$count || $count < 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $count or $count < 1
MC/DC50%1/2
not $count or $count < 1
not $count
$count < 1
Truth table66%2/3
not(A) or B
A= not $countB= $count < 1
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 16 | ▶ | if ( $count == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 14 | ( my $c_mutex = $self->{c_mutex} )->lock; | |||||||||||||||||||||||||||
| 84 | 14 | MCE::Util::_sysread( $self->{c_sock}, my($plen), 4 ); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 14 | my $len = unpack('i', $plen); | |||||||||||||||||||||||||||
| 87 | 14 | ▶ | if ( $len < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | $self->end, $c_mutex->unlock; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | return wantarray ? () : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 14 | ▶ | MCE::Channel::_read( $self->{c_sock}, my($data), $len ) if $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 14 | $c_mutex->unlock; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 14 | ▶ | $len ? $data : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||
| 98 | 2 | my ( $plen, @ret ); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | ( my $c_mutex = $self->{c_mutex} )->lock; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 2 | ▶ | while ( $count-- ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 6 | MCE::Util::_sysread( $self->{c_sock}, $plen, 4 ); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 6 | my $len = unpack('i', $plen); | |||||||||||||||||||||||||||
| 106 | 6 | ▶ | if ( $len < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | $self->end; | |||||||||||||||||||||||||||
| 108 | 0 | last; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 6 | ▶ | push(@ret, ''), next unless $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 6 | MCE::Channel::_read( $self->{c_sock}, my($data), $len ); | |||||||||||||||||||||||||||
| 113 | 6 | push @ret, $data; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 2 | $c_mutex->unlock; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | ▶ | wantarray ? @ret : $ret[-1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 20 | ▶ | sub dequeue_nb { | ||||||||||||||||||||||||||
|
Subroutine
dequeue_nb: called CC=12 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 20 | my ( $self, $count ) = @_; | |||||||||||||||||||||||||||
| 124 | 20 | ▶ | $count = 1 if ( !$count || $count < 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $count or $count < 1
MC/DC50%1/2
not $count or $count < 1
not $count
$count < 1
Truth table66%2/3
not(A) or B
A= not $countB= $count < 1
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 20 | my ( $plen, @ret ); | |||||||||||||||||||||||||||
| 127 | 20 | ( my $c_mutex = $self->{c_mutex} )->lock; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 20 | ▶ | while ( $count-- ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 24 | MCE::Util::_nonblocking( $self->{c_sock}, 1 ); | |||||||||||||||||||||||||||
| 131 | 24 | MCE::Util::_sysread( $self->{c_sock}, $plen, 4 ); | |||||||||||||||||||||||||||
| 132 | 24 | MCE::Util::_nonblocking( $self->{c_sock}, 0 ); | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 24 | ▶ | my $len; $len = unpack('i', $plen) if $plen; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 24 | ▶ | if ( !$len || $len < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $len or $len < 0
MC/DC50%1/2
not $len or $len < 0
not $len
$len < 0
Truth table66%2/3
not(A) or B
A= not $lenB= $len < 0
| |||||||||||||||||||||||||||||
| 136 | 4 | ▶ | $self->end if defined $len && $len < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $len and $len < 0
MC/DC0%0/2
defined $len and $len < 0
defined $len
$len < 0
Truth table33%1/3
A and B
A= defined $lenB= $len < 0
| |||||||||||||||||||||||||||||
| 137 | 4 | ▶ | push @ret, '' if defined $len && $len == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $len and $len == 0
MC/DC0%0/2
defined $len and $len == 0
defined $len
$len == 0
Truth table33%1/3
A and B
A= defined $lenB= $len == 0
| |||||||||||||||||||||||||||||
| 138 | 4 | last; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 20 | MCE::Channel::_read( $self->{c_sock}, my($data), $len ); | |||||||||||||||||||||||||||
| 142 | 20 | push @ret, $data; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 20 | $c_mutex->unlock; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 20 | ▶ | wantarray ? @ret : $ret[-1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | ############################################################################### | ||||||||||||||||||||||||||||
| 151 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 152 | ## Methods for two-way communication; producer to consumer. | ||||||||||||||||||||||||||||
| 153 | ## | ||||||||||||||||||||||||||||
| 154 | ############################################################################### | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 29 | ▶ | sub send { | ||||||||||||||||||||||||||
|
Subroutine
send: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 29 | my $self = shift; | |||||||||||||||||||||||||||
| 158 | 29 | ▶ | return MCE::Channel::_ended('send') if $self->{ended}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 27 | my $data = ''.shift; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 27 | ▶ | local $\ = undef if (defined $\); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 27 | my $p_mutex = $self->{p_mutex}; | |||||||||||||||||||||||||||
| 164 | 27 | ▶ | $p_mutex->lock2 if $p_mutex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 27 | print { $self->{p_sock} } pack('i', length $data), $data; | |||||||||||||||||||||||||||
| 167 | 27 | ▶ | $p_mutex->unlock2 if $p_mutex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 27 | return 1; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 9 | ▶ | sub recv { | ||||||||||||||||||||||||||
|
Subroutine
recv: called CC=5 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||
| 173 | 9 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 9 | ( my $c_mutex = $self->{c_mutex} )->lock; | |||||||||||||||||||||||||||
| 176 | 9 | MCE::Util::_sysread( $self->{c_sock}, my($plen), 4 ); | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 9 | my $len = unpack('i', $plen); | |||||||||||||||||||||||||||
| 179 | 9 | ▶ | if ( $len < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 0 | $self->end, $c_mutex->unlock; | |||||||||||||||||||||||||||
| 181 | 0 | ▶ | return wantarray ? () : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 9 | ▶ | MCE::Channel::_read( $self->{c_sock}, my($data), $len ) if $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 9 | $c_mutex->unlock; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 9 | ▶ | $len ? $data : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 6 | ▶ | sub recv_nb { | ||||||||||||||||||||||||||
|
Subroutine
recv_nb: called CC=9 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | 6 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 6 | ( my $c_mutex = $self->{c_mutex} )->lock; | |||||||||||||||||||||||||||
| 194 | 6 | MCE::Util::_nonblocking( $self->{c_sock}, 1 ); | |||||||||||||||||||||||||||
| 195 | 6 | MCE::Util::_sysread( $self->{c_sock}, my($plen), 4 ); | |||||||||||||||||||||||||||
| 196 | 6 | MCE::Util::_nonblocking( $self->{c_sock}, 0 ); | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 6 | ▶ | my $len; $len = unpack('i', $plen) if $plen; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 6 | ▶ | if ( !$len || $len < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $len or $len < 0
MC/DC50%1/2
not $len or $len < 0
not $len
$len < 0
Truth table66%2/3
not(A) or B
A= not $lenB= $len < 0
| |||||||||||||||||||||||||||||
| 200 | 4 | ▶ | $self->end if defined $len && $len < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $len and $len < 0
MC/DC0%0/2
defined $len and $len < 0
defined $len
$len < 0
Truth table33%1/3
A and B
A= defined $lenB= $len < 0
| |||||||||||||||||||||||||||||
| 201 | 4 | $c_mutex->unlock; | |||||||||||||||||||||||||||
| 202 | 4 | ▶ | return '' if defined $len && $len == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $len and $len == 0
MC/DC0%0/2
defined $len and $len == 0
defined $len
$len == 0
Truth table33%1/3
A and B
A= defined $lenB= $len == 0
| |||||||||||||||||||||||||||||
| 203 | 0 | ▶ | return wantarray ? () : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 2 | MCE::Channel::_read( $self->{c_sock}, my($data), $len ); | |||||||||||||||||||||||||||
| 207 | 2 | $c_mutex->unlock; | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 2 | $data; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | ############################################################################### | ||||||||||||||||||||||||||||
| 213 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 214 | ## Methods for two-way communication; consumer to producer. | ||||||||||||||||||||||||||||
| 215 | ## | ||||||||||||||||||||||||||||
| 216 | ############################################################################### | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 12 | ▶ | sub send2 { | ||||||||||||||||||||||||||
|
Subroutine
send2: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 219 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 220 | 12 | my $data = ''.shift; | |||||||||||||||||||||||||||
| 221 | 12 | my $sig; | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||
| 224 | 12 | local $SIG{ABRT} = local $SIG{HUP} = | |||||||||||||||||||||||||||
| 225 | local $SIG{QUIT} = local $SIG{INT} = | ||||||||||||||||||||||||||||
| 226 | 0 | ▶ | local $SIG{TERM} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 227 | 0 | $sig = $_[0]; | |||||||||||||||||||||||||||
| 228 | 12 | }; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 12 | ▶ | local $\ = undef if (defined $\); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 12 | ▶ | $self->{c_mutex}->synchronize2( sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 232 | 12 | print { $self->{c_sock} } pack('i', length $data), $data; | |||||||||||||||||||||||||||
| 233 | 12 | }); | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 12 | ▶ | CORE::kill($sig, $$) if $sig; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 12 | return 1; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 6 | ▶ | sub recv2 { | ||||||||||||||||||||||||||
|
Subroutine
recv2: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 242 | 6 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 243 | 6 | my ( $plen, $data ); | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 6 | ▶ | local $/ = $LF if ( $/ ne $LF ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 6 | my $p_mutex = $self->{p_mutex}; | |||||||||||||||||||||||||||
| 247 | 6 | ▶ | $p_mutex->lock if $p_mutex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | ( $p_mutex ) | ||||||||||||||||||||||||||||
| 250 | ? MCE::Util::_sysread( $self->{p_sock}, $plen, 4 ) | ||||||||||||||||||||||||||||
| 251 | 6 | ▶ | : read( $self->{p_sock}, $plen, 4 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 6 | my $len = unpack('i', $plen); | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 6 | ▶ | if ( $len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | ( $p_mutex ) | ||||||||||||||||||||||||||||
| 257 | ? MCE::Channel::_read( $self->{p_sock}, $data, $len ) | ||||||||||||||||||||||||||||
| 258 | 2 | ▶ | : read( $self->{p_sock}, $data, $len ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 6 | ▶ | $p_mutex->unlock if $p_mutex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 6 | ▶ | $len ? $data : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 6 | ▶ | sub recv2_nb { | ||||||||||||||||||||||||||
|
Subroutine
recv2_nb: called CC=12 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||
| 267 | 6 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 268 | 6 | my ( $plen, $data ); | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 6 | ▶ | local $/ = $LF if ( $/ ne $LF ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 6 | my $p_mutex = $self->{p_mutex}; | |||||||||||||||||||||||||||
| 272 | 6 | ▶ | $p_mutex->lock if $p_mutex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 6 | MCE::Util::_nonblocking( $self->{p_sock}, 1 ); | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | ( $p_mutex ) | ||||||||||||||||||||||||||||
| 277 | ? MCE::Util::_sysread( $self->{p_sock}, $plen, 4 ) | ||||||||||||||||||||||||||||
| 278 | 6 | ▶ | : read( $self->{p_sock}, $plen, 4 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 6 | MCE::Util::_nonblocking( $self->{p_sock}, 0 ); | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 6 | ▶ | my $len; $len = unpack('i', $plen) if $plen; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | 6 | ▶ | if ( !$len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | 4 | ▶ | $p_mutex->unlock if $p_mutex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 4 | ▶ | return '' if defined $len && $len == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $len and $len == 0
MC/DC0%0/2
defined $len and $len == 0
defined $len
$len == 0
Truth table33%1/3
A and B
A= defined $lenB= $len == 0
| |||||||||||||||||||||||||||||
| 286 | 0 | ▶ | return wantarray ? () : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | ( $p_mutex ) | ||||||||||||||||||||||||||||
| 290 | ? MCE::Channel::_read( $self->{p_sock}, $data, $len ) | ||||||||||||||||||||||||||||
| 291 | 2 | ▶ | : read( $self->{p_sock}, $data, $len ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 2 | ▶ | $p_mutex->unlock if $p_mutex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 2 | $data; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 10 | 1; | |||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | __END__ | ||||||||||||||||||||||||||||