clean up close ordering

This commit is contained in:
John Smith 2023-11-01 16:05:54 -04:00 committed by Christien Rioux
parent 520d8c43f7
commit 7f67a00ab2

View File

@ -40,7 +40,8 @@ fn err_to_network_result<T>(err: Error) -> NetworkResult<T> {
Error::ConnectionClosed Error::ConnectionClosed
| Error::AlreadyClosed | Error::AlreadyClosed
| Error::Io(_) | Error::Io(_)
| Error::Protocol(ProtocolError::ResetWithoutClosingHandshake) => { | Error::Protocol(ProtocolError::ResetWithoutClosingHandshake)
| Error::Protocol(ProtocolError::SendAfterClosing) => {
NetworkResult::NoConnection(to_io_error_other(err)) NetworkResult::NoConnection(to_io_error_other(err))
} }
_ => NetworkResult::InvalidMessage(err.to_string()), _ => NetworkResult::InvalidMessage(err.to_string()),
@ -88,23 +89,20 @@ where
pub async fn close(&self) -> io::Result<NetworkResult<()>> { pub async fn close(&self) -> io::Result<NetworkResult<()>> {
// Make an attempt to close the stream normally // Make an attempt to close the stream normally
let mut stream = self.stream.clone(); let mut stream = self.stream.clone();
stream let out = match stream
.send(Message::Close(Some(CloseFrame { .send(Message::Close(Some(CloseFrame {
code: CloseCode::Normal, code: CloseCode::Normal,
reason: "".into(), reason: "".into(),
}))) })))
.await .await
.map_err(to_io_error_other)?; {
// match stream.flush().await { Ok(v) => NetworkResult::value(v),
// Ok(()) => Ok(NetworkResult::value(())), Err(e) => err_to_network_result(e),
// Err(Error::Io(ioerr)) => Err(ioerr).into_network_result(), };
// Err(Error::ConnectionClosed) => Ok(NetworkResult::value(())),
// Err(e) => Err(to_io_error_other(e)),
// }
stream.close().await.map_err(to_io_error_other)?; let _ = stream.close().await;
Ok(NetworkResult::value(())) Ok(out)
// Drive connection to close // Drive connection to close
/* /*