path: root/src
diff options
authorShane Kearns <>2012-04-27 19:31:37 +0100
committerQt by Nokia <>2012-05-05 03:50:25 +0200
commit1aeaf0e7089c893a927a5ab311a6176aad5874a7 (patch)
treef4f9244dc1b0fb6e3f7c0b4c4b0c3e771d1d06f7 /src
parentcd7abae39ff586d98293d86c8295d53511878b58 (diff)
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 Change-Id: I2963bdf13fb02e3ac269489ea463669142f3c5f3 Reviewed-by: Martin Petersson <>
Diffstat (limited to 'src')
1 files changed, 4 insertions, 4 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 7e95fc547d..b539ed4d9a 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -1018,9 +1018,6 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
d->initializeSession = false;
- if (d->networkSession)
- d->networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), -1);
QNetworkRequest request = req;
@@ -1113,8 +1110,11 @@ void QNetworkAccessManagerPrivate::_q_replyFinished()
emit q->finished(reply);
+ // If there are no active requests, release our reference to the network session.
+ // It will not be destroyed immediately, but rather when the connection cache is flushed
+ // after 2 minutes.
if (networkSession && q->findChildren<QNetworkReply *>().count() == 1)
- networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), 120000);
+ networkSession.clear();