Skip to content
Permalink
Browse files

Connectivity: Improve reconnecting after network change/disconnect #4167

  • Loading branch information...
guruz committed Nov 23, 2015
1 parent 33dcb0c commit b52a3a415c3dbb4cb5d20d8a93d39817fe05856e
@@ -177,11 +177,15 @@ Application::Application(int &argc, char **argv) :

// startup procedure.
connect(&_checkConnectionTimer, SIGNAL(timeout()), this, SLOT(slotCheckConnection()));
_checkConnectionTimer.setInterval(32 * 1000); // check for connection every 32 seconds.
_checkConnectionTimer.setInterval(ConnectionValidator::defaultCallingIntervalMsec()); // check for connection every 32 seconds.
_checkConnectionTimer.start();
// Also check immediately
QTimer::singleShot( 0, this, SLOT( slotCheckConnection() ));

// Can't use onlineStateChanged because it is always true on modern systems because of many interfaces
connect(&_networkConfigurationManager, SIGNAL(configurationChanged(QNetworkConfiguration)),
this, SLOT(slotSystemOnlineConfigurationChanged(QNetworkConfiguration)));

// Update checks
UpdaterScheduler *updaterScheduler = new UpdaterScheduler(this);
connect(updaterScheduler, SIGNAL(updaterAnnouncement(QString, QString)),
@@ -234,6 +238,17 @@ void Application::slotCleanup()
_gui->deleteLater();
}

// FIXME: This is not ideal yet since a ConnectionValidator might already be running and is in
// progress of timing out in some seconds.
// Maybe we need 2 validators, one triggered by timer, one by network configuration changes?
void Application::slotSystemOnlineConfigurationChanged(QNetworkConfiguration cnf)
{
if (cnf.state() & QNetworkConfiguration::Active) {
//qDebug() << "Trying fast reconnect";
QMetaObject::invokeMethod(this, "slotCheckConnection", Qt::QueuedConnection);
}
}

void Application::slotCheckConnection()
{
auto list = AccountManager::instance()->accounts();
@@ -20,6 +20,7 @@
#include <QQueue>
#include <QTimer>
#include <QElapsedTimer>
#include <QNetworkConfigurationManager>

#include "qtsingleapplication.h"

@@ -87,6 +88,7 @@ protected slots:
void slotAccountStateAdded(AccountState *accountState);
void slotAccountStateRemoved(AccountState *accountState);
void slotCrash();
void slotSystemOnlineConfigurationChanged(QNetworkConfiguration);

private:
void setHelp();
@@ -111,6 +113,7 @@ protected slots:

ClientProxy _proxy;

QNetworkConfigurationManager _networkConfigurationManager;
QTimer _checkConnectionTimer;

#if defined(WITH_CRASHREPORTER)
@@ -57,6 +57,8 @@ class OWNCLOUDSYNC_EXPORT AbstractNetworkJob : public QObject {
QByteArray responseTimestamp();
quint64 duration();

qint64 timeoutMsec() { return _timer.interval(); }

This comment has been minimized.

Copy link
@ckamm

ckamm Nov 24, 2015

Member

minor: could be const


public slots:
void setTimeout(qint64 msec);
void resetTimeout();
@@ -23,6 +23,10 @@

namespace OCC {

// Make sure the timeout for this job is less than how often we get called
// This makes sure we get tried often enough without "ConnectionValidator already running"
static qint64 timeoutToUseMsec = qMax(qint64(1000), ConnectionValidator::defaultCallingIntervalMsec() - 5*1000);

ConnectionValidator::ConnectionValidator(AccountPtr account, QObject *parent)
: QObject(parent),
_account(account),
@@ -99,6 +103,7 @@ void ConnectionValidator::systemProxyLookupDone(const QNetworkProxy &proxy) {
void ConnectionValidator::slotCheckServerAndAuth()
{
CheckServerJob *checkJob = new CheckServerJob(_account, this);
checkJob->setTimeout(timeoutToUseMsec);
checkJob->setIgnoreCredentialFailure(true);
connect(checkJob, SIGNAL(instanceFound(QUrl,QVariantMap)), SLOT(slotStatusFound(QUrl,QVariantMap)));
connect(checkJob, SIGNAL(networkError(QNetworkReply*)), SLOT(slotNoStatusFound(QNetworkReply*)));
@@ -165,6 +170,7 @@ void ConnectionValidator::checkAuthentication()
// continue in slotAuthCheck here :-)
qDebug() << "# Check whether authenticated propfind works.";
PropfindJob *job = new PropfindJob(_account, "/", this);
job->setTimeout(timeoutToUseMsec);
job->setProperties(QList<QByteArray>() << "getlastmodified");
connect(job, SIGNAL(result(QVariantMap)), SLOT(slotAuthSuccess()));
connect(job, SIGNAL(networkError(QNetworkReply*)), SLOT(slotAuthFailed(QNetworkReply*)));
@@ -84,6 +84,9 @@ class OWNCLOUDSYNC_EXPORT ConnectionValidator : public QObject

static QString statusString( Status );

// How often should the Application ask this object to check for the connection?
static qint64 defaultCallingIntervalMsec() { return 32 * 1000;}

public slots:
/// Checks the server and the authentication.
void checkServerAndAuth();

2 comments on commit b52a3a4

@guruz

This comment has been minimized.

Copy link
Collaborator Author

replied Nov 23, 2015

@ckamm

This comment has been minimized.

Copy link
Member

replied Nov 24, 2015

+1

Please sign in to comment.
You can’t perform that action at this time.