X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FConnectionServer.pm;h=13bf81147eebcd048f6d2107baaf456b8400aecd;hp=85869d09aea838c9b3cfdecac2349ad5cf6574c2;hb=9031635d18e754da303557b656c63ce8e7eb8e77;hpb=3687a42d0f4ac20dfd2cb31cb76cf9866ee63f14 diff --git a/lib/Object/Remote/ConnectionServer.pm b/lib/Object/Remote/ConnectionServer.pm index 85869d0..13bf811 100644 --- a/lib/Object/Remote/ConnectionServer.pm +++ b/lib/Object/Remote/ConnectionServer.pm @@ -3,6 +3,7 @@ package Object::Remote::ConnectionServer; use Scalar::Util qw(blessed weaken); use Module::Runtime qw(use_module); use Object::Remote; +use Object::Remote::Logging qw( :log :dlog ); use IO::Socket::UNIX; use POSIX (); use Moo; @@ -19,6 +20,7 @@ has listen_on => ( }, trigger => sub { my ($self, $fh) = @_; + log_debug { "adding connection server to run loop because the trigger has executed" }; weaken($self); Object::Remote->current_loop ->watch_io( @@ -37,18 +39,23 @@ has connection_callback => ( ); sub BUILD { + log_debug { "A connection server has been built; calling want_run on run loop" }; Object::Remote->current_loop->want_run; } sub run { + log_debug { "Connection server is calling run_while_wanted on the run loop" }; Object::Remote->current_loop->run_while_wanted; } sub _listen_ready { my ($self, $fh) = @_; + log_debug { "Got a connection, calling accept on the file handle" }; my $new = $fh->accept or die "Couldn't accept: $!"; + log_trace { "Setting file handle non-blocking" }; $new->blocking(0); my $f = CPS::Future->new; + log_trace { "Creating a new connection with the remote node" }; my $c = use_module('Object::Remote::Connection')->new( receive_from_fh => $new, send_to_fh => $new, @@ -56,22 +63,32 @@ sub _listen_ready { @{$self->connection_args} )->${\$self->connection_callback}; $f->on_ready(sub { undef($c) }); + log_trace { "marking the future as done" }; $c->ready_future->done; + #TODO see if this runs on the controller or the remote node + #if this runs on the controller a poorly behaved remote node + #could cause the print() to block but it's a very low probability + Dlog_trace { "Sending 'Shere' to socket $_" } $new; print $new "Shere\n" or die "Couldn't send to new socket: $!"; + log_debug { "Connection has been fully handled" }; return $c; } sub DEMOLISH { my ($self, $gd) = @_; + log_debug { "A connection server is being destroyed; global destruction: '$gd'" }; return if $gd; + log_trace { "Removing the connection server IO watcher from run loop" }; Object::Remote->current_loop ->unwatch_io( handle => $self->listen_on, on_read_ready => 1 ); if ($self->listen_on->can('hostpath')) { + log_debug { my $p = $self->listen_on->hostpath; "Removing '$p' from the filesystem" }; unlink($self->listen_on->hostpath); } + log_trace { "calling want_stop on the run loop" }; Object::Remote->current_loop->want_stop; }