From cc57cd255a923140aed48a4b1211e99966ff8e0b Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Fri, 27 Apr 2012 19:31:37 +0100 Subject: Use reference count to close down idle network session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 1aeaf0e7089c893a927a5ab311a6176aad5874a7) (cherry picked from commit aef97ec5e684f75e4f4e36da1ac321270a1ae2f3) Reviewed-by: Pasi Pentikäinen --- src/network/access/qnetworkaccessmanager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 58690fa6ad..6a701afc68 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -948,9 +948,6 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera d->initializeSession = false; } } - - if (d->networkSession) - d->networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), -1); #endif QNetworkRequest request = req; @@ -1014,8 +1011,11 @@ void QNetworkAccessManagerPrivate::_q_replyFinished() emit q->finished(reply); #ifndef QT_NO_BEARERMANAGEMENT + // 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().count() == 1) - networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), 120000); + networkSession.clear(); #endif } -- cgit v1.2.1