From 1e6603353e0d9445e9a6be61b0742f37aa365be9 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Mon, 25 Feb 2019 17:27:51 -0800 Subject: [PATCH] perf(http2): don't register callback with main h2 client task --- src/client/dispatch.rs | 11 +++++++++-- src/proto/h2/client.rs | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 6973df79..b49c6d3f 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -178,14 +178,21 @@ pub enum Callback { } impl Callback { - pub fn poll_cancel(&mut self) -> Poll<(), ()> { + pub(crate) fn is_canceled(&self) -> bool { + match *self { + Callback::Retry(ref tx) => tx.is_canceled(), + Callback::NoRetry(ref tx) => tx.is_canceled(), + } + } + + pub(crate) fn poll_cancel(&mut self) -> Poll<(), ()> { match *self { Callback::Retry(ref mut tx) => tx.poll_cancel(), Callback::NoRetry(ref mut tx) => tx.poll_cancel(), } } - pub fn send(self, val: Result)>) { + pub(crate) fn send(self, val: Result)>) { match self { Callback::Retry(tx) => { let _ = tx.send(val); diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 7ccceac0..c48561c8 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -102,7 +102,7 @@ where match self.rx.poll() { Ok(Async::Ready(Some((req, mut cb)))) => { // check that future hasn't been canceled already - if let Async::Ready(()) = cb.poll_cancel().expect("poll_cancel cannot error") { + if cb.is_canceled() { trace!("request canceled"); continue; } @@ -117,7 +117,7 @@ where Ok(ok) => ok, Err(err) => { debug!("client send request error: {}", err); - let _ = cb.send(Err((::Error::new_h2(err), None))); + cb.send(Err((::Error::new_h2(err), None))); continue; } }; @@ -147,11 +147,11 @@ where let content_length = content_length_parse_all(res.headers()); let res = res.map(|stream| ::Body::h2(stream, content_length)); - let _ = cb.send(Ok(res)); + cb.send(Ok(res)); }, Err(err) => { debug!("client response error: {}", err); - let _ = cb.send(Err((::Error::new_h2(err), None))); + cb.send(Err((::Error::new_h2(err), None))); } } Ok(())