package Object::Remote::ReadChannel;
use CPS::Future;
-use Scalar::Util qw(weaken);
+use Scalar::Util qw(weaken openhandle);
use Object::Remote::Logging qw(:log :dlog);
-use POSIX;
use Moo;
has fh => (
Dlog_trace { "Preparing to read data from $_" } $fh;
my $rb = $self->_receive_data_buffer;
my $len = sysread($fh, $$rb, 32768, length($$rb));
- my $err = defined($len) ? '' : ": $!";
+ 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);
}
- #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) {
+ } else {
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);
}
}
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;