fix(http): Handle readable in keep-alive

It's possible that a connection will be closed and the only way to find
out is by doing a read. The keep-alive state (State::Init + Next_::Wait)
now tries to read on readable. In the case of EOF, it returns state
closed. If bytes are actually available, it's a connection error, and
the connection is closed. Otherwise, it's just a spurious wakeup.
This commit is contained in:
Joe Wilm
2016-10-11 19:25:58 -07:00
parent 34c4d72712
commit 915af2a3a8

View File

@@ -236,6 +236,29 @@ impl<K: Key, T: Transport, H: MessageHandler<T>> ConnInner<K, T, H> {
} }
} }
}, },
State::Init { interest: Next_::Wait, .. } => {
match self.buf.read_from(&mut self.transport) {
Ok(0) => {
// End-of-file; connection was closed by peer
State::Closed
},
Ok(n) => {
// Didn't expect bytes here! Close the connection.
warn!("read {} bytes in State::Init with Wait interest", n);
State::Closed
},
Err(e) => match e.kind() {
io::ErrorKind::WouldBlock => {
// This is the expected case reading in this state
state
},
_ => {
warn!("socket error reading State::Init with Wait interest: {}", e);
State::Closed
}
}
}
},
State::Init { .. } => { State::Init { .. } => {
trace!("on_readable State::{:?}", state); trace!("on_readable State::{:?}", state);
state state