diff --git a/Core/WebServer.cpp b/Core/WebServer.cpp index 8ab773fd1f..eab106add0 100644 --- a/Core/WebServer.cpp +++ b/Core/WebServer.cpp @@ -37,6 +37,7 @@ enum class ServerStatus { STARTING, RUNNING, STOPPING, + FINISHED, }; static const char *REPORT_HOSTNAME = "report.ppsspp.org"; @@ -248,7 +249,7 @@ static void ExecuteWebServer() { if (!http->Listen(g_Config.iRemoteISOPort)) { if (!http->Listen(0)) { ERROR_LOG(FILESYS, "Unable to listen on any port"); - UpdateStatus(ServerStatus::STOPPED); + UpdateStatus(ServerStatus::FINISHED); return; } } @@ -271,7 +272,7 @@ static void ExecuteWebServer() { StopAllDebuggers(); delete http; - UpdateStatus(ServerStatus::STOPPED); + UpdateStatus(ServerStatus::FINISHED); } bool StartWebServer(WebServerFlags flags) { @@ -284,6 +285,9 @@ bool StartWebServer(WebServerFlags flags) { serverFlags |= (int)flags; return true; + case ServerStatus::FINISHED: + serverThread.join(); + // Intentional fallthrough. case ServerStatus::STOPPED: serverStatus = ServerStatus::STARTING; serverFlags = (int)flags; @@ -318,11 +322,13 @@ bool WebServerStopped(WebServerFlags flags) { if (serverStatus == ServerStatus::RUNNING) { return (serverFlags & (int)flags) == 0; } - return serverStatus == ServerStatus::STOPPED; + return serverStatus == ServerStatus::STOPPED || serverStatus == ServerStatus::FINISHED; } void ShutdownWebServer() { StopWebServer(WebServerFlags::ALL); - if (serverThread.joinable()) + + if (serverStatus != ServerStatus::STOPPED) serverThread.join(); + serverStatus = ServerStatus::STOPPED; }