Refactor write_one_frame -> buffer_frame

pull/358/head
Alex Butler 2 years ago
parent f33bb2cb97
commit 0cada00fb5
  1. 4
      src/protocol/frame/mod.rs
  2. 8
      src/protocol/mod.rs

@ -205,7 +205,9 @@ impl FrameCodec {
/// If the out buffer size is over the `out_buffer_write_len` will also write /// If the out buffer size is over the `out_buffer_write_len` will also write
/// the out buffer into the provided `stream`. /// 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<()> pub(super) fn buffer_frame<Stream>(&mut self, stream: &mut Stream, frame: Frame) -> Result<()>
where where
Stream: Write, Stream: Write,

@ -442,7 +442,7 @@ impl WebSocketContext {
Stream: Read + Write, Stream: Read + Write,
{ {
if let Some(data) = data { 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 // 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) // respond with Pong frame as soon as is practical. (RFC 6455)
let should_flush = if let Some(msg) = self.additional_send.take() { let should_flush = if let Some(msg) = self.additional_send.take() {
trace!("Sending pong/close"); trace!("Sending pong/close");
match self.write_one_frame(stream, msg) { match self.buffer_frame(stream, msg) {
Err(Error::WriteBufferFull(Message::Frame(msg))) => { Err(Error::WriteBufferFull(Message::Frame(msg))) => {
// if an system message would exceed the buffer put it back in // if an system message would exceed the buffer put it back in
// `additional_send` for retry. Otherwise returning this error // `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. /// Write a single frame into the write-buffer.
fn write_one_frame<Stream>(&mut self, stream: &mut Stream, mut frame: Frame) -> Result<()> fn buffer_frame<Stream>(&mut self, stream: &mut Stream, mut frame: Frame) -> Result<()>
where where
Stream: Read + Write, Stream: Read + Write,
{ {

Loading…
Cancel
Save