Skip to content

Commit cc57cd2

Browse files
Shane KearnsPasi Pentikäinen
Shane Kearns
authored and
Pasi Pentikäinen
committed
Use reference count to close down idle network session
QNetworkAccessManager was using the AutoCloseConnection property of QNetworkSession to close it when idle. However this property is only implemented for polling engines and not event driven engines. Instead, release the network session reference. If another request comes in, it will be resurrected from the shared session weak reference. If not, then after 2 minutes when the connection caches are flushed the ref count will reach zero and cause the QNetworkSession to be destroyed (which closes it) Task-number: QTBUG-15812 Task-number: ou1cimx1#997006 Change-Id: I2963bdf13fb02e3ac269489ea463669142f3c5f3 Reviewed-by: Martin Petersson <[email protected]> (cherry picked from commit 1aeaf0e7089c893a927a5ab311a6176aad5874a7) (cherry picked from commit aef97ec) Reviewed-by: Pasi Pentikäinen <[email protected]>
1 parent f52aa9d commit cc57cd2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/network/access/qnetworkaccessmanager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,6 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
948948
d->initializeSession = false;
949949
}
950950
}
951-
952-
if (d->networkSession)
953-
d->networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), -1);
954951
#endif
955952

956953
QNetworkRequest request = req;
@@ -1014,8 +1011,11 @@ void QNetworkAccessManagerPrivate::_q_replyFinished()
10141011
emit q->finished(reply);
10151012

10161013
#ifndef QT_NO_BEARERMANAGEMENT
1014+
// If there are no active requests, release our reference to the network session.
1015+
// It will not be destroyed immediately, but rather when the connection cache is flushed
1016+
// after 2 minutes.
10171017
if (networkSession && q->findChildren<QNetworkReply *>().count() == 1)
1018-
networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), 120000);
1018+
networkSession.clear();
10191019
#endif
10201020
}
10211021

0 commit comments

Comments
 (0)