mirror of
https://github.com/feather-wallet/feather.git
synced 2025-03-12 09:37:47 +00:00
websocket: cleanup before quit
This commit is contained in:
parent
c31b351b17
commit
a1836a64b2
3 changed files with 11 additions and 2 deletions
|
@ -12,6 +12,8 @@ WebsocketClient::WebsocketClient(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, webSocket(new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this))
|
, webSocket(new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this))
|
||||||
{
|
{
|
||||||
|
connect(qApp, &QCoreApplication::aboutToQuit, this, &WebsocketClient::stop);
|
||||||
|
|
||||||
connect(webSocket, &QWebSocket::stateChanged, this, &WebsocketClient::onStateChanged);
|
connect(webSocket, &QWebSocket::stateChanged, this, &WebsocketClient::onStateChanged);
|
||||||
connect(webSocket, &QWebSocket::connected, this, &WebsocketClient::onConnected);
|
connect(webSocket, &QWebSocket::connected, this, &WebsocketClient::onConnected);
|
||||||
connect(webSocket, &QWebSocket::disconnected, this, &WebsocketClient::onDisconnected);
|
connect(webSocket, &QWebSocket::disconnected, this, &WebsocketClient::onDisconnected);
|
||||||
|
@ -26,7 +28,6 @@ WebsocketClient::WebsocketClient(QObject *parent)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
m_pingTimer.setInterval(30 * 1000);
|
m_pingTimer.setInterval(30 * 1000);
|
||||||
m_pingTimer.start();
|
|
||||||
|
|
||||||
connect(&m_connectionTimeout, &QTimer::timeout, this, &WebsocketClient::onConnectionTimeout);
|
connect(&m_connectionTimeout, &QTimer::timeout, this, &WebsocketClient::onConnectionTimeout);
|
||||||
|
|
||||||
|
@ -67,9 +68,11 @@ void WebsocketClient::restart() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebsocketClient::stop() {
|
void WebsocketClient::stop() {
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
m_stopped = true;
|
m_stopped = true;
|
||||||
webSocket->close();
|
webSocket->close();
|
||||||
m_connectionTimeout.stop();
|
m_connectionTimeout.stop();
|
||||||
|
m_pingTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebsocketClient::onConnected() {
|
void WebsocketClient::onConnected() {
|
||||||
|
@ -89,6 +92,7 @@ void WebsocketClient::onStateChanged(QAbstractSocket::SocketState state) {
|
||||||
}
|
}
|
||||||
else if (state == QAbstractSocket::ConnectedState) {
|
else if (state == QAbstractSocket::ConnectedState) {
|
||||||
m_connectionTimeout.stop();
|
m_connectionTimeout.stop();
|
||||||
|
m_pingTimer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,3 +117,7 @@ WebsocketNotifier* WebsocketNotifier::instance()
|
||||||
|
|
||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebsocketNotifier::~WebsocketNotifier() {
|
||||||
|
qDebug() << "~WebsocketNotifier" << QThread::currentThreadId();
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ class WebsocketNotifier : public QObject {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WebsocketNotifier(QObject *parent);
|
explicit WebsocketNotifier(QObject *parent);
|
||||||
|
~WebsocketNotifier();
|
||||||
|
|
||||||
QMap<NetworkType::Type, int> heights;
|
QMap<NetworkType::Type, int> heights;
|
||||||
WebsocketClient *websocketClient;
|
WebsocketClient *websocketClient;
|
||||||
|
|
Loading…
Reference in a new issue