| 1 | package Object::Remote::Role::Connector; | ||||||||||
| 2 | |||||||||||
| 3 | 28 | ▶ | use Module::Runtime qw(use_module); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 14 | ▶ | use Object::Remote::Future; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 14 | ▶ | use Object::Remote::Logging qw(:log :dlog router); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 14 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | requires '_open2_for'; | ||||||||||
| 9 | |||||||||||
| 10 | 22 | ▶ | has timeout => (is => 'ro', default => sub { 10 }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 14 | ▶ | BEGIN { router()->exclude_forwarding; } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 20 | ▶ | sub connect { | ||||||||
|
Subroutine
connect: called CC=1 SCAR=1.3
Pod
undocumented
| |||||||||||
| 15 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
connect: not called CC=1 SCAR=1.3
Pod
undocumented
| |||||||||||
| 16 | 0 | ▶ | Dlog_debug { "Preparing to create connection with args of: $_" } @_; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||
| 17 | 0 | my ($send_to_fh, $receive_from_fh, $child_pid) = $self->_open2_for(@_); | |||||||||
| 18 | 0 | my $channel = use_module('Object::Remote::ReadChannel')->new( | |||||||||
| 19 | fh => $receive_from_fh | ||||||||||
| 20 | ); | ||||||||||
| 21 | return future { | ||||||||||
| 22 | 20 | ▶ | log_trace { "Initializing connection for child pid '$child_pid'" }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 39 | my $f = shift; | |||||||||
| 24 | $channel->on_line_call(sub { | ||||||||||
| 25 | 0 | ▶ | if ($_[0] eq "Shere") { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=15.9
Branch: 1 branch
| |||||||||||
| 26 | 0 | ▶ | log_trace { "Received 'Shere' from child pid '$child_pid'; setting done handler to create connection" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | 0 | $f->done( | |||||||||
| 28 | use_module('Object::Remote::Connection')->new( | ||||||||||
| 29 | send_to_fh => $send_to_fh, | ||||||||||
| 30 | read_channel => $channel, | ||||||||||
| 31 | child_pid => $child_pid, | ||||||||||
| 32 | ) | ||||||||||
| 33 | ); | ||||||||||
| 34 | } else { | ||||||||||
| 35 | 0 | ▶ | log_warn { "'Shere' was not found in connection data for child pid '$child_pid'" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | 0 | $f->fail("Expected Shere from remote but received: $_[0]"); | |||||||||
| 37 | } | ||||||||||
| 38 | 0 | undef($channel); | |||||||||
| 39 | 39 | }); | |||||||||
| 40 | $f->on_fail(sub { | ||||||||||
| 41 | # when the future doesn't fail, the connection takes ownership of the child process | ||||||||||
| 42 | 1 | ▶ | kill('TERM', $child_pid); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 1 | waitpid $child_pid, 0; | |||||||||
| 44 | 20 | }); | |||||||||
| 45 | $channel->on_close_call(sub { | ||||||||||
| 46 | 0 | ▶ | log_trace { "Connection has been closed" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 47 | 0 | $f->fail("Channel closed without seeing Shere: $_[0]"); | |||||||||
| 48 | 0 | undef($channel); | |||||||||
| 49 | 20 | }); | |||||||||
| 50 | 39 | ▶ | log_trace { "initialized events on channel for child pid '$child_pid'; creating timeout" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 51 | Object::Remote->current_loop | ||||||||||
| 52 | ->watch_time( | ||||||||||
| 53 | after => $self->timeout, | ||||||||||
| 54 | code => sub { | ||||||||||
| 55 | 1 | ▶ | Dlog_trace {"Connection timeout timer has fired for child pid '$child_pid'; is_ready: $_" } $f->is_ready; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 56 | 1 | ▶ | unless($f->is_ready) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 1 | ▶ | log_warn { "Connection with child pid '$child_pid' has timed out" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 58 | 1 | ▶ | $f->fail("Connection timed out") unless $f->is_ready; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | } | ||||||||||
| 60 | 0 | undef($channel); | |||||||||
| 61 | |||||||||||
| 62 | } | ||||||||||
| 63 | 20 | ); | |||||||||
| 64 | 20 | ▶ | log_trace { "connection for child pid '$child_pid' has been initialized" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 65 | 0 | $f; | |||||||||
| 66 | } | ||||||||||
| 67 | 0 | } | |||||||||
| 68 | |||||||||||
| 69 | 1; | ||||||||||