From 7f67a00ab2d45400e377e3f8e60db55c2c82a9fb Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 1 Nov 2023 16:05:54 -0400 Subject: [PATCH] clean up close ordering --- .../src/network_manager/native/protocol/ws.rs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/veilid-core/src/network_manager/native/protocol/ws.rs b/veilid-core/src/network_manager/native/protocol/ws.rs index 27e6a0fc..57d8a79d 100644 --- a/veilid-core/src/network_manager/native/protocol/ws.rs +++ b/veilid-core/src/network_manager/native/protocol/ws.rs @@ -40,7 +40,8 @@ fn err_to_network_result(err: Error) -> NetworkResult { Error::ConnectionClosed | Error::AlreadyClosed | Error::Io(_) - | Error::Protocol(ProtocolError::ResetWithoutClosingHandshake) => { + | Error::Protocol(ProtocolError::ResetWithoutClosingHandshake) + | Error::Protocol(ProtocolError::SendAfterClosing) => { NetworkResult::NoConnection(to_io_error_other(err)) } _ => NetworkResult::InvalidMessage(err.to_string()), @@ -88,23 +89,20 @@ where pub async fn close(&self) -> io::Result> { // Make an attempt to close the stream normally let mut stream = self.stream.clone(); - stream + let out = match stream .send(Message::Close(Some(CloseFrame { code: CloseCode::Normal, reason: "".into(), }))) .await - .map_err(to_io_error_other)?; - // match stream.flush().await { - // Ok(()) => Ok(NetworkResult::value(())), - // Err(Error::Io(ioerr)) => Err(ioerr).into_network_result(), - // Err(Error::ConnectionClosed) => Ok(NetworkResult::value(())), - // Err(e) => Err(to_io_error_other(e)), - // } + { + Ok(v) => NetworkResult::value(v), + Err(e) => err_to_network_result(e), + }; - stream.close().await.map_err(to_io_error_other)?; + let _ = stream.close().await; - Ok(NetworkResult::value(())) + Ok(out) // Drive connection to close /*