]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
websocket: cleanup before quit
authortobtoht <tob@featherwallet.org>
Tue, 1 Oct 2024 14:36:47 +0000 (16:36 +0200)
committertobtoht <tob@featherwallet.org>
Tue, 1 Oct 2024 14:36:47 +0000 (16:36 +0200)
src/utils/WebsocketClient.cpp
src/utils/WebsocketNotifier.cpp
src/utils/WebsocketNotifier.h

index 63f0e1da165fb3db3eb4635366d158e03b13de2c..85b60309aefb75ca6f74a0bfa60df882d1c19a9b 100644 (file)
@@ -12,6 +12,8 @@ WebsocketClient::WebsocketClient(QObject *parent)
     : QObject(parent)
     , webSocket(new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this))
 {
+    connect(qApp, &QCoreApplication::aboutToQuit, this, &WebsocketClient::stop);
+
     connect(webSocket, &QWebSocket::stateChanged, this, &WebsocketClient::onStateChanged);
     connect(webSocket, &QWebSocket::connected, this, &WebsocketClient::onConnected);
     connect(webSocket, &QWebSocket::disconnected, this, &WebsocketClient::onDisconnected);
@@ -26,7 +28,6 @@ WebsocketClient::WebsocketClient(QObject *parent)
         }
     });
     m_pingTimer.setInterval(30 * 1000);
-    m_pingTimer.start();
 
     connect(&m_connectionTimeout, &QTimer::timeout, this, &WebsocketClient::onConnectionTimeout);
 
@@ -67,9 +68,11 @@ void WebsocketClient::restart() {
 }
 
 void WebsocketClient::stop() {
+    qDebug() << Q_FUNC_INFO;
     m_stopped = true;
     webSocket->close();
     m_connectionTimeout.stop();
+    m_pingTimer.stop();
 }
 
 void WebsocketClient::onConnected() {
@@ -89,6 +92,7 @@ void WebsocketClient::onStateChanged(QAbstractSocket::SocketState state) {
     }
     else if (state == QAbstractSocket::ConnectedState) {
         m_connectionTimeout.stop();
+        m_pingTimer.start();
     }
 }
 
index 75666ccec210ea2d3cb2e6af6b684f71759ae216..b3fbc2275f1ab849ee00e69fbb69fb6f9b4dbcd7 100644 (file)
@@ -116,4 +116,8 @@ WebsocketNotifier* WebsocketNotifier::instance()
     }
 
     return m_instance;
-}
\ No newline at end of file
+}
+
+WebsocketNotifier::~WebsocketNotifier() {
+    qDebug() << "~WebsocketNotifier" << QThread::currentThreadId();
+}
index ea163fb432e7385a7884001dce4b81ad14cbae4a..f2ee464eabf44a11e2b9c071f210843b5114c067 100644 (file)
@@ -18,6 +18,7 @@ class WebsocketNotifier : public QObject {
 
 public:
     explicit WebsocketNotifier(QObject *parent);
+    ~WebsocketNotifier();
 
     QMap<NetworkType::Type, int> heights;
     WebsocketClient *websocketClient;