Skip to content

Commit

Permalink
made exception handling in Mojo::IOLoop::Stream more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 17, 2011
1 parent 62467be commit 3fd0619
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -38,7 +38,7 @@ sub is_readable {

sub is_writing {
my $self = shift;
return if $self->{timed};
return if $self->{closed} || $self->{error} || $self->{timed_out};
return length($self->{buffer}) || $self->has_subscribers('drain');
}

Expand All @@ -57,7 +57,7 @@ sub resume {
$self->{timer} ||= $watcher->recurring(
'0.025' => sub {
return unless $self && (time - ($self->{active})) >= $self->timeout;
$self->emit_safe('timeout') unless $self->{timed}++;
$self->emit_safe('timeout') unless $self->{timed_out}++;
$self->_close;
}
);
Expand Down Expand Up @@ -102,6 +102,12 @@ sub _close {
$self->emit_safe('close') unless $self->{closed}++;
}

sub _error {
my $self = shift;
$self->{error}++;
$self->emit_safe(error => $!);
}

sub _read {
my $self = shift;

Expand All @@ -118,7 +124,7 @@ sub _read {
return $self->_close if $! == ECONNRESET;

# Read error
return $self->emit_safe(error => $!);
return $self->_error($!);
}

# EOF
Expand Down Expand Up @@ -149,7 +155,7 @@ sub _write {
return $self->_close if $! ~~ [ECONNRESET, EPIPE];

# Write error
return $self->emit_safe(error => $!);
return $self->_error($!);
}

# Remove written chunk from buffer
Expand Down

0 comments on commit 3fd0619

Please sign in to comment.