QNetworkAccessManager: defer call to _q_networkSessionStateChanged

Also, call it only if the state really changes. If we stay disconnected
the whole time, there is no point in trying to create the session over
and over.

Change-Id: Ic3a92dd0575bed1a23ae36a944cc51b9741fb64a
Fixes: QTBUG-49760
Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Ulf Hermann 2018-09-26 13:15:19 +02:00 committed by Mårten Nordheim
parent 2b1913a7cb
commit c89d0f9d53

View File

@ -1848,6 +1848,7 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co
if (config.isValid())
newSession = QSharedNetworkSessionManager::getSession(config);
QNetworkSession::State oldState = QNetworkSession::Invalid;
if (networkSessionStrongRef) {
//do nothing if new and old session are the same
if (networkSessionStrongRef == newSession)
@ -1859,6 +1860,7 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co
q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)));
QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(error(QNetworkSession::SessionError)),
q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError)));
oldState = networkSessionStrongRef->state();
}
//switch to new session (null if config was invalid)
@ -1884,7 +1886,11 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co
QObject::connect(networkSessionStrongRef.data(), SIGNAL(error(QNetworkSession::SessionError)),
q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError)));
_q_networkSessionStateChanged(networkSessionStrongRef->state());
const QNetworkSession::State newState = networkSessionStrongRef->state();
if (newState != oldState) {
QMetaObject::invokeMethod(q, "_q_networkSessionStateChanged", Qt::QueuedConnection,
Q_ARG(QNetworkSession::State, newState));
}
}
void QNetworkAccessManagerPrivate::_q_networkSessionClosed()