Remove boilerplace in `poll_flush()`

tungstenite-0.20
Daniel Abramov 2 years ago committed by Sebastian Dröge
parent 59a8bf29db
commit 56917cd21e
  1. 18
      src/lib.rs

@ -388,19 +388,13 @@ where
} }
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match (*self).with_context(Some((ContextWaker::Write, cx)), |s| s.write_pending()) { (*self).with_context(Some((ContextWaker::Write, cx)), |s| cvt(s.write_pending())).map(|r| {
Ok(()) => Poll::Ready(Ok(())), // WebSocket connection has just been closed. Flushing completed, not an error.
Err(WsError::ConnectionClosed) => { match r {
// WebSocket is closing and there is nothing to send anymore. Err(WsError::ConnectionClosed) => Ok(()),
// Not an failure, the flush operation is a success. other => other,
Poll::Ready(Ok(()))
}
Err(WsError::Io(ref e)) if e.kind() == std::io::ErrorKind::WouldBlock => {
trace!("WouldBlock");
Poll::Pending
} }
Err(e) => Poll::Ready(Err(e)), })
}
} }
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {

Loading…
Cancel
Save