X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FRole%2FConnector.pm;h=747341c777355d0c2abe000db1aae6bd5d822b5d;hp=cc8684b6b0bf703090da1cfec935348a9d42aa0a;hb=f1d7083568d3d8322a66f9c1265ef326999c5a23;hpb=12fb4a80d68ad14c18a35f60cc6d8a671f728ac9 diff --git a/lib/Object/Remote/Role/Connector.pm b/lib/Object/Remote/Role/Connector.pm index cc8684b..747341c 100644 --- a/lib/Object/Remote/Role/Connector.pm +++ b/lib/Object/Remote/Role/Connector.pm @@ -2,20 +2,26 @@ package Object::Remote::Role::Connector; use Module::Runtime qw(use_module); use Object::Remote::Future; +use Object::Remote::Logging qw(:log :dlog ); use Moo::Role; requires '_open2_for'; +has timeout => (is => 'ro', default => sub { 10 }); + sub connect { my $self = shift; + Dlog_debug { "Preparing to create connection with args of: $_" } @_; my ($send_to_fh, $receive_from_fh, $child_pid) = $self->_open2_for(@_); my $channel = use_module('Object::Remote::ReadChannel')->new( fh => $receive_from_fh ); return future { + log_trace { "Initializing connection for child pid '$child_pid'" }; my $f = shift; $channel->on_line_call(sub { if ($_[0] eq "Shere") { + log_trace { "Received 'Shere' from child pid '$child_pid'; setting done handler to create connection" }; $f->done( use_module('Object::Remote::Connection')->new( send_to_fh => $send_to_fh, @@ -24,22 +30,31 @@ sub connect { ) ); } else { + log_warn { "'Shere' was not found in connection data for child pid '$child_pid'" }; $f->fail("Expected Shere from remote but received: $_[0]"); } undef($channel); }); $channel->on_close_call(sub { + log_trace { "Connection has been closed" }; $f->fail("Channel closed without seeing Shere: $_[0]"); undef($channel); }); + log_trace { "initialized events on channel for child pid '$child_pid'; creating timeout" }; Object::Remote->current_loop ->watch_time( - after => 5, + after => $self->timeout, code => sub { - $f->fail("Connection timed out") unless $f->is_ready; + Dlog_trace {"Connection timeout timer has fired for child pid '$child_pid'; is_ready: $_" } $f->is_ready; + unless($f->is_ready) { + log_warn { "Connection with child pid '$child_pid' has timed out" }; + $f->fail("Connection timed out") unless $f->is_ready; + } undef($channel); + } ); + log_trace { "connection for child pid '$child_pid' has been initialized" }; $f; } }