| 1 | package IPC::Manager::Spawn; | ||||||||||||||||||||||||||||
| 2 | 459 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 459 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 459 | our $VERSION = '0.000035'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 459 | ▶ | use POSIX(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 459 | ▶ | use Time::HiRes(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 459 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 459 | ▶ | use IPC::Manager::Serializer::JSON(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 459 | ▶ | use IPC::Manager::Util qw/tinysleep/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | use overload( | ||||||||||||||||||||||||||||
| 15 | fallback => 1, | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 23 | ▶ | '""' => sub { $_[0]->info }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 459 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 459 | use Object::HashBase qw{ | |||||||||||||||||||||||||||
| 21 | <protocol | ||||||||||||||||||||||||||||
| 22 | <route | ||||||||||||||||||||||||||||
| 23 | <serializer | ||||||||||||||||||||||||||||
| 24 | <guard | ||||||||||||||||||||||||||||
| 25 | <stash | ||||||||||||||||||||||||||||
| 26 | <pid | ||||||||||||||||||||||||||||
| 27 | <signal | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | do_sanity_check | ||||||||||||||||||||||||||||
| 30 | debug | ||||||||||||||||||||||||||||
| 31 | 459 | ▶ | }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub init { | ||||||||||||||||||||||||||||
| 34 | 287 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 287 | ▶ | $self->{+PID} //= $$; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"pid"} //= $$
MC/DC0%0/2
$self->{"pid"} //= $$
$self->{"pid"}
$$
Truth table33%1/3
A //= B
A= $self->{"pid"}B= $$
| |||||||||||||||||||||||||||||
| 37 | 287 | ▶ | $self->{+GUARD} //= 1; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"guard"} //= 1
MC/DC0%0/1
$self->{"guard"} //= 1
$self->{"guard"}
Truth table50%1/2
A
A= $self->{"guard"}
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 287 | ▶ | croak "'protocol' is a required attribute" unless $self->{+PROTOCOL}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 286 | ▶ | croak "'route' is a required attribute" unless $self->{+ROUTE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 285 | ▶ | croak "'serializer' is a required attribute" unless $self->{+SERIALIZER}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub cleave { | ||||||||||||||||||||||||||||
| 45 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
cleave: called CC=7 SCAR=29.1
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 4 | my ($rh, $wh); | |||||||||||||||||||||||||||
| 48 | 4 | ▶ | pipe($rh, $wh) or die "Could not open a pipe: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 4 | ▶ | my $pid = fork() // die "Could not fork: $!"; | ||||||||||||||||||||||||||
|
Condition50%1/2
fork // die("Could not fork: $!")
MC/DC0%0/1
fork // die("Could not fork: $!")
fork
Truth table50%1/2
A
A= fork
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 4 | ▶ | if ($pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 4 | close($wh); | |||||||||||||||||||||||||||
| 54 | 4 | chomp(my $out = <$rh>); | |||||||||||||||||||||||||||
| 55 | 4 | close($rh); | |||||||||||||||||||||||||||
| 56 | 4 | return $self->{+PID} = $out; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | close($rh); | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | POSIX::setsid() or die "Can't start a new session: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $pid = fork() // die "Could not fork: $!"; | ||||||||||||||||||||||||||
|
Condition0%0/2
fork // die("Could not fork: $!")
MC/DC0%0/1
fork // die("Could not fork: $!")
fork
Truth table0%0/2
A
A= fork
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | close($wh); | |||||||||||||||||||||||||||
| 66 | 0 | POSIX::_exit(0); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | print $wh "$$\n"; | |||||||||||||||||||||||||||
| 70 | 0 | close($wh); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | $self->{+PID} = $$; | |||||||||||||||||||||||||||
| 73 | 0 | return 0; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub info { | ||||||||||||||||||||||||||||
| 77 | 282 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 282 | return IPC::Manager::Serializer::JSON->serialize([@{$self}{PROTOCOL(), SERIALIZER(), ROUTE()}]); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub connect { | ||||||||||||||||||||||||||||
| 82 | 170 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
connect: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 170 | my ($id) = @_; | |||||||||||||||||||||||||||
| 84 | 170 | return $self->{+PROTOCOL}->connect($id, $self->{+SERIALIZER}, $self->{+ROUTE}); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | sub terminate { | ||||||||||||||||||||||||||||
| 88 | 157 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
terminate: called CC=8 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 157 | my ($con) = @_; | |||||||||||||||||||||||||||
| 90 | 157 | ▶ | $con //= $self->connect('spawn'); | ||||||||||||||||||||||||||
|
Condition33%1/3
$con //= $self->connect("spawn")
MC/DC0%0/2
$con //= $self->connect("spawn")
$con
$self->connect("spawn")
Truth table33%1/3
A //= B
A= $conB= $self->connect("spawn")
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # Send the signal before the broadcast so services can act on it | ||||||||||||||||||||||||||||
| 93 | # before the terminate message arrives and ends the event loop. | ||||||||||||||||||||||||||||
| 94 | 157 | ▶ | if ($self->{+SIGNAL()}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 4 | for my $peer ($con->peers) { | |||||||||||||||||||||||||||
| 96 | 4 | my $pid; | |||||||||||||||||||||||||||
| 97 | 4 | ▶ | unless (eval { $pid = $con->peer_pid($peer); 1 }) { warn $@; next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 4 | ▶ | next unless $pid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 4 | ▶ | next if $pid == $$; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 4 | ▶ | kill($self->{+SIGNAL()}, $pid) if $self->{+SIGNAL()}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 157 | $con->broadcast({terminate => 1}); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub _collect_peer_pids { | ||||||||||||||||||||||||||||
| 108 | 157 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_collect_peer_pids: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||
| 109 | 157 | my ($con) = @_; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 157 | my %pids; | |||||||||||||||||||||||||||
| 112 | 157 | for my $peer ($con->peers) { | |||||||||||||||||||||||||||
| 113 | 100 | ▶ | next if $peer eq $con->id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 100 | my $pid; | |||||||||||||||||||||||||||
| 115 | 100 | ▶ | unless (eval { $pid = $con->peer_pid($peer); 1 }) { next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 100 | ▶ | $pids{$pid} = 1 if $pid && $pid != $$; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pid and $pid != $$
MC/DC50%1/2
$pid and $pid != $$
$pid
$pid != $$
Truth table66%2/3
A and B
A= $pidB= $pid != $$
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 157 | return \%pids; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub wait { | ||||||||||||||||||||||||||||
| 123 | 157 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
wait: called CC=20 SCAR=32.5
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 157 | my ($con, %params) = @_; | |||||||||||||||||||||||||||
| 125 | 157 | ▶ | $con //= $self->connect('spawn'); | ||||||||||||||||||||||||||
|
Condition33%1/3
$con //= $self->connect("spawn")
MC/DC0%0/2
$con //= $self->connect("spawn")
$con
$self->connect("spawn")
Truth table33%1/3
A //= B
A= $conB= $self->connect("spawn")
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 157 | my %child_pids; | |||||||||||||||||||||||||||
| 128 | 157 | ▶ | if (my $pre = $params{child_pids}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 157 | %child_pids = %$pre; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 157 | for my $client (IPC::Manager::Client->local_clients($self->{+ROUTE})) { | |||||||||||||||||||||||||||
| 133 | 201 | ▶ | eval { $client->disconnect; 1 } or warn $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # Bound the peer-disappear loop. The poll used to be unbounded with a | ||||||||||||||||||||||||||||
| 137 | # 1-second sleep — a wedged service or a slow filesystem on a CPAN | ||||||||||||||||||||||||||||
| 138 | # smoker could trap shutdown indefinitely. After the deadline we stop | ||||||||||||||||||||||||||||
| 139 | # waiting for clean disconnect and force the reap path to clean up | ||||||||||||||||||||||||||||
| 140 | # whatever pids we've seen. | ||||||||||||||||||||||||||||
| 141 | my $peer_timeout = $params{peer_timeout} | ||||||||||||||||||||||||||||
| 142 | // $ENV{IPC_MANAGER_SPAWN_PEER_TIMEOUT} | ||||||||||||||||||||||||||||
| 143 | 157 | ▶ | // 60; | ||||||||||||||||||||||||||
|
Condition40%2/5
($params{"peer_timeout"} // $ENV{"IPC_MANAGER_SPAWN_PEER_TIMEOUT"}) // 60
$params{"peer_timeout"} // $ENV{"IPC_MANAGER_SPAWN_PEER_TIMEOUT"}
MC/DC0%0/2
($params{"peer_timeout"} // $ENV{"IPC_MANAGER_SPAWN_PEER_TIMEOUT"}) // 60
$params{"peer_timeout"}
$ENV{"IPC_MANAGER_SPAWN_PEER_TIMEOUT"}
Truth table33%1/3
A // B
A= $params{"peer_timeout"}B= $ENV{"IPC_MANAGER_SPAWN_PEER_TIMEOUT"}
| |||||||||||||||||||||||||||||
| 144 | 157 | my $peer_deadline = Time::HiRes::time() + $peer_timeout; | |||||||||||||||||||||||||||
| 145 | 157 | my @last_found; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 157 | while (1) { | |||||||||||||||||||||||||||
| 148 | 318 | my @found; | |||||||||||||||||||||||||||
| 149 | 318 | for my $peer ($con->peers) { | |||||||||||||||||||||||||||
| 150 | 177 | ▶ | next if $peer eq $con->id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 177 | my $pid; | |||||||||||||||||||||||||||
| 152 | 177 | ▶ | unless (eval { $pid = $con->peer_pid($peer); 1 }) { warn $@; next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 177 | ▶ | $child_pids{$pid} = 1 if $pid && $pid != $$; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pid and $pid != $$
MC/DC0%0/2
$pid and $pid != $$
$pid
$pid != $$
Truth table33%1/3
A and B
A= $pidB= $pid != $$
| |||||||||||||||||||||||||||||
| 154 | 177 | push @found => $peer; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 318 | ▶ | last unless @found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 161 | @last_found = @found; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 161 | ▶ | if (Time::HiRes::time() >= $peer_deadline) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | warn "IPC::Manager::Spawn: gave up waiting for clients to disconnect after ${peer_timeout}s: " | |||||||||||||||||||||||||||
| 162 | . join(', ' => sort @found) . "\n"; | ||||||||||||||||||||||||||||
| 163 | 0 | last; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 161 | ▶ | print STDERR "Waiting for clients to go away: " . join(', ' => sort @found) . "\n" if $self->{+DEBUG}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 161 | sleep 1; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | # Wait for child processes to fully exit before returning, so that | ||||||||||||||||||||||||||||
| 171 | # unspawn() does not destroy shared resources while children are | ||||||||||||||||||||||||||||
| 172 | # still running cleanup code. | ||||||||||||||||||||||||||||
| 173 | 157 | my $deadline = Time::HiRes::time() + 10; | |||||||||||||||||||||||||||
| 174 | 157 | ▶ | while (keys %child_pids && Time::HiRes::time() < $deadline) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
keys %child_pids and &Time::HiRes::time() < $deadline
MC/DC50%1/2
keys %child_pids and &Time::HiRes::time() < $deadline
keys %child_pids
&Time::HiRes::time() < $deadline
Truth table66%2/3
A and B
A= keys %child_pidsB= &Time::HiRes::time() < $deadline
| |||||||||||||||||||||||||||||
| 175 | 95 | for my $pid (keys %child_pids) { | |||||||||||||||||||||||||||
| 176 | 103 | my $ret = waitpid($pid, POSIX::WNOHANG()); | |||||||||||||||||||||||||||
| 177 | 103 | ▶ | delete $child_pids{$pid} if $ret != 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 95 | ▶ | tinysleep(0.05) if keys %child_pids; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | sub sanity_delta { | ||||||||||||||||||||||||||||
| 184 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
sanity_delta: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||
| 185 | 8 | my ($con) = @_; | |||||||||||||||||||||||||||
| 186 | 8 | ▶ | $con //= $self->connect('spawn'); | ||||||||||||||||||||||||||
|
Condition66%2/3
$con //= $self->connect("spawn")
MC/DC0%0/2
$con //= $self->connect("spawn")
$con
$self->connect("spawn")
Truth table66%2/3
A //= B
A= $conB= $self->connect("spawn")
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 8 | my $stats = $con->all_stats; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 8 | my $deltas = {}; | |||||||||||||||||||||||||||
| 191 | 8 | for my $peer1 (keys %$stats) { | |||||||||||||||||||||||||||
| 192 | 24 | my $stat = $stats->{$peer1}; | |||||||||||||||||||||||||||
| 193 | 24 | ▶ | my $sent = $stat->{sent} // {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$stat->{"sent"} // {}
MC/DC0%0/1
$stat->{"sent"} // {}
$stat->{"sent"}
Truth table50%1/2
A
A= $stat->{"sent"}
| |||||||||||||||||||||||||||||
| 194 | 24 | ▶ | my $read = $stat->{read} // {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$stat->{"read"} // {}
MC/DC0%0/1
$stat->{"read"} // {}
$stat->{"read"}
Truth table50%1/2
A
A= $stat->{"read"}
| |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 24 | for my $peer2 (keys %$sent) { | |||||||||||||||||||||||||||
| 197 | 32 | $deltas->{"$peer1 -> $peer2"} += $sent->{$peer2}; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 24 | for my $peer2 (keys %$read) { | |||||||||||||||||||||||||||
| 201 | 30 | $deltas->{"$peer2 -> $peer1"} -= $read->{$peer2}; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 8 | ▶ | delete $deltas->{$_} for grep { /(:spawn|spawn:)/ || !$deltas->{$_} } keys %$deltas; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 8 | ▶ | return undef unless keys %$deltas; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 6 | return $deltas; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | sub sanity_check { | ||||||||||||||||||||||||||||
| 212 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
sanity_check: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 6 | ▶ | my $delta = $self->sanity_delta(@_) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 5 | die "\nMessages sent vs received mismatch:\n Positive means sent and not recieved.\n negative means recieved more messages than were sent\n" . join("\n" => map { " $delta->{$_} $_" } sort keys %$delta) . "\n\n"; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | sub DESTROY { | ||||||||||||||||||||||||||||
| 220 | 283 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 221 | 283 | ▶ | return unless $self->{+GUARD}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 264 | $self->shutdown(); | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | sub unspawn { | ||||||||||||||||||||||||||||
| 227 | 164 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
unspawn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 164 | $self->{+PROTOCOL}->unspawn($self->{+ROUTE}, delete $self->{+STASH}); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | sub shutdown { | ||||||||||||||||||||||||||||
| 233 | 265 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
shutdown: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 265 | ▶ | return unless $self->{+PID} == $$; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 157 | my $con = $self->connect('spawn'); | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | # Snapshot peer PIDs before terminate, while all peers are still | ||||||||||||||||||||||||||||
| 240 | # registered. After terminate the service may disconnect and exit | ||||||||||||||||||||||||||||
| 241 | # before wait() gets a chance to see it. | ||||||||||||||||||||||||||||
| 242 | 157 | my $child_pids = $self->_collect_peer_pids($con); | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 157 | $self->terminate($con); | |||||||||||||||||||||||||||
| 245 | 157 | $self->wait($con, child_pids => $child_pids); | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 157 | my $sanity_err; | |||||||||||||||||||||||||||
| 248 | 157 | ▶ | if ($self->do_sanity_check) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 4 | local $@; | |||||||||||||||||||||||||||
| 250 | 4 | ▶ | eval { $self->sanity_check($con); 1 } or $sanity_err = $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 157 | $con->disconnect; | |||||||||||||||||||||||||||
| 254 | 157 | $con = undef; | |||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 157 | $self->unspawn; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 157 | ▶ | die $sanity_err if $sanity_err; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 459 | 1; | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | __END__ | ||||||||||||||||||||||||||||