Permalink
Browse files

improved Mojo::IOLoop::Stream to handle unexpected connection close m…

…ore gracefully
  • Loading branch information...
1 parent ac5b89f commit 137e1515dc2c38ac1a1a50b434264945bff55d42 @kraih committed Oct 13, 2011
Showing with 7 additions and 2 deletions.
  1. +2 −0 Changes
  2. +5 −2 lib/Mojo/IOLoop/Stream.pm
View
@@ -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.
@@ -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;
@@ -88,7 +88,7 @@ sub _read {
# Retry
return if $! == EAGAIN || $! == EINTR || $! == EWOULDBLOCK;
- # Connection reset
+ # Closed
return $self->emit_safe('close') if $! == ECONNRESET;
# Read error
@@ -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 => $!);
}

0 comments on commit 137e151

Please sign in to comment.