Simplify and fix (re)connection logic
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 8 Apr 2013 22:08:12 +0000 (00:08 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 8 Apr 2013 22:08:12 +0000 (00:08 +0200)
Still a mess, but the refactor is right around the corner anyway. Now at
least Quassel should no longer reconnect automagically if disconnected
explicitly.

src/client/coreconnection.cpp
src/client/coreconnection.h

index fb553fe..ab42b74 100644 (file)
@@ -42,11 +42,10 @@ CoreConnection::CoreConnection(CoreAccountModel *model, QObject *parent)
     _model(model),
     _state(Disconnected),
     _wantReconnect(false),
     _model(model),
     _state(Disconnected),
     _wantReconnect(false),
+    _wasReconnect(false),
     _progressMinimum(0),
     _progressMaximum(-1),
     _progressValue(-1),
     _progressMinimum(0),
     _progressMaximum(-1),
     _progressValue(-1),
-    _wasReconnect(false),
-    _requestedDisconnect(false),
     _resetting(false)
 {
     qRegisterMetaType<ConnectionState>("CoreConnection::ConnectionState");
     _resetting(false)
 {
     qRegisterMetaType<ConnectionState>("CoreConnection::ConnectionState");
@@ -56,7 +55,6 @@ CoreConnection::CoreConnection(CoreAccountModel *model, QObject *parent)
 void CoreConnection::init()
 {
     Client::signalProxy()->setHeartBeatInterval(30);
 void CoreConnection::init()
 {
     Client::signalProxy()->setHeartBeatInterval(30);
-    connect(Client::signalProxy(), SIGNAL(disconnected()), SLOT(coreSocketDisconnected()));
     connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), SIGNAL(lagUpdated(int)));
 
     _reconnectTimer.setSingleShot(true);
     connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), SIGNAL(lagUpdated(int)));
 
     _reconnectTimer.setSingleShot(true);
@@ -289,8 +287,8 @@ void CoreConnection::coreSocketError(QAbstractSocket::SocketError)
 
 void CoreConnection::coreSocketDisconnected()
 {
 
 void CoreConnection::coreSocketDisconnected()
 {
-    _wasReconnect = !_requestedDisconnect;
-    resetConnection(true);
+    _wasReconnect = false;
+    resetConnection(_wantReconnect);
     // FIXME handle disconnects gracefully
 }
 
     // FIXME handle disconnects gracefully
 }
 
@@ -347,10 +345,8 @@ void CoreConnection::coreHasData(const QVariant &item)
 
 void CoreConnection::disconnectFromCore()
 {
 
 void CoreConnection::disconnectFromCore()
 {
-    if (_socket) {
-        _requestedDisconnect = true;
+    if (_socket)
         disconnectFromCore(QString(), false); // requested disconnect, so don't try to reconnect
         disconnectFromCore(QString(), false); // requested disconnect, so don't try to reconnect
-    }
 }
 
 
 }
 
 
@@ -359,9 +355,11 @@ void CoreConnection::disconnectFromCore(const QString &errorString, bool wantRec
     if (!wantReconnect)
         _reconnectTimer.stop();
 
     if (!wantReconnect)
         _reconnectTimer.stop();
 
-    _wasReconnect = wantReconnect; // store if disconnect was requested
+    _wantReconnect = wantReconnect; // store if disconnect was requested
+    _wasReconnect = false;
 
 
-    resetConnection(wantReconnect);
+    if (_socket)
+        _socket->close();
 
     if (errorString.isEmpty())
         emit connectionError(tr("Disconnected"));
 
     if (errorString.isEmpty())
         emit connectionError(tr("Disconnected"));
@@ -394,8 +392,6 @@ void CoreConnection::resetConnection(bool wantReconnect)
         _socket = 0;
     }
 
         _socket = 0;
     }
 
-    _requestedDisconnect = false;
-
     _coreMsgBuffer.clear();
     _netsToSync.clear();
     _numNetsToSync = 0;
     _coreMsgBuffer.clear();
     _netsToSync.clear();
     _numNetsToSync = 0;
@@ -419,8 +415,10 @@ void CoreConnection::resetConnection(bool wantReconnect)
 
 void CoreConnection::reconnectToCore()
 {
 
 void CoreConnection::reconnectToCore()
 {
-    if (currentAccount().isValid())
+    if (currentAccount().isValid()) {
+        _wasReconnect = true;
         connectToCore(currentAccount().accountId());
         connectToCore(currentAccount().accountId());
+    }
 }
 
 
 }
 
 
index 9ba9d6a..0bf402e 100644 (file)
@@ -182,6 +182,7 @@ private:
 
     QTimer _reconnectTimer;
     bool _wantReconnect;
 
     QTimer _reconnectTimer;
     bool _wantReconnect;
+    bool _wasReconnect;
 
     QSet<QObject *> _netsToSync;
     int _numNetsToSync;
 
     QSet<QObject *> _netsToSync;
     int _numNetsToSync;
@@ -189,8 +190,6 @@ private:
     QString _progressText;
 
     QString _coreInfoString(const QVariantMap &);
     QString _progressText;
 
     QString _coreInfoString(const QVariantMap &);
-    bool _wasReconnect;
-    bool _requestedDisconnect;
     bool _resetting;
 
     inline CoreAccountModel *accountModel() const;
     bool _resetting;
 
     inline CoreAccountModel *accountModel() const;