| 1 | package IPC::Manager::Service::Handle; | ||||||||||||||||||||||||||||
| 2 | 208 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 208 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 208 | our $VERSION = '0.000036'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 208 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 208 | ▶ | use Time::HiRes qw/time/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 208 | ▶ | use Test2::Util::UUID qw/gen_uuid/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 208 | ▶ | use IPC::Manager::Util qw/tinysleep/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 208 | ▶ | use Role::Tiny::With; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 208 | with 'IPC::Manager::Role::Service::Select'; | |||||||||||||||||||||||||||
| 16 | 208 | with 'IPC::Manager::Role::Service::Requests'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 208 | use Object::HashBase qw{ | |||||||||||||||||||||||||||
| 19 | <service_name | ||||||||||||||||||||||||||||
| 20 | <name | ||||||||||||||||||||||||||||
| 21 | <ipcm_info | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | interval | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | <child_pid | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | +client | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | +request_callbacks | ||||||||||||||||||||||||||||
| 30 | +requests | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | +buffer | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | +spawn | ||||||||||||||||||||||||||||
| 35 | 208 | ▶ | }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 141 | ▶ | sub _set_child_pid { $_[0]->{+CHILD_PID} = $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
_set_child_pid: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub init { | ||||||||||||||||||||||||||||
| 40 | 164 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 164 | $self->clear_servicerequests_fields; | |||||||||||||||||||||||||||
| 43 | 164 | $self->clear_serviceselect_fields; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 164 | ▶ | croak "'service_name' is a required attribute" unless $self->{+SERVICE_NAME}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 163 | ▶ | croak "'ipcm_info' is a required attribute" unless $self->{+IPCM_INFO}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 162 | ▶ | $self->{+INTERVAL} //= 0.2; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"interval"} //= "0.2"
MC/DC100%1/1
$self->{"interval"} //= "0.2"
$self->{"interval"}
Truth table100%2/2
A
A= $self->{"interval"}
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 162 | ▶ | $self->{+NAME} //= gen_uuid(); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"name"} //= gen_uuid()
MC/DC0%0/2
$self->{"name"} //= gen_uuid()
$self->{"name"}
gen_uuid()
Truth table66%2/3
A //= B
A= $self->{"name"}B= gen_uuid()
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub DESTROY { | ||||||||||||||||||||||||||||
| 54 | 164 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Disconnect the client before the spawn is destroyed, otherwise the | ||||||||||||||||||||||||||||
| 57 | # spawn's unspawn() may remove shared resources (e.g. SysV semaphores) | ||||||||||||||||||||||||||||
| 58 | # that the client's disconnect/write_stats still needs. | ||||||||||||||||||||||||||||
| 59 | 164 | ▶ | if (my $client = delete $self->{+CLIENT}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 149 | local $@; | |||||||||||||||||||||||||||
| 61 | 149 | ▶ | eval { $client->disconnect; 1 } or warn $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub select_handles { | ||||||||||||||||||||||||||||
| 66 | 140 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
select_handles: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 140 | my $client = $self->client; | |||||||||||||||||||||||||||
| 68 | 140 | ▶ | return $client->have_handles_for_select ? $client->handles_for_select : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub ready { | ||||||||||||||||||||||||||||
| 72 | 144 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
ready: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 144 | my ($timeout) = @_; | |||||||||||||||||||||||||||
| 74 | 144 | $self->client->peer_active($self->{+SERVICE_NAME}, $timeout); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub client { | ||||||||||||||||||||||||||||
| 78 | 1854 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
client: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 1854 | ▶ | return $self->{+CLIENT} if $self->{+CLIENT}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 140 | require IPC::Manager; | |||||||||||||||||||||||||||
| 82 | 140 | return $self->{+CLIENT} = IPC::Manager->connect($self->{+NAME}, $self->{+IPCM_INFO}); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub service_pid { | ||||||||||||||||||||||||||||
| 86 | 28 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
service_pid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 28 | $self->client->peer_pid($self->service_name); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub sync_request { | ||||||||||||||||||||||||||||
| 91 | 66 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
sync_request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 66 | my ($peer, $payload, $timeout) = @_; | |||||||||||||||||||||||||||
| 93 | 66 | my $id = $self->send_request($peer, $payload); | |||||||||||||||||||||||||||
| 94 | 66 | return $self->await_response($id, $timeout); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # Returns true if the named peer is still considered live for the purpose | ||||||||||||||||||||||||||||
| 98 | # of expecting a response. Protocols that advertise suspend_supported let | ||||||||||||||||||||||||||||
| 99 | # peers suspend cleanly (pidfile dropped) or restart under a new pid while | ||||||||||||||||||||||||||||
| 100 | # the registration stays in place — a missing pid or a pid mismatch is | ||||||||||||||||||||||||||||
| 101 | # therefore not a failure on its own, only full unregistration is. | ||||||||||||||||||||||||||||
| 102 | # Protocols without suspend treat a dead or missing pid as a permanent loss. | ||||||||||||||||||||||||||||
| 103 | sub _pending_peer_active { | ||||||||||||||||||||||||||||
| 104 | 412 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_pending_peer_active: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 105 | 412 | my ($peer, $pid) = @_; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 412 | my $client = $self->client; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 412 | ▶ | return $client->peer_exists($peer) ? 1 : 0 if $client->suspend_supported; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 110 | 131 | ▶ | return $client->pid_is_running($pid) ? 1 : 0 if defined $pid; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 111 | 1 | return $client->peer_active($peer); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub await_response { | ||||||||||||||||||||||||||||
| 115 | 132 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
await_response: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 132 | my ($id, $timeout) = @_; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 132 | my $interval = $self->{+INTERVAL}; | |||||||||||||||||||||||||||
| 119 | 132 | ▶ | my $deadline = defined($timeout) ? time + $timeout : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 132 | while (1) { | |||||||||||||||||||||||||||
| 122 | 422 | my @out = $self->get_response($id); | |||||||||||||||||||||||||||
| 123 | 422 | ▶ | return $out[0] if @out; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 358 | my ($peer, $pid) = $self->pending_response_peer($id); | |||||||||||||||||||||||||||
| 126 | 358 | ▶ | if ($peer && !$self->_pending_peer_active($peer, $pid)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$peer and not $self->_pending_peer_active($peer, $pid)
MC/DC50%1/2
$peer and not $self->_pending_peer_active($peer, $pid)
$peer
not $self->_pending_peer_active($peer, $pid)
Truth table66%2/3
A and not(B)
A= $peerB= not $self->_pending_peer_active($peer, $pid)
| |||||||||||||||||||||||||||||
| 127 | # Race: the peer may have sent its response and then exited | ||||||||||||||||||||||||||||
| 128 | # before we polled for it. The peer-active check now reports | ||||||||||||||||||||||||||||
| 129 | # gone, but the response can still be sitting in the transport | ||||||||||||||||||||||||||||
| 130 | # waiting to be ingested. Do one final non-blocking drain and | ||||||||||||||||||||||||||||
| 131 | # re-check before declaring the request lost. | ||||||||||||||||||||||||||||
| 132 | 63 | $self->poll(0); | |||||||||||||||||||||||||||
| 133 | 63 | @out = $self->get_response($id); | |||||||||||||||||||||||||||
| 134 | 63 | ▶ | return $out[0] if @out; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 3 | croak "peer '$peer' went away while awaiting response '$id'"; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 295 | my $wait = $interval; | |||||||||||||||||||||||||||
| 140 | 295 | ▶ | if (defined $deadline) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 18 | my $remaining = $deadline - time; | |||||||||||||||||||||||||||
| 142 | 18 | ▶ | croak "await_response: timed out after ${timeout}s waiting for response '$id'" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | if $remaining <= 0; | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 16 | ▶ | $wait = $remaining if $remaining < $wait; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 293 | $self->poll($wait); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | sub await_all_responses { | ||||||||||||||||||||||||||||
| 153 | 24 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
await_all_responses: called CC=9 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | 24 | my ($timeout) = @_; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 24 | ▶ | my $deadline = defined($timeout) ? time + $timeout : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 24 | ▶ | while ($self->have_pending_responses) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 33 | ▶ | if ($self->_have_gone_pending_peers) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | # Drain once more in case responses raced peer disappearance. | ||||||||||||||||||||||||||||
| 161 | 0 | $self->poll(0); | |||||||||||||||||||||||||||
| 162 | 0 | ▶ | last unless $self->have_pending_responses; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | my @gone = $self->_gone_pending_peers; | |||||||||||||||||||||||||||
| 165 | 0 | ▶ | if (@gone) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | my %seen; | |||||||||||||||||||||||||||
| 167 | 0 | my @uniq = grep { !$seen{$_}++ } map { $_->[0] } @gone; | |||||||||||||||||||||||||||
| 168 | 0 | croak "peer(s) '" . join(", ", @uniq) . "' went away while awaiting responses"; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 33 | my $wait = $self->{+INTERVAL}; | |||||||||||||||||||||||||||
| 173 | 33 | ▶ | if (defined $deadline) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | my $remaining = $deadline - time; | |||||||||||||||||||||||||||
| 175 | 0 | ▶ | croak "await_all_responses: timed out after ${timeout}s with pending responses" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | if $remaining <= 0; | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $wait = $remaining if $remaining < $wait; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 33 | $self->poll($wait); | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 24 | return; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # Returns a list of [peer, pid] tuples for pending responses whose peer is | ||||||||||||||||||||||||||||
| 187 | # no longer considered active. | ||||||||||||||||||||||||||||
| 188 | sub _gone_pending_peers { | ||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_gone_pending_peers: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | my @gone; | |||||||||||||||||||||||||||
| 192 | 0 | ▶ | for my $entry (values %{$self->{_RESPONSES} // {}}) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"_RESPONSES"} // {}
MC/DC0%0/1
$self->{"_RESPONSES"} // {}
$self->{"_RESPONSES"}
Truth table0%0/2
A
A= $self->{"_RESPONSES"}
| |||||||||||||||||||||||||||||
| 193 | 0 | ▶ | next if defined $entry->{response}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | push @gone, [$entry->{peer}, $entry->{pid}] | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | unless $self->_pending_peer_active($entry->{peer}, $entry->{pid}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | for my $entry (values %{$self->{_RESPONSE_HANDLER} // {}}) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"_RESPONSE_HANDLER"} // {}
MC/DC0%0/1
$self->{"_RESPONSE_HANDLER"} // {}
$self->{"_RESPONSE_HANDLER"}
Truth table0%0/2
A
A= $self->{"_RESPONSE_HANDLER"}
| |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | next unless defined $entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | push @gone, [$entry->{peer}, $entry->{pid}] | ||||||||||||||||||||||||||||
| 200 | 0 | ▶ | unless $self->_pending_peer_active($entry->{peer}, $entry->{pid}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 0 | return @gone; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # Boolean fast path for "is any pending response's peer gone?". Short- | ||||||||||||||||||||||||||||
| 206 | # circuits on the first hit so we skip _pending_peer_active probes (which | ||||||||||||||||||||||||||||
| 207 | # can hit the FS / DB) for every other pending response. Use this when | ||||||||||||||||||||||||||||
| 208 | # the caller only needs the yes/no; collect names via _gone_pending_peers | ||||||||||||||||||||||||||||
| 209 | # only after this confirms there is at least one. | ||||||||||||||||||||||||||||
| 210 | sub _have_gone_pending_peers { | ||||||||||||||||||||||||||||
| 211 | 33 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_have_gone_pending_peers: called CC=9 SCAR=28.1
| |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 33 | ▶ | for my $entry (values %{$self->{_RESPONSES} // {}}) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_RESPONSES"} // {}
MC/DC0%0/1
$self->{"_RESPONSES"} // {}
$self->{"_RESPONSES"}
Truth table50%1/2
A
A= $self->{"_RESPONSES"}
| |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | next if defined $entry->{response}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | return 1 unless $self->_pending_peer_active($entry->{peer}, $entry->{pid}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | 33 | ▶ | for my $entry (values %{$self->{_RESPONSE_HANDLER} // {}}) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_RESPONSE_HANDLER"} // {}
MC/DC0%0/1
$self->{"_RESPONSE_HANDLER"} // {}
$self->{"_RESPONSE_HANDLER"}
Truth table50%1/2
A
A= $self->{"_RESPONSE_HANDLER"}
| |||||||||||||||||||||||||||||
| 218 | 54 | ▶ | next unless defined $entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 54 | ▶ | return 1 unless $self->_pending_peer_active($entry->{peer}, $entry->{pid}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | 33 | return 0; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | sub messages { | ||||||||||||||||||||||||||||
| 225 | 11 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
messages: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 226 | 11 | my $messages = delete $self->{+BUFFER}; | |||||||||||||||||||||||||||
| 227 | 11 | ▶ | return unless $messages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 5 | return @$messages; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | sub poll { | ||||||||||||||||||||||||||||
| 232 | 389 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
poll: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||
| 233 | 389 | my ($timeout) = @_; | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 389 | my $client = $self->client; | |||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 389 | my @messages; | |||||||||||||||||||||||||||
| 238 | 389 | ▶ | if (my $select = $self->select) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 79 | ▶ | if ($select->can_read($timeout)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 79 | @messages = $client->get_messages; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | else { | ||||||||||||||||||||||||||||
| 244 | 310 | ▶ | my $start = $timeout ? time : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 310 | while (1) { | |||||||||||||||||||||||||||
| 247 | 583 | @messages = $client->get_messages; | |||||||||||||||||||||||||||
| 248 | 583 | ▶ | last if @messages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 508 | ▶ | if (defined $timeout) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 508 | ▶ | last unless $timeout; # timeout is 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 505 | my $delta = time - $start; | |||||||||||||||||||||||||||
| 254 | 505 | ▶ | last if $delta >= $timeout | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 276 | tinysleep($self->{+INTERVAL}); | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 386 | ▶ | return unless @messages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | # handle the messages | ||||||||||||||||||||||||||||
| 264 | # Split into regular message to go in the buffer and handle responses | ||||||||||||||||||||||||||||
| 265 | 154 | for my $msg (@messages) { | |||||||||||||||||||||||||||
| 266 | 168 | my $c = $msg->content; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 168 | ▶ | if (ref($c) eq 'HASH' && $c->{ipcm_response_id}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $c eq "HASH" and $c->{"ipcm_response_id"}
MC/DC50%1/2
ref $c eq "HASH" and $c->{"ipcm_response_id"}
ref $c eq "HASH"
$c->{"ipcm_response_id"}
Truth table66%2/3
A and B
A= ref $c eq "HASH"B= $c->{"ipcm_response_id"}
| |||||||||||||||||||||||||||||
| 269 | 164 | $self->handle_response($c, $msg); | |||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | else { | ||||||||||||||||||||||||||||
| 272 | 4 | push @{$self->{+BUFFER}} => $msg; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 154 | return scalar @messages; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 208 | 1; | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | __END__ | ||||||||||||||||||||||||||||