Skip to content

Commit

Permalink
http: Remove web server restart handling.
Browse files Browse the repository at this point in the history
Now it serves the response dynamically, so it doesn't need to restart.
  • Loading branch information
unknownbrackets committed Aug 25, 2019
1 parent b2005f8 commit 5f78728
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions Core/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ enum class ServerStatus {
STARTING,
RUNNING,
STOPPING,
RESTARTING,
};

static const char *REPORT_HOSTNAME = "report.ppsspp.org";
Expand All @@ -53,15 +52,6 @@ static void UpdateStatus(ServerStatus s) {
serverStatus = s;
}

static bool UpdateStatus(ServerStatus s, ServerStatus old) {
std::lock_guard<std::mutex> guard(serverStatusLock);
if (serverStatus == old) {
serverStatus = s;
return true;
}
return false;
}

static ServerStatus RetrieveStatus() {
std::lock_guard<std::mutex> guard(serverStatusLock);
return serverStatus;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<std::mutex> 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;

Expand All @@ -313,24 +298,19 @@ bool StartWebServer(WebServerFlags flags) {

bool StopWebServer(WebServerFlags flags) {
std::lock_guard<std::mutex> 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<std::mutex> guard(serverStatusLock);
if (serverStatus == ServerStatus::RESTARTING) {
return (serverFlags & (int)flags) == 0;
}
return serverStatus == ServerStatus::STOPPING;
}

Expand Down

0 comments on commit 5f78728

Please sign in to comment.