X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FReadChannel.pm;h=ed29f582628139db13a2b37a0abfc902c960c15d;hp=6402bdd9011b530c40bc653e86b89ff0043fc1cb;hb=8c3529062a426181861d58ee59fb8f10e0be68e5;hpb=9d64d2d9b2401f99b747ecf754384adb661f0a5b diff --git a/lib/Object/Remote/ReadChannel.pm b/lib/Object/Remote/ReadChannel.pm index 6402bdd..ed29f58 100644 --- a/lib/Object/Remote/ReadChannel.pm +++ b/lib/Object/Remote/ReadChannel.pm @@ -1,10 +1,12 @@ package Object::Remote::ReadChannel; use CPS::Future; -use Scalar::Util qw(weaken); -use Object::Remote::Logging qw(:log); +use Scalar::Util qw(weaken openhandle); +use Object::Remote::Logging qw(:log :dlog router ); use Moo; +BEGIN { router()->exclude_forwarding } + has fh => ( is => 'ro', required => 1, trigger => sub { @@ -27,26 +29,12 @@ has on_line_call => (is => 'rw'); has _receive_data_buffer => (is => 'ro', default => sub { my $x = ''; \$x }); -#TODO confirmed this is the point of the hang - sysread() is invoked on a -#socket inside the controller that blocks and deadlocks the entire system. -#The remote nodes are all waiting to receive data at that point. -#Validated this behavior exists in an unmodified Object::Remote from CPAN -#by wrapping this sysread() with warns that have the pid in them and pounding -#my local machine with System::Introspector via ssh and 7 remote perl instances -#It looks like one of the futures is responding to an event regarding the ability -#to read from a socket and every once in a while an ordering issue means that -#there is no actual data to read from the socket sub _receive_data_from { my ($self, $fh) = @_; - log_trace { "Preparing to read data" }; - #use Carp qw(cluck); cluck(); + Dlog_trace { "Preparing to read data from $_" } $fh; my $rb = $self->_receive_data_buffer; - #TODO is there a specific reason sysread() and syswrite() aren't - #a part of ::MiniLoop? It's one spot to handle errors and other - #logic involving filehandles - #TODO why are the buffers so small? BUFSIZ is usually 32768 - my $len = sysread($fh, $$rb, 1024, length($$rb)); - my $err = defined($len) ? '' : ": $!"; + my $len = sysread($fh, $$rb, 32768, length($$rb)); + my $err = defined($len) ? 'eof' : ": $!"; if (defined($len) and $len > 0) { log_trace { "Read $len bytes of data" }; while (my $cb = $self->on_line_call and $$rb =~ s/^(.*)\n//) { @@ -59,6 +47,7 @@ sub _receive_data_from { handle => $self->fh, on_read_ready => 1 ); + log_trace { "Invoking on_close_call() for dead read channel" }; $self->on_close_call->($err); } } @@ -67,11 +56,14 @@ sub DEMOLISH { my ($self, $gd) = @_; return if $gd; log_trace { "read channel is being demolished" }; + Object::Remote->current_loop ->unwatch_io( handle => $self->fh, on_read_ready => 1 ); + + } 1;