From 24e724a824dc7e037adc9e372786d510cba4e373 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 00:26:26 -0700 Subject: [PATCH] Hopefully prevent close socket race condition --- source/server/SocketBase.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/server/SocketBase.cpp b/source/server/SocketBase.cpp index 4f82d95..b9c408a 100644 --- a/source/server/SocketBase.cpp +++ b/source/server/SocketBase.cpp @@ -72,12 +72,13 @@ s32 SocketBase::getFd() { bool SocketBase::closeSocket() { - this->socket_log_state = SOCKET_LOG_DISCONNECTED; // probably not safe to assume socket will be closed + if (this->socket_log_state != SOCKET_LOG_DISCONNECTED) { + nn::Result result = nn::socket::Close(this->socket_log_socket); + if (result.isSuccess()) { + this->socket_log_state = SOCKET_LOG_DISCONNECTED; + } + return result.isSuccess(); + } - nn::Result result = nn::socket::Close(this->socket_log_socket); - - return result.isSuccess(); + return true; } - - -