1 package Object::Remote::Role::Connector;
3 use Module::Runtime qw(use_module);
4 use Object::Remote::Future;
5 use Object::Remote::Logging qw(:log :dlog );
10 #TODO return to 10 seconds after debugging
11 #has timeout => (is => 'ro', default => sub { { after => 10 } });
12 has timeout => (is => 'ro', default => sub { { after => 10 } });
16 Dlog_debug { "Perparing to create connection with args of: $_" } @_;
17 my ($send_to_fh, $receive_from_fh, $child_pid) = $self->_open2_for(@_);
18 my $channel = use_module('Object::Remote::ReadChannel')->new(
19 fh => $receive_from_fh
22 log_trace { "Initializing connection for child pid '$child_pid'" };
24 $channel->on_line_call(sub {
25 if ($_[0] eq "Shere") {
26 log_trace { "Received 'Shere' from child pid '$child_pid'; setting done handler to create connection" };
28 use_module('Object::Remote::Connection')->new(
29 send_to_fh => $send_to_fh,
30 read_channel => $channel,
31 child_pid => $child_pid,
35 log_warn { "'Shere' was not found in connection data for child pid '$child_pid'" };
36 $f->fail("Expected Shere from remote but received: $_[0]");
40 $channel->on_close_call(sub {
41 log_trace { "Connection has been closed" };
42 $f->fail("Channel closed without seeing Shere: $_[0]");
45 log_trace { "initialized events on channel for child pid '$child_pid'; creating timeout" };
46 Object::Remote->current_loop
50 # log_warn { "Connection timed out for child pid '$child_pid'" };
51 # $f->fail("Connection timed out") unless $f->is_ready;
53 Dlog_trace { "Connection timeout timer has fired for child pid '$child_pid'; is_ready: $_" } $f->is_ready;
54 unless($f->is_ready) {
55 log_warn { "Connection with child pid '$child_pid' has timed out" };
56 $f->fail("Connection timed out") unless $f->is_ready;
62 log_trace { "connection for child pid '$child_pid' has been initialized" };