|
|
@ -357,34 +357,24 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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>> { |
|
|
|
if self.closing { |
|
|
|
let res = if self.closing { |
|
|
|
// After queueing it, we call `write_pending` to drive the close handshake to completion.
|
|
|
|
// After queueing it, we call `write_pending` to drive the close handshake to completion.
|
|
|
|
match (*self).with_context(Some((ContextWaker::Write, cx)), |s| s.write_pending()) { |
|
|
|
(*self).with_context(Some((ContextWaker::Write, cx)), |s| s.write_pending()) |
|
|
|
Ok(()) => Poll::Ready(Ok(())), |
|
|
|
|
|
|
|
Err(::tungstenite::Error::ConnectionClosed) => Poll::Ready(Ok(())), |
|
|
|
|
|
|
|
Err(::tungstenite::Error::Io(err)) |
|
|
|
|
|
|
|
if err.kind() == std::io::ErrorKind::WouldBlock => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
trace!("WouldBlock"); |
|
|
|
|
|
|
|
Poll::Pending |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Err(err) => Poll::Ready(Err(err)), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
match (*self).with_context(Some((ContextWaker::Write, cx)), |s| s.close(None)) { |
|
|
|
(*self).with_context(Some((ContextWaker::Write, cx)), |s| s.close(None)) |
|
|
|
Ok(()) => Poll::Ready(Ok(())), |
|
|
|
}; |
|
|
|
Err(::tungstenite::Error::ConnectionClosed) => Poll::Ready(Ok(())), |
|
|
|
|
|
|
|
Err(::tungstenite::Error::Io(err)) |
|
|
|
match res { |
|
|
|
if err.kind() == std::io::ErrorKind::WouldBlock => |
|
|
|
Ok(()) => Poll::Ready(Ok(())), |
|
|
|
{ |
|
|
|
Err(::tungstenite::Error::ConnectionClosed) => Poll::Ready(Ok(())), |
|
|
|
trace!("WouldBlock"); |
|
|
|
Err(::tungstenite::Error::Io(err)) if err.kind() == std::io::ErrorKind::WouldBlock => { |
|
|
|
self.closing = true; |
|
|
|
trace!("WouldBlock"); |
|
|
|
Poll::Pending |
|
|
|
self.closing = true; |
|
|
|
} |
|
|
|
Poll::Pending |
|
|
|
Err(err) => { |
|
|
|
} |
|
|
|
debug!("websocket close error: {}", err); |
|
|
|
Err(err) => { |
|
|
|
Poll::Ready(Err(err)) |
|
|
|
debug!("websocket close error: {}", err); |
|
|
|
} |
|
|
|
Poll::Ready(Err(err)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|