Relatively graceful shutdowns

This commit is contained in:
2025-11-09 01:35:19 +01:00
parent 5312c4205c
commit 098afeb4d8
11 changed files with 154 additions and 30 deletions

View File

@@ -69,9 +69,11 @@ namespace ColumnLynx::Net::TCP {
}
}
void disconnect() {
void disconnect(bool echo = true) {
if (mConnected && mHandler) {
mHandler->sendMessage(ClientMessageType::GRACEFUL_DISCONNECT, "Goodbye");
if (echo) {
mHandler->sendMessage(ClientMessageType::GRACEFUL_DISCONNECT, "Goodbye");
}
asio::error_code ec;
@@ -94,6 +96,10 @@ namespace ColumnLynx::Net::TCP {
return mHandshakeComplete;
}
bool isConnected() const {
return mConnected;
}
private:
void mHandleMessage(ServerMessageType type, const std::string& data) {
switch (type) {
@@ -187,7 +193,7 @@ namespace ColumnLynx::Net::TCP {
case ServerMessageType::GRACEFUL_DISCONNECT:
Utils::log("Server is disconnecting: " + data);
if (mConnected) { // Prevent Recursion
disconnect();
disconnect(false);
}
break;
default: