From f33bb2cb971c1a0207530ffe1426b20229bf656e Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Tue, 30 May 2023 12:01:06 +0100 Subject: [PATCH] Ensure out_buffer written when !can_read --- src/protocol/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index e310dd7..f515f75 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -473,6 +473,7 @@ impl WebSocketContext { // maximum segment lifetimes (2MSL), while there is no corresponding // server impact as a TIME_WAIT connection is immediately reopened upon // a new SYN with a higher seq number). (RFC 6455) + self.frame.write_out_buffer(stream)?; self.state = WebSocketState::Terminated; Err(Error::ConnectionClosed) } else { @@ -484,7 +485,7 @@ impl WebSocketContext { /// /// This function guarantees that the close frame will be queued. /// There is no need to call it again. Calling this function is - /// the same as calling `write(Message::Close(..))`. + /// the same as calling `send(Message::Close(..))`. pub fn close(&mut self, stream: &mut Stream, code: Option) -> Result<()> where Stream: Read + Write, @@ -493,11 +494,8 @@ impl WebSocketContext { self.state = WebSocketState::ClosedByUs; let frame = Frame::close(code); self._write(stream, Some(frame))?; - self.frame.write_out_buffer(stream)?; - } else { - // Already closed, nothing to do. } - Ok(stream.flush()?) + self.flush(stream) } /// Try to decode one message frame. May return None.