From 06e55a4ef25350d7d6a21e8421a2a183a1310b6e Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Sat, 27 May 2023 13:27:55 +0100 Subject: [PATCH] Refactor additional_send writing --- src/protocol/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index ce97c51..1100a67 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -434,16 +434,17 @@ impl WebSocketContext { // respond with Pong frame as soon as is practical. (RFC 6455) let should_flush = if let Some(msg) = self.additional_send.take() { trace!("Sending pong/close"); - if let Err(err) = self.write_one_frame(stream, msg) { - match err { + match self.write_one_frame(stream, msg) { + Err(Error::WriteBufferFull(Message::Frame(msg))) => { // if an system message would exceed the buffer put it back in // `additional_send` for retry. Otherwise returning this error // may not make sense to the user, e.g. calling `flush`. - Error::WriteBufferFull(Message::Frame(msg)) => self.set_additional(msg), - err => return Err(err), + self.set_additional(msg); + false } + Err(err) => return Err(err), + Ok(_) => true, } - true } else { false };