Gracefully handle debugger accept thread already running
This commit is contained in:
parent
fbfdfc8914
commit
6bb5b002e0
|
@ -58,7 +58,8 @@ Breakpoint::~Breakpoint() = default;
|
|||
Debugger::Debugger(Emulator* emulator)
|
||||
: emulator_(emulator),
|
||||
listen_socket_(INVALID_SOCKET),
|
||||
client_socket_(INVALID_SOCKET) {
|
||||
client_socket_(INVALID_SOCKET),
|
||||
accept_thread_running_(false) {
|
||||
WSADATA wsa_data;
|
||||
WSAStartup(MAKEWORD(2, 2), &wsa_data);
|
||||
}
|
||||
|
@ -134,6 +135,8 @@ void SendResponse(SOCKET client_socket, flatbuffers::FlatBufferBuilder& fbb,
|
|||
}
|
||||
|
||||
void Debugger::PreLaunch() {
|
||||
if (!accept_thread_running_) {
|
||||
accept_thread_running_ = true;
|
||||
accept_thread_ = std::thread([this]() {
|
||||
xe::threading::set_name("Debugger Server");
|
||||
|
||||
|
@ -176,8 +179,8 @@ void Debugger::PreLaunch() {
|
|||
|
||||
// Read body.
|
||||
std::vector<uint8_t> body(length);
|
||||
r = recv(client_socket_, reinterpret_cast<char*>(body.data()), length,
|
||||
MSG_WAITALL);
|
||||
r = recv(client_socket_, reinterpret_cast<char*>(body.data()),
|
||||
length, MSG_WAITALL);
|
||||
if (r != length) {
|
||||
// Failed?
|
||||
XELOGE("Failed to recv debug data body - dead connection?");
|
||||
|
@ -195,6 +198,7 @@ void Debugger::PreLaunch() {
|
|||
// This will WaitForClient if it was waiting.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (FLAGS_wait_for_debugger) {
|
||||
// Wait for the first client.
|
||||
|
|
|
@ -111,6 +111,7 @@ class Debugger {
|
|||
Emulator* emulator_;
|
||||
|
||||
uintptr_t listen_socket_;
|
||||
bool accept_thread_running_;
|
||||
std::thread accept_thread_;
|
||||
xe::threading::Fence accept_fence_;
|
||||
uintptr_t client_socket_;
|
||||
|
|
Loading…
Reference in New Issue