split write and write_out_buffer internals

Fix internal method naming
pull/358/head
Alex Butler 2 years ago
parent 2ef5b9a5e2
commit 1b47964f18
  1. 2
      src/protocol/frame/mod.rs
  2. 13
      src/protocol/mod.rs

@ -139,7 +139,7 @@ impl FrameCodec {
/// Sets [`Self::buffer_frame`] buffer target length to reach before /// Sets [`Self::buffer_frame`] buffer target length to reach before
/// writing to the stream. /// writing to the stream.
pub(super) fn set_target_buffer_write_len(&mut self, len: usize) { pub(super) fn set_out_buffer_write_len(&mut self, len: usize) {
self.out_buffer_write_len = len; self.out_buffer_write_len = len;
} }

@ -295,7 +295,7 @@ impl WebSocketContext {
let config = config.unwrap_or_default(); let config = config.unwrap_or_default();
let mut frame = FrameCodec::new(); let mut frame = FrameCodec::new();
frame.set_max_out_buffer_len(config.max_write_buffer_size); frame.set_max_out_buffer_len(config.max_write_buffer_size);
frame.set_target_buffer_write_len(config.write_buffer_size); frame.set_out_buffer_write_len(config.write_buffer_size);
Self::_new(role, frame, config) Self::_new(role, frame, config)
} }
@ -304,7 +304,7 @@ impl WebSocketContext {
let config = config.unwrap_or_default(); let config = config.unwrap_or_default();
let mut frame = FrameCodec::from_partially_read(part); let mut frame = FrameCodec::from_partially_read(part);
frame.set_max_out_buffer_len(config.max_write_buffer_size); frame.set_max_out_buffer_len(config.max_write_buffer_size);
frame.set_target_buffer_write_len(config.write_buffer_size); frame.set_out_buffer_write_len(config.write_buffer_size);
Self::_new(role, frame, config) Self::_new(role, frame, config)
} }
@ -323,7 +323,7 @@ impl WebSocketContext {
pub fn set_config(&mut self, set_func: impl FnOnce(&mut WebSocketConfig)) { pub fn set_config(&mut self, set_func: impl FnOnce(&mut WebSocketConfig)) {
set_func(&mut self.config); set_func(&mut self.config);
self.frame.set_max_out_buffer_len(self.config.max_write_buffer_size); self.frame.set_max_out_buffer_len(self.config.max_write_buffer_size);
self.frame.set_target_buffer_write_len(self.config.write_buffer_size); self.frame.set_out_buffer_write_len(self.config.write_buffer_size);
} }
/// Read the configuration. /// Read the configuration.
@ -428,6 +428,7 @@ impl WebSocketContext {
Stream: Read + Write, Stream: Read + Write,
{ {
self._write(stream, None)?; self._write(stream, None)?;
self.frame.write_out_buffer(stream)?;
Ok(stream.flush()?) Ok(stream.flush()?)
} }
@ -440,9 +441,8 @@ impl WebSocketContext {
where where
Stream: Read + Write, Stream: Read + Write,
{ {
match data { if let Some(data) = data {
Some(data) => self.write_one_frame(stream, data)?, self.write_one_frame(stream, data)?;
None => self.frame.write_out_buffer(stream)?,
} }
// 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
@ -493,6 +493,7 @@ impl WebSocketContext {
self.state = WebSocketState::ClosedByUs; self.state = WebSocketState::ClosedByUs;
let frame = Frame::close(code); let frame = Frame::close(code);
self._write(stream, Some(frame))?; self._write(stream, Some(frame))?;
self.frame.write_out_buffer(stream)?;
} else { } else {
// Already closed, nothing to do. // Already closed, nothing to do.
} }

Loading…
Cancel
Save