From 41818166cf74495c4b747b466da64583a3b3f3dd Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Tue, 30 May 2023 14:37:15 +0100 Subject: [PATCH] refactor WebSocketContext new --- src/protocol/mod.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 634c945..994c951 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -292,23 +292,17 @@ pub struct WebSocketContext { impl WebSocketContext { /// Create a WebSocket context that manages a post-handshake stream. pub fn new(role: Role, config: Option) -> Self { - let config = config.unwrap_or_default(); - let mut frame = FrameCodec::new(); - frame.set_max_out_buffer_len(config.max_write_buffer_size); - frame.set_out_buffer_write_len(config.write_buffer_size); - Self::_new(role, frame, config) + Self::_new(role, FrameCodec::new(), config.unwrap_or_default()) } /// Create a WebSocket context that manages an post-handshake stream. pub fn from_partially_read(part: Vec, role: Role, config: Option) -> Self { - let config = config.unwrap_or_default(); - let mut frame = FrameCodec::from_partially_read(part); - frame.set_max_out_buffer_len(config.max_write_buffer_size); - frame.set_out_buffer_write_len(config.write_buffer_size); - Self::_new(role, frame, config) + Self::_new(role, FrameCodec::from_partially_read(part), config.unwrap_or_default()) } - fn _new(role: Role, frame: FrameCodec, config: WebSocketConfig) -> Self { + fn _new(role: Role, mut frame: FrameCodec, config: WebSocketConfig) -> Self { + frame.set_max_out_buffer_len(config.max_write_buffer_size); + frame.set_out_buffer_write_len(config.write_buffer_size); Self { role, frame,