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