From 5f7872885d7b12be9d2db9a3c12ad7486e83174d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2019 13:14:49 -0700 Subject: [PATCH] http: Remove web server restart handling. Now it serves the response dynamically, so it doesn't need to restart. --- Core/WebServer.cpp | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/Core/WebServer.cpp b/Core/WebServer.cpp index 7a239ffadcdc..3bec6d622a6a 100644 --- a/Core/WebServer.cpp +++ b/Core/WebServer.cpp @@ -37,7 +37,6 @@ enum class ServerStatus { STARTING, RUNNING, STOPPING, - RESTARTING, }; static const char *REPORT_HOSTNAME = "report.ppsspp.org"; @@ -53,15 +52,6 @@ static void UpdateStatus(ServerStatus s) { serverStatus = s; } -static bool UpdateStatus(ServerStatus s, ServerStatus old) { - std::lock_guard guard(serverStatusLock); - if (serverStatus == old) { - serverStatus = s; - return true; - } - return false; -} - static ServerStatus RetrieveStatus() { std::lock_guard guard(serverStatusLock); return serverStatus; @@ -225,14 +215,17 @@ static void HandleListing(const http::Request &request) { } static void HandleFallback(const http::Request &request) { - std::string filename = LocalFromRemotePath(request.resource()); - if (!filename.empty()) { - DiscHandler(request, filename); - } else { - static const std::string payload = "404 not found\r\n"; - request.WriteHttpResponseHeader("1.0", 404, (int)payload.size(), "text/plain"); - request.Out()->Push(payload); + if (serverFlags & (int)WebServerFlags::DISCS) { + std::string filename = LocalFromRemotePath(request.resource()); + if (!filename.empty()) { + DiscHandler(request, filename); + return; + } } + + static const std::string payload = "404 not found\r\n"; + request.WriteHttpResponseHeader("1.0", 404, (int)payload.size(), "text/plain"); + request.Out()->Push(payload); } static void ForwardDebuggerRequest(const http::Request &request) { @@ -278,24 +271,16 @@ static void ExecuteWebServer() { StopAllDebuggers(); delete http; - // Move to STARTING to lock flags/STOPPING. - if (UpdateStatus(ServerStatus::STARTING, ServerStatus::RESTARTING)) { - ExecuteWebServer(); - } else { - UpdateStatus(ServerStatus::STOPPED); - } + UpdateStatus(ServerStatus::STOPPED); } bool StartWebServer(WebServerFlags flags) { std::lock_guard guard(serverStatusLock); switch (serverStatus) { case ServerStatus::RUNNING: - case ServerStatus::RESTARTING: if ((serverFlags & (int)flags) == (int)flags) { - // Already running those flags. return false; } - serverStatus = ServerStatus::RESTARTING; serverFlags |= (int)flags; return true; @@ -313,24 +298,19 @@ bool StartWebServer(WebServerFlags flags) { bool StopWebServer(WebServerFlags flags) { std::lock_guard guard(serverStatusLock); - if (serverStatus != ServerStatus::RUNNING && serverStatus != ServerStatus::RESTARTING) { + if (serverStatus != ServerStatus::RUNNING) { return false; } serverFlags &= ~(int)flags; if (serverFlags == 0) { serverStatus = ServerStatus::STOPPING; - } else { - serverStatus = ServerStatus::RESTARTING; } return true; } bool WebServerStopping(WebServerFlags flags) { std::lock_guard guard(serverStatusLock); - if (serverStatus == ServerStatus::RESTARTING) { - return (serverFlags & (int)flags) == 0; - } return serverStatus == ServerStatus::STOPPING; }