X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FRemote%2FReadChannel.pm;h=6bfc3694533508204d7edd70f1a6bd84a73cd72c;hb=b9baacc29444767f88abdbca93f65c8bd5e5a676;hp=5de5bf131a6edd0e8a69674b37f263ffc28404f2;hpb=5d59cb9859e004df5cde5d83aa7230e621a28b95;p=scpubgit%2FObject-Remote.git diff --git a/lib/Object/Remote/ReadChannel.pm b/lib/Object/Remote/ReadChannel.pm index 5de5bf1..6bfc369 100644 --- a/lib/Object/Remote/ReadChannel.pm +++ b/lib/Object/Remote/ReadChannel.pm @@ -2,7 +2,8 @@ package Object::Remote::ReadChannel; use CPS::Future; use Scalar::Util qw(weaken); -use Object::Remote::Logging qw(:log); +use Object::Remote::Logging qw(:log :dlog); +use POSIX; use Moo; has fh => ( @@ -29,22 +30,26 @@ has _receive_data_buffer => (is => 'ro', default => sub { my $x = ''; \$x }); sub _receive_data_from { my ($self, $fh) = @_; - log_trace { "Preparing to read data" }; + Dlog_trace { "Preparing to read data from $_" } $fh; my $rb = $self->_receive_data_buffer; - 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//) { $cb->(my $line = $1); } - } else { + #TODO this isn't compatible with Windows but would be if + #EAGAIN was set to something that could never match + #if on Windows + } elsif ($! != EAGAIN) { log_trace { "Got EOF or error, this read channel is done" }; Object::Remote->current_loop ->unwatch_io( handle => $self->fh, on_read_ready => 1 ); + log_trace { "Invoking on_close_call() for dead read channel" }; $self->on_close_call->($err); } }