mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Debugger: Disconnect on shutdown/disable.
Although, it could be made safe to keep them up when restarting with debugging still enabled.
This commit is contained in:
parent
a2d82cb654
commit
6bec3db3fb
5 changed files with 37 additions and 1 deletions
|
@ -15,6 +15,8 @@
|
|||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include "thread/threadutil.h"
|
||||
#include "Core/Debugger/WebSocket.h"
|
||||
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
|
||||
|
@ -54,12 +56,25 @@ static const std::vector<SubscriberInfo> subscribers({
|
|||
{ &WebSocketCPUCoreInit, nullptr },
|
||||
});
|
||||
|
||||
// To handle webserver restart, keep track of how many running.
|
||||
static volatile int debuggersConnected = 0;
|
||||
static volatile bool stopRequested = false;
|
||||
static std::mutex stopLock;
|
||||
static std::condition_variable stopCond;
|
||||
|
||||
static void UpdateConnected(int delta) {
|
||||
std::lock_guard<std::mutex> guard(stopLock);
|
||||
debuggersConnected += delta;
|
||||
stopCond.notify_all();
|
||||
}
|
||||
|
||||
void HandleDebuggerRequest(const http::Request &request) {
|
||||
net::WebSocketServer *ws = net::WebSocketServer::CreateAsUpgrade(request, "debugger.ppsspp.org");
|
||||
if (!ws)
|
||||
return;
|
||||
|
||||
setCurrentThreadName("Debugger");
|
||||
UpdateConnected(1);
|
||||
|
||||
LogBroadcaster logger;
|
||||
GameBroadcaster game;
|
||||
|
@ -103,6 +118,10 @@ void HandleDebuggerRequest(const http::Request &request) {
|
|||
logger.Broadcast(ws);
|
||||
game.Broadcast(ws);
|
||||
stepping.Broadcast(ws);
|
||||
|
||||
if (stopRequested) {
|
||||
ws->Close(net::WebSocketClose::GOING_AWAY);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < subscribers.size(); ++i) {
|
||||
|
@ -114,4 +133,16 @@ void HandleDebuggerRequest(const http::Request &request) {
|
|||
}
|
||||
|
||||
delete ws;
|
||||
UpdateConnected(-1);
|
||||
}
|
||||
|
||||
void StopAllDebuggers() {
|
||||
std::unique_lock<std::mutex> guard(stopLock);
|
||||
while (debuggersConnected != 0) {
|
||||
stopRequested = true;
|
||||
stopCond.wait(guard);
|
||||
}
|
||||
|
||||
// Reset it back for next time.
|
||||
stopRequested = false;
|
||||
}
|
||||
|
|
|
@ -22,3 +22,5 @@ class Request;
|
|||
}
|
||||
|
||||
void HandleDebuggerRequest(const http::Request &request);
|
||||
// Note: blocks.
|
||||
void StopAllDebuggers();
|
||||
|
|
|
@ -216,6 +216,8 @@ static void ExecuteWebServer() {
|
|||
}
|
||||
|
||||
http->Stop();
|
||||
StopAllDebuggers();
|
||||
delete http;
|
||||
|
||||
// Move to STARTING to lock flags/STOPPING.
|
||||
if (UpdateStatus(ServerStatus::STARTING, ServerStatus::RESTARTING)) {
|
||||
|
|
|
@ -279,7 +279,7 @@ void Server::HandleConnection(int conn_fd) {
|
|||
WLOG("Bad request, ignoring.");
|
||||
return;
|
||||
}
|
||||
HandleRequestDefault(request);
|
||||
HandleRequest(request);
|
||||
|
||||
// TODO: Way to mark the content body as read, read it here if never read.
|
||||
// This allows the handler to stream if need be.
|
||||
|
|
|
@ -63,6 +63,7 @@ private:
|
|||
class Server {
|
||||
public:
|
||||
Server(threading::Executor *executor);
|
||||
virtual ~Server() {}
|
||||
|
||||
typedef std::function<void(const Request &)> UrlHandlerFunc;
|
||||
typedef std::map<std::string, UrlHandlerFunc> UrlHandlerMap;
|
||||
|
|
Loading…
Add table
Reference in a new issue