feat(server): Allow keep alive to be turned off for a connection (#1390)
Closes #1365
This commit is contained in:
committed by
Sean McArthur
parent
cecef9d402
commit
eb9590e3da
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -536,6 +536,18 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, B, S> Connection<I, S>
|
||||
where S: Service<Request = Request, Response = Response<B>, Error = ::Error> + 'static,
|
||||
I: AsyncRead + AsyncWrite + 'static,
|
||||
B: Stream<Error=::Error> + 'static,
|
||||
B::Item: AsRef<[u8]>,
|
||||
{
|
||||
/// Disables keep-alive for this connection.
|
||||
pub fn disable_keep_alive(&mut self) {
|
||||
self.conn.disable_keep_alive()
|
||||
}
|
||||
}
|
||||
|
||||
mod unnameable {
|
||||
// This type is specifically not exported outside the crate,
|
||||
// so no one can actually name the type. With no methods, we make no
|
||||
|
||||
Reference in New Issue
Block a user