Refactor write_one_frame -> buffer_frame

This commit is contained in:
Alex Butler 2023-05-30 14:34:24 +01:00
parent f33bb2cb97
commit 0cada00fb5
2 changed files with 7 additions and 5 deletions

View File

@ -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<Stream>(&mut self, stream: &mut Stream, frame: Frame) -> Result<()>
where
Stream: Write,

View File

@ -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<Stream>(&mut self, stream: &mut Stream, mut frame: Frame) -> Result<()>
/// Write a single frame into the write-buffer.
fn buffer_frame<Stream>(&mut self, stream: &mut Stream, mut frame: Frame) -> Result<()>
where
Stream: Read + Write,
{