Skip to content

Commit

Permalink
fixed error handling bugs in Mojo::IOLoop::Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 17, 2014
1 parent 484732f commit 90fd43f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@

5.70 2014-12-17
- Improved Mojo::Template performance.
- Fixed error handling bugs in Mojo::IOLoop::Stream.
- Fixed a few limit bugs in Mojo::Message.
- Fixed Windows bug in Mojo::IOLoop::Client. (OlegG)

Expand Down
22 changes: 9 additions & 13 deletions lib/Mojo/IOLoop/Stream.pm
@@ -1,7 +1,7 @@
package Mojo::IOLoop::Stream;
use Mojo::Base 'Mojo::EventEmitter';

use Errno qw(EAGAIN ECONNRESET EINTR EPIPE EWOULDBLOCK);
use Errno qw(EAGAIN ECONNRESET EINTR EWOULDBLOCK);
use Mojo::IOLoop;
use Scalar::Util 'weaken';

Expand Down Expand Up @@ -95,34 +95,30 @@ sub write {

sub _again { $_[0]->reactor->again($_[0]{timer}) if $_[0]{timer} }

sub _error {
sub _read {
my $self = shift;

if (defined(my $read = $self->{handle}->sysread(my $buffer, 131072, 0))) {
return $self->close if $read == 0;
return $self->emit(read => $buffer)->_again;
}

# Retry
return if $! == EAGAIN || $! == EINTR || $! == EWOULDBLOCK;

# Closed
return $self->close if $! == ECONNRESET || $! == EPIPE;
return $self->close if $! == ECONNRESET;

# Error
$self->emit(error => $!)->close;
}

sub _read {
my $self = shift;
my $read = $self->{handle}->sysread(my $buffer, 131072, 0);
return $self->_error unless defined $read;
return $self->close if $read == 0;
$self->emit(read => $buffer)->_again;
}

sub _write {
my $self = shift;

my $handle = $self->{handle};
if (length $self->{buffer}) {
my $written = $handle->syswrite($self->{buffer});
return $self->_error unless defined $written;
return unless defined(my $written = $handle->syswrite($self->{buffer}));
$self->emit(write => substr($self->{buffer}, 0, $written, ''))->_again;
}

Expand Down

0 comments on commit 90fd43f

Please sign in to comment.