From d9f4d3f0eabd3767b4d25438319116f77c158c52 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Tue, 8 Dec 2009 18:46:59 +0100 Subject: [PATCH] Improve handling of disconnections a bit Also make the sigproxy send pings again even if we don't want to ping timeout, as they're also used for lag measuring. --- src/client/coreconnection.cpp | 63 +++++++++++++++++------------------ src/client/coreconnection.h | 2 +- src/common/signalproxy.cpp | 11 ++---- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/client/coreconnection.cpp b/src/client/coreconnection.cpp index d20e434d..59d3f8ff 100644 --- a/src/client/coreconnection.cpp +++ b/src/client/coreconnection.cpp @@ -102,35 +102,6 @@ void CoreConnection::updateProgress(int value, int max) { setProgressValue(value); } -void CoreConnection::resetConnection(bool wantReconnect) { - _wantReconnect = wantReconnect; - - if(_socket) { - disconnect(_socket, 0, this, 0); - _socket->deleteLater(); - _socket = 0; - } - _blockSize = 0; - - _coreMsgBuffer.clear(); - - _netsToSync.clear(); - _numNetsToSync = 0; - - setProgressMaximum(-1); // disable - setState(Disconnected); - - emit connectionMsg(tr("Disconnected from core.")); - emit encrypted(false); - - // initiate if a reconnect if appropriate - CoreConnectionSettings s; - if(wantReconnect && s.autoReconnect()) { - _reconnectTimer.start(); - //reconnectToCore(); - } -} - void CoreConnection::reconnectTimeout() { if(!_socket) { CoreConnectionSettings s; @@ -283,7 +254,6 @@ void CoreConnection::coreSocketError(QAbstractSocket::SocketError) { } void CoreConnection::coreSocketDisconnected() { - emit disconnected(); qDebug() << Q_FUNC_INFO; resetConnection(true); // FIXME handle disconnects gracefully @@ -349,6 +319,34 @@ void CoreConnection::disconnectFromCore(const QString &errorString, bool wantRec resetConnection(wantReconnect); } +void CoreConnection::resetConnection(bool wantReconnect) { + _wantReconnect = wantReconnect; + + if(_socket) { + disconnect(_socket, 0, this, 0); + _socket->deleteLater(); + _socket = 0; + } + _blockSize = 0; + + _coreMsgBuffer.clear(); + + _netsToSync.clear(); + _numNetsToSync = 0; + + setProgressMaximum(-1); // disable + setState(Disconnected); + + emit connectionMsg(tr("Disconnected from core.")); + emit encrypted(false); + + // initiate if a reconnect if appropriate + CoreConnectionSettings s; + if(wantReconnect && s.autoReconnect()) { + _reconnectTimer.start(); + } +} + void CoreConnection::reconnectToCore() { if(currentAccount().isValid()) connectToCore(currentAccount().accountId()); @@ -670,8 +668,9 @@ void CoreConnection::syncToCore(const QVariantMap &sessionState) { checkSyncState(); } +// this is also called for destroyed networks! void CoreConnection::networkInitDone() { - Network *net = qobject_cast(sender()); + QObject *net = sender(); Q_ASSERT(net); disconnect(net, 0, this, 0); _netsToSync.remove(net); @@ -680,7 +679,7 @@ void CoreConnection::networkInitDone() { } void CoreConnection::checkSyncState() { - if(_netsToSync.isEmpty()) { + if(_netsToSync.isEmpty() && state() >= Synchronizing) { setState(Synchronized); setProgressText(tr("Synchronized to %1").arg(currentAccount().accountName())); setProgressMaximum(-1); diff --git a/src/client/coreconnection.h b/src/client/coreconnection.h index 6a3f37bf..a06a8101 100644 --- a/src/client/coreconnection.h +++ b/src/client/coreconnection.h @@ -175,7 +175,7 @@ private: QTimer _reconnectTimer; bool _wantReconnect; - QSet _netsToSync; + QSet _netsToSync; int _numNetsToSync; int _progressMinimum, _progressMaximum, _progressValue; QString _progressText; diff --git a/src/common/signalproxy.cpp b/src/common/signalproxy.cpp index b3410e64..e7c641b4 100644 --- a/src/common/signalproxy.cpp +++ b/src/common/signalproxy.cpp @@ -275,6 +275,7 @@ void SignalProxy::init() { connect(&_heartBeatTimer, SIGNAL(timeout()), this, SLOT(sendHeartBeat())); setHeartBeatInterval(30); setMaxHeartBeatCount(2); + _heartBeatTimer.start(); _secure = false; updateSecureState(); } @@ -333,13 +334,7 @@ void SignalProxy::setHeartBeatInterval(int secs) { } void SignalProxy::setMaxHeartBeatCount(int max) { - if(max < 0) - _heartBeatTimer.stop(); - else { - _maxHeartBeatCount = max; - if(!_heartBeatTimer.isActive()) - _heartBeatTimer.start(); - } + _maxHeartBeatCount = max; } bool SignalProxy::addPeer(SignalProxy* proxy) { @@ -960,7 +955,7 @@ void SignalProxy::sendHeartBeat() { if(ioPeer->sentHeartBeats > 0) { updateLag(ioPeer, ioPeer->sentHeartBeats * _heartBeatTimer.interval()); } - if(ioPeer->sentHeartBeats >= maxHeartBeatCount()) + if(maxHeartBeatCount() >= 0 && ioPeer->sentHeartBeats >= maxHeartBeatCount()) toClose.append(ioPeer); else ioPeer->sentHeartBeats++; -- 2.20.1