diff --git a/src/protocol/frame/mod.rs b/src/protocol/frame/mod.rs index f93f911..6756f0a 100644 --- a/src/protocol/frame/mod.rs +++ b/src/protocol/frame/mod.rs @@ -12,7 +12,7 @@ pub use self::frame::{Frame, FrameHeader}; use crate::error::{Error, Result}; use input_buffer::{InputBuffer, MIN_READ}; use log::*; -use std::io::{Read, Write, Error as IoError, ErrorKind as IoErrorKind}; +use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read, Write}; /// A reader and writer for WebSocket frames. #[derive(Debug)] @@ -199,7 +199,11 @@ impl FrameCodec { let len = stream.write(&self.out_buffer)?; if len == 0 { // This is the same as "Connection reset by peer" - return Err(IoError::new(IoErrorKind::ConnectionReset, "Connection reset while sending").into()) + return Err(IoError::new( + IoErrorKind::ConnectionReset, + "Connection reset while sending", + ) + .into()); } self.out_buffer.drain(0..len); } diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 5eddf75..be43824 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -280,7 +280,9 @@ impl WebSocketContext { // Do not write after sending a close frame. if !self.state.is_active() { - return Err(Error::Protocol("Sending after closing is not allowed".into())); + return Err(Error::Protocol( + "Sending after closing is not allowed".into(), + )); } if let Some(max_send_queue) = self.config.max_send_queue { @@ -378,7 +380,9 @@ impl WebSocketContext { { if let Some(mut frame) = self.frame.read_frame(stream, self.config.max_frame_size)? { if !self.state.can_read() { - return Err(Error::Protocol("Remote sent frame after having sent a Close Frame".into())); + return Err(Error::Protocol( + "Remote sent frame after having sent a Close Frame".into(), + )); } // MUST be 0 unless an extension is negotiated that defines meanings // for non-zero values. If a nonzero value is received and none of @@ -600,8 +604,7 @@ impl WebSocketState { /// close frame, so we should still pass those to client code, hence ClosedByUs is valid. fn can_read(&self) -> bool { match self { - WebSocketState::Active | - WebSocketState::ClosedByUs => true, + WebSocketState::Active | WebSocketState::ClosedByUs => true, _ => false, } } diff --git a/tests/no_send_after_close.rs b/tests/no_send_after_close.rs index 3993e81..d8e20e5 100644 --- a/tests/no_send_after_close.rs +++ b/tests/no_send_after_close.rs @@ -39,13 +39,12 @@ fn test_no_send_after_close() { client_handler.close(None).unwrap(); // send close to client - let err = client_handler - .write_message(Message::Text("Hello WebSocket".into())); + let err = client_handler.write_message(Message::Text("Hello WebSocket".into())); - assert!( err.is_err() ); + assert!(err.is_err()); match err.unwrap_err() { - Error::Protocol(s) => { assert_eq!( "Sending after closing is not allowed", s )} + Error::Protocol(s) => assert_eq!("Sending after closing is not allowed", s), e => panic!("unexpected error: {:?}", e), }