Merge pull request #81 from najamelan/cleanup/use_can_read

Make use of can_read to clean up some code
pull/87/head
Daniel Abramov 5 years ago committed by GitHub
commit 9e4244aecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      src/protocol/mod.rs

@ -335,13 +335,8 @@ impl WebSocketContext {
// If we get to this point, the send queue is empty and the underlying socket is still // If we get to this point, the send queue is empty and the underlying socket is still
// willing to take more data. // willing to take more data.
let closing_state = match self.state {
WebSocketState::ClosedByPeer | WebSocketState::CloseAcknowledged => true,
_ => false,
};
// If we're closing and there is nothing to send anymore, we should close the connection. // If we're closing and there is nothing to send anymore, we should close the connection.
if self.role == Role::Server && closing_state { if self.role == Role::Server && !self.state.can_read() {
// The underlying TCP connection, in most normal cases, SHOULD be closed // The underlying TCP connection, in most normal cases, SHOULD be closed
// first by the server, so that it holds the TIME_WAIT state and not the // first by the server, so that it holds the TIME_WAIT state and not the
// client (as this would prevent it from re-opening the connection for 2 // client (as this would prevent it from re-opening the connection for 2
@ -565,13 +560,10 @@ impl WebSocketContext {
// An expected "Connection reset by peer" is not fatal // An expected "Connection reset by peer" is not fatal
match res { match res {
Err(Error::Io(err)) => Err({ Err(Error::Io(err)) => Err({
match self.state { if !self.state.can_read() && err.kind() == IoErrorKind::ConnectionReset {
WebSocketState::ClosedByPeer | WebSocketState::CloseAcknowledged Error::ConnectionClosed
if err.kind() == IoErrorKind::ConnectionReset => } else {
{ Error::Io(err)
Error::ConnectionClosed
}
_ => Error::Io(err),
} }
}), }),
x => x, x => x,

Loading…
Cancel
Save