From 5bab8e85b91e259628dcb7d543acdc22d0c37afb Mon Sep 17 00:00:00 2001 From: Andreas Rottmann Date: Tue, 6 Dec 2016 09:24:34 +0100 Subject: [PATCH] Handle `hup` events as indicating read readiness Using Linux's `epoll(7)` interface, a `EPOLLHUP` condition is signalled for the reading end of a pipe or socket when the other end is closed for writing. This may happen in combination with `EPOLLIN` being signalled (if further data is available for reading), or with `EPOLLIN`. If `EPOLLHUP` is signalled without `EPOLLIN` it indicates an immediate EOF condition, which will result in the next `read()` suceeding with 0 bytes read. It is thus not required to handle `EPOLLHUP` specially in the reader, but we need to indicate readiness upon encountering it. Looking at the `kqueue` and `windows` mio backends, they seem to be turn a detected EOF and connection reset into `mio::Ready::hup()` events, so it may be reasonable to speculate that this change is an improvement for these platforms as well. Fixes #117. --- src/reactor/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reactor/mod.rs b/src/reactor/mod.rs index 470bd5854..4b65a7c7a 100644 --- a/src/reactor/mod.rs +++ b/src/reactor/mod.rs @@ -306,7 +306,7 @@ impl Core { let mut writer = None; let mut inner = self.inner.borrow_mut(); if let Some(io) = inner.io_dispatch.get_mut(token) { - if ready.is_readable() { + if ready.is_readable() || ready.is_hup() { reader = io.reader.take(); io.readiness.fetch_or(1, Ordering::Relaxed); } @@ -430,7 +430,7 @@ impl Inner { let entry = self.io_dispatch.vacant_entry().unwrap(); try!(self.io.register(source, mio::Token(TOKEN_START + entry.index() * 2), - mio::Ready::readable() | mio::Ready::writable(), + mio::Ready::readable() | mio::Ready::writable() | mio::Ready::hup(), mio::PollOpt::edge())); Ok((sched.readiness.clone(), entry.insert(sched).index())) }