feat(server): Allow keep alive to be turned off for a connection (#1390)

Closes #1365
This commit is contained in:
Steven Fackler
2017-12-04 10:14:20 -08:00
committed by Sean McArthur
parent cecef9d402
commit eb9590e3da
4 changed files with 136 additions and 3 deletions

View File

@@ -453,6 +453,14 @@ where I: AsyncRead + AsyncWrite,
pub fn close_write(&mut self) {
self.state.close_write();
}
pub fn disable_keep_alive(&mut self) {
if self.state.is_idle() {
self.state.close_read();
} else {
self.state.disable_keep_alive();
}
}
}
// ==== tokio_proto impl ====
@@ -700,6 +708,10 @@ impl<B, K: KeepAlive> State<B, K> {
}
}
fn disable_keep_alive(&mut self) {
self.keep_alive.disable()
}
fn busy(&mut self) {
if let KA::Disabled = self.keep_alive.status() {
return;
@@ -869,7 +881,7 @@ mod tests {
other => panic!("unexpected frame: {:?}", other)
}
// client
// client
let io = AsyncIo::new_buf(vec![], 1);
let mut conn = Conn::<_, proto::Chunk, ClientTransaction>::new(io, Default::default());
conn.state.busy();

View File

@@ -54,6 +54,10 @@ where
}
}
pub fn disable_keep_alive(&mut self) {
self.conn.disable_keep_alive()
}
fn poll_read(&mut self) -> Poll<(), ::Error> {
loop {
if self.conn.can_read_head() {