Run everything through rustfmt

pull/93/head
Sebastian Dröge 5 years ago
parent f659af4493
commit 7a4779b6f6
  1. 8
      src/protocol/frame/mod.rs
  2. 11
      src/protocol/mod.rs
  3. 7
      tests/no_send_after_close.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);
}

@ -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,
}
}

@ -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),
}

Loading…
Cancel
Save