From 57c14a0ebab56c322fe2b42e33e557cc42a70781 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 19 Mar 2015 11:40:47 +0100 Subject: [PATCH] Windows: Reset QNAM as a workaround. #2899 #2895 #2973 The QNetworkAccessManager is reset when we are disconnected, just before attempting to fetch the server's status.php. This may help fix the problem described in various issues where we get 'Connection closed' or timeout errors after the OS has woken from sleep. --- src/gui/accountstate.cpp | 9 +++++++++ src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 1 + 3 files changed, 25 insertions(+) diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index 600650fa5..289717f4b 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -179,6 +179,15 @@ void AccountState::checkConnectivity() conValidator->checkAuthentication(); } else { // Check the server and then the auth. + +#ifdef Q_OS_WIN + // There seems to be a bug in Qt on Windows where QNAM sometimes stops + // working correctly after the computer woke up from sleep. See #2895 #2899 + // and #2973. + // As an attempted workaround, reset the QNAM regularly if the account is + // disconnected. + account()->resetNetworkAccessManager(); +#endif conValidator->checkServerAndAuth(); } } diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 5d2db3475..990b482d2 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -271,6 +271,21 @@ void Account::clearCookieJar() _am->setCookieJar(new CookieJar); } +void Account::resetNetworkAccessManager() +{ + if (!_credentials || !_am) { + return; + } + + qDebug() << "Resetting QNAM"; + QNetworkCookieJar* jar = _am->cookieJar(); + _am->deleteLater(); + _am = _credentials->getQNAM(); + _am->setCookieJar(jar); // takes ownership of the old cookie jar + connect(_am, SIGNAL(sslErrors(QNetworkReply*,QList)), + SLOT(slotHandleErrors(QNetworkReply*,QList))); +} + QNetworkAccessManager *Account::networkAccessManager() { return _am; diff --git a/src/libsync/account.h b/src/libsync/account.h index 1397195dc..3d8604f2b 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -156,6 +156,7 @@ public: void clearCookieJar(); + void resetNetworkAccessManager(); QNetworkAccessManager* networkAccessManager(); /// Called by network jobs on credential errors.