From 0cada00fb55828f347735a084d040b08dbd5a7c1 Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Tue, 30 May 2023 14:34:24 +0100 Subject: [PATCH] Refactor write_one_frame -> buffer_frame --- src/protocol/frame/mod.rs | 4 +++- src/protocol/mod.rs | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/protocol/frame/mod.rs b/src/protocol/frame/mod.rs index df8230e..7d2ee41 100644 --- a/src/protocol/frame/mod.rs +++ b/src/protocol/frame/mod.rs @@ -205,7 +205,9 @@ impl FrameCodec { /// If the out buffer size is over the `out_buffer_write_len` will also write /// the out buffer into the provided `stream`. /// - /// Does **not** flush. + /// To ensure buffered frames are written call [`Self::write_out_buffer`]. + /// + /// May write to the stream, will **not** flush. pub(super) fn buffer_frame(&mut self, stream: &mut Stream, frame: Frame) -> Result<()> where Stream: Write, diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index f515f75..634c945 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -442,7 +442,7 @@ impl WebSocketContext { Stream: Read + Write, { if let Some(data) = data { - self.write_one_frame(stream, data)?; + self.buffer_frame(stream, data)?; } // Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in @@ -450,7 +450,7 @@ 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"); - match self.write_one_frame(stream, msg) { + match self.buffer_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 @@ -665,8 +665,8 @@ impl WebSocketContext { } } - /// Write a single frame into the stream via the write-buffer. - fn write_one_frame(&mut self, stream: &mut Stream, mut frame: Frame) -> Result<()> + /// Write a single frame into the write-buffer. + fn buffer_frame(&mut self, stream: &mut Stream, mut frame: Frame) -> Result<()> where Stream: Read + Write, {