feat: resume on disconnect & add 'resumed' response

This commit is contained in:
MihailRis 2025-10-09 00:42:19 +03:00
parent f4c3b53cd1
commit a33e3068c8
2 changed files with 25 additions and 7 deletions

View File

@ -61,6 +61,10 @@ void ClientConnection::sendResponse(const std::string& type) {
send(dv::object({{"type", type}})); send(dv::object({{"type", type}}));
} }
bool ClientConnection::alive() const {
return network.getConnection(this->connection, true) != nullptr;
}
static network::Server& create_tcp_server( static network::Server& create_tcp_server(
DebuggingServer& dbgServer, Engine& engine, int port DebuggingServer& dbgServer, Engine& engine, int port
) { ) {
@ -134,6 +138,10 @@ bool DebuggingServer::update() {
} }
std::string message = connection->read(); std::string message = connection->read();
if (message.empty()) { if (message.empty()) {
if (!connection->alive()) {
connection.reset();
return true;
}
return false; return false;
} }
logger.debug() << "received: " << message; logger.debug() << "received: " << message;
@ -144,7 +152,10 @@ bool DebuggingServer::update() {
return false; return false;
} }
const auto& type = obj["type"].asString(); const auto& type = obj["type"].asString();
return performCommand(type, obj); if (performCommand(type, obj)) {
connection->sendResponse("resumed");
return true;
}
} catch (const std::runtime_error& err) { } catch (const std::runtime_error& err) {
logger.error() << "could not to parse message: " << err.what(); logger.error() << "could not to parse message: " << err.what();
} }
@ -219,12 +230,17 @@ void DebuggingServer::pause(
if (connection == nullptr) { if (connection == nullptr) {
return; return;
} }
connection->send(dv::object({ auto response = dv::object({{"type", std::string("paused")}});
{"type", std::string("paused")}, if (!reason.empty()) {
{"reason", std::move(reason)}, response["reason"] = std::move(reason);
{"message", std::move(message)}, }
{"stack", std::move(stackTrace)} if (!message.empty()) {
})); response["message"] = std::move(message);
}
if (stackTrace != nullptr) {
response["stack"] = std::move(stackTrace);
}
connection->send(std::move(response));
engine.startPauseLoop(); engine.startPauseLoop();
} }

View File

@ -31,6 +31,8 @@ namespace devtools {
std::string read(); std::string read();
void send(const dv::value& message); void send(const dv::value& message);
void sendResponse(const std::string& type); void sendResponse(const std::string& type);
bool alive() const;
private: private:
network::Network& network; network::Network& network;
size_t messageLength = 0; size_t messageLength = 0;