X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FConnection.pm;h=ba68d86023ad5c12d1a20aeadb7aed0018913b8b;hp=da80bac8ae2f4b8e559cb512edb86a7c2d0b70c7;hb=9d64d2d9b2401f99b747ecf754384adb661f0a5b;hpb=a6786ddab559c869f448c1cb963e83faeb5efd40 diff --git a/lib/Object/Remote/Connection.pm b/lib/Object/Remote/Connection.pm index da80bac..ba68d86 100644 --- a/lib/Object/Remote/Connection.pm +++ b/lib/Object/Remote/Connection.pm @@ -6,6 +6,7 @@ use Object::Remote::Handle; use Object::Remote::CodeContainer; use Object::Remote::GlobProxy; use Object::Remote::GlobContainer; +use Object::Remote::Logging qw (:log :dlog); use Object::Remote; use Symbol; use IO::Handle; @@ -139,6 +140,7 @@ sub remote_object { sub connect { my ($self, $to) = @_; + Dlog_debug { "Creating connection to remote node $_" } $to; return await_future( $self->send_class_call(0, 'Object::Remote', connect => $to) ); @@ -147,11 +149,13 @@ sub connect { sub remote_sub { my ($self, $sub) = @_; my ($pkg, $name) = $sub =~ m/^(.*)::([^:]+)$/; + log_debug { "Invoking remote sub '$sub'" }; return await_future($self->send_class_call(0, $pkg, can => $name)); } sub send_class_call { my ($self, $ctx, @call) = @_; + log_trace { "Sending a non-blocking class call" }; $self->send(call => class_call_handler => $ctx => call => @call); } @@ -175,12 +179,14 @@ sub new_class_call_handler { sub register_remote { my ($self, $remote) = @_; + log_trace { my $i = $remote->id; "Registered a remote object with id of '$i'" }; weaken($self->remote_objects_by_id->{$remote->id} = $remote); return $remote; } sub send_free { my ($self, $id) = @_; + log_debug { "sending request to free object '$id'" }; delete $self->remote_objects_by_id->{$id}; $self->_send([ free => $id ]); } @@ -215,8 +221,16 @@ sub send_discard { sub _send { my ($self, $to_send) = @_; - - print { $self->send_to_fh } $self->_serialize($to_send)."\n"; + my $fh = $self->send_to_fh; + my $serialized = $self->_serialize($to_send)."\n"; + Dlog_debug { my $l = length($serialized); "Sending '$l' characters of serialized data to $_" } $fh; + #TODO this is very risky for deadlocks unless it's set to non-blocking and then with out extra + #logic it could easily do short-writes to the remote side + my $ret = print $fh $serialized; + Dlog_trace { my $r = defined $ret ? $ret : 'undef'; "print() returned $r with $_" } $fh; + #TODO hrm reason print's return value was ignored? + die "could not write to filehandle: $!" unless $ret; + return $ret; } sub _serialize {