Track active network replies without qFindChildren
authorShane Kearns <ext-shane.2.kearns@nokia.com>
Wed, 30 May 2012 16:08:16 +0000 (17:08 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 1 Jun 2012 13:19:33 +0000 (15:19 +0200)
For bearer management to work correctly, we need to know when there
are no network replies active. Previously this was implemented
using qFindChildren, but that doesn't work when the user reparents
QNetworkReply.
QtWebkit does this (actually sets parent to 0).
Also the qFindChildren implementation was racy if multiple requests
were finished in parallel. Again, likely to be triggered by webkit
loading page elements.

Task-number: QTBUG-15812
Change-Id: I181a9ba6611c7c4b6fffa2d84fe4029d89e8f596
Reviewed-by: Martin Petersson <Martin.Petersson@nokia.com>
src/network/access/qnetworkaccessmanager.cpp
src/network/access/qnetworkaccessmanager_p.h

index f27c38c..283bf86 100644 (file)
@@ -1115,7 +1115,8 @@ void QNetworkAccessManagerPrivate::_q_replyFinished()
     // 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)
+    activeReplyCount--;
+    if (networkSession && activeReplyCount == 0)
         networkSession.clear();
 #endif
 }
@@ -1142,6 +1143,9 @@ QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *reply)
      * avoid getting a connection error. */
     q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>)));
 #endif
+#ifndef QT_NO_BEARERMANAGEMENT
+    activeReplyCount++;
+#endif
 
     return reply;
 }
index 08c0e72..bd3dc39 100644 (file)
@@ -81,6 +81,7 @@ public:
           networkSession(0),
           lastSessionState(QNetworkSession::Invalid),
           networkAccessible(QNetworkAccessManager::Accessible),
+          activeReplyCount(0),
           online(false),
           initializeSession(true),
 #endif
@@ -147,6 +148,7 @@ public:
     QNetworkSession::State lastSessionState;
     QString networkConfiguration;
     QNetworkAccessManager::NetworkAccessibility networkAccessible;
+    int activeReplyCount;
     bool online;
     bool initializeSession;
 #endif