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