diff --git a/src/client/conn.rs b/src/client/conn.rs index 064f9aad3b..2195622c54 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -376,6 +376,10 @@ where /// upgrade. Once the upgrade is completed, the connection would be "done", /// but it is not desired to actally shutdown the IO object. Instead you /// would take it back using `into_parts`. + /// + /// Use [`poll_fn`](https://docs.rs/futures/0.1.25/futures/future/fn.poll_fn.html) + /// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html) + /// to work with this function; or use the `without_shutdown` wrapper. pub fn poll_without_shutdown(&mut self) -> Poll<(), ::Error> { match self.inner.as_mut().expect("already upgraded") { &mut Either::A(ref mut h1) => { @@ -386,6 +390,16 @@ where } } } + + /// Prevent shutdown of the underlying IO object at the end of service the request, + /// instead run `into_parts`. This is a convenience wrapper over `poll_without_shutdown`. + pub fn without_shutdown(self) -> impl Future, Error=::Error> { + let mut conn = Some(self); + ::futures::future::poll_fn(move || -> ::Result<_> { + try_ready!(conn.as_mut().unwrap().poll_without_shutdown()); + Ok(conn.take().unwrap().into_parts().into()) + }) + } } impl Future for Connection diff --git a/src/server/conn.rs b/src/server/conn.rs index ad52944667..82b3ba7d2f 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -542,6 +542,10 @@ where /// upgrade. Once the upgrade is completed, the connection would be "done", /// but it is not desired to actally shutdown the IO object. Instead you /// would take it back using `into_parts`. + /// + /// Use [`poll_fn`](https://docs.rs/futures/0.1.25/futures/future/fn.poll_fn.html) + /// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html) + /// to work with this function; or use the `without_shutdown` wrapper. pub fn poll_without_shutdown(&mut self) -> Poll<(), ::Error> { loop { let polled = match *self.conn.as_mut().unwrap() { @@ -564,6 +568,16 @@ where } } + /// Prevent shutdown of the underlying IO object at the end of service the request, + /// instead run `into_parts`. This is a convenience wrapper over `poll_without_shutdown`. + pub fn without_shutdown(self) -> impl Future, Error=::Error> { + let mut conn = Some(self); + ::futures::future::poll_fn(move || -> ::Result<_> { + try_ready!(conn.as_mut().unwrap().poll_without_shutdown()); + Ok(conn.take().unwrap().into_parts().into()) + }) + } + fn upgrade_h2(&mut self) { trace!("Trying to upgrade connection to h2"); let conn = self.conn.take();