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