chatgui: rework shutdown — main thread owns cleanup, remove glШбаls

Changes:
- UtunNode::requestStop() — async stop from any thread (m_stop+wakeup)
- UtunNode::finalize() — cleanup in main thread (etcp_router, chat_sync, chat_core, utun_instance, uasync)
- UtunNode::stop() — requestStop + join + finalize (for tray Quit path)
- Worker runLoop: only exits poll loop on m_stop, then emits stopped — no cleanup
- stopped() handler: calls finalize() in main thread, then qApp->quit()
- Tray Quit: calls requestStop(), stopped handler does finalize+quit
- Ctrl-C (Windows): SetConsoleCtrlHandler calls requestStop() via g_ctrl_node
- Ctrl-C (Linux): signal_handler calls requestStop() via g_currentNode
- Removed: g_shutdown, g_signal_ua, utun_node_signal_shutdown globals
This commit is contained in:
Evgeny committed 2026-07-24 14:14:27 +03:00
1 parent 4c623e25ce
commit fbaf58530f
5 files changed
+41 -32

No files matched your search

+4 -2
View File
@@ -9,13 +9,14 @@
#include "mainwindow.h"
#include "../db/db_manager.h"
#include "../transport/node_config.h"
#include "../transport/utun_node.h"
#ifdef _WIN32
extern "C" void utun_node_signal_shutdown(void);
static UtunNode* g_ctrl_node = nullptr;
static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType) {
if (dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT) {
utun_node_signal_shutdown();
if (g_ctrl_node) g_ctrl_node->requestStop();
return TRUE;
}
return FALSE;
@@ -92,6 +93,7 @@ int main(int argc, char *argv[]) {
w.show();
#ifdef _WIN32
g_ctrl_node = w.utunNode();
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
#endif