Skip to content

Commit

Permalink
improved Mojo::IOLoop::Stream to handle unexpected connection close m…
Browse files Browse the repository at this point in the history
…ore gracefully
  • Loading branch information
kraih committed Oct 13, 2011
1 parent ac5b89f commit 137e151
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -17,6 +17,8 @@ This file documents the revision history for Perl extension Mojolicious.
- Improved Mojo::IOLoop to die if started twice.
- Improved setuidgid in Mojo::Server::Daemon.
- Improved Mojo::IOWatcher backend detection.
- Improved Mojo::IOLoop::Stream to handle unexpected connection close
more gracefully.
- Improved documentation.
- Improved tests.
- Fixed many portability issues.
Expand Down
7 changes: 5 additions & 2 deletions lib/Mojo/IOLoop/Stream.pm
@@ -1,7 +1,7 @@
package Mojo::IOLoop::Stream;
use Mojo::Base 'Mojo::EventEmitter';

use Errno qw/EAGAIN EINTR ECONNRESET EWOULDBLOCK/;
use Errno qw/EAGAIN ECONNRESET EINTR EPIPE EWOULDBLOCK/;
use Scalar::Util 'weaken';

use constant CHUNK_SIZE => $ENV{MOJO_CHUNK_SIZE} || 131072;
Expand Down Expand Up @@ -88,7 +88,7 @@ sub _read {
# Retry
return if $! == EAGAIN || $! == EINTR || $! == EWOULDBLOCK;

# Connection reset
# Closed
return $self->emit_safe('close') if $! == ECONNRESET;

# Read error
Expand Down Expand Up @@ -116,6 +116,9 @@ sub _write {
# Retry
return if $! == EAGAIN || $! == EINTR || $! == EWOULDBLOCK;

# Closed
return $self->emit_safe('close') if $! == ECONNRESET || $! == EPIPE;

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

0 comments on commit 137e151

Please sign in to comment.