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.
This commit is contained in:
Christian Kamm 2015-03-19 11:40:47 +01:00
parent 89f831e7d4
commit 57c14a0eba
3 changed files with 25 additions and 0 deletions

View file

@ -179,6 +179,15 @@ void AccountState::checkConnectivity()
conValidator->checkAuthentication(); conValidator->checkAuthentication();
} else { } else {
// Check the server and then the auth. // 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(); conValidator->checkServerAndAuth();
} }
} }

View file

@ -271,6 +271,21 @@ void Account::clearCookieJar()
_am->setCookieJar(new CookieJar); _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<QSslError>)),
SLOT(slotHandleErrors(QNetworkReply*,QList<QSslError>)));
}
QNetworkAccessManager *Account::networkAccessManager() QNetworkAccessManager *Account::networkAccessManager()
{ {
return _am; return _am;

View file

@ -156,6 +156,7 @@ public:
void clearCookieJar(); void clearCookieJar();
void resetNetworkAccessManager();
QNetworkAccessManager* networkAccessManager(); QNetworkAccessManager* networkAccessManager();
/// Called by network jobs on credential errors. /// Called by network jobs on credential errors.