From b9df442f035e6648e80adf8f9bf86b4943508ae5 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 22 Jul 2022 13:32:08 +0200 Subject: Small optimization --- src/endpoint.rs | 5 ++++- src/message.rs | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/endpoint.rs b/src/endpoint.rs index 31500aa..588f7e3 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -52,7 +52,10 @@ where T: EndpointHandler, M: Message + 'static, { - async fn handle(self: &Arc, m: Req, from: NodeID) -> Resp { + async fn handle(self: &Arc, mut m: Req, from: NodeID) -> Resp { + // Immediately drop stream to avoid backpressure if a stream was sent + // (this will make all data sent to the stream be ignored immediately) + drop(m.take_stream()); Resp::new(EndpointHandler::handle(self, m.msg(), from).await) } } diff --git a/src/message.rs b/src/message.rs index ba06551..0ac4cb8 100644 --- a/src/message.rs +++ b/src/message.rs @@ -81,6 +81,10 @@ impl Req { } } + pub fn take_stream(&mut self) -> Option { + std::mem::replace(&mut self.body, BodyData::None).into_stream() + } + pub(crate) fn into_enc( self, prio: RequestPriority, -- cgit v1.2.3