Fix close handling while read.

Signed-off-by: Alexey Galakhov <agalakhov@snapview.de>
pull/13/head
Alexey Galakhov 7 years ago
parent 22f7df0b46
commit e3c0ec30c8
  1. 12
      src/protocol/mod.rs

@ -293,7 +293,14 @@ impl<Stream: Read + Write> WebSocket<Stream> {
} // match opcode } // match opcode
} else { } else {
Err(Error::Protocol("Connection reset without closing handshake".into())) match replace(&mut self.state, WebSocketState::Terminated) {
WebSocketState::CloseAcknowledged(close) | WebSocketState::ClosedByPeer(close) => {
Err(Error::ConnectionClosed(close))
}
_ => {
Err(Error::Protocol("Connection reset without closing handshake".into()))
}
}
} }
} }
@ -342,6 +349,7 @@ impl<Stream: Read + Write> WebSocket<Stream> {
} }
} }
} }
WebSocketState::Terminated => unreachable!(),
} }
} }
@ -413,6 +421,8 @@ enum WebSocketState {
ClosedByPeer(Option<CloseFrame<'static>>), ClosedByPeer(Option<CloseFrame<'static>>),
/// The peer replied to our close handshake. /// The peer replied to our close handshake.
CloseAcknowledged(Option<CloseFrame<'static>>), CloseAcknowledged(Option<CloseFrame<'static>>),
/// The connection does not exist anymore.
Terminated,
} }
impl WebSocketState { impl WebSocketState {

Loading…
Cancel
Save