From 5aaa38c7ac9370fa6f61581f4b5e57dd6d119ec0 Mon Sep 17 00:00:00 2001 From: Martin Petersson Date: Wed, 27 Apr 2011 12:36:53 +0200 Subject: [PATCH] QNetworkConfigurationManager: Fix network polling. startPolling() is called by each engine, so before it would start multiple singleshot timers. So I moved the timer to the class and check if it has already been started before it is activated again. So that we just use one timer. Task-number: QTBUG-17219 Reviewed-by: Iiro Kause Reviewed-by: Kranthi Kuntala (cherry picked from commit 2506b86828ca8140c2f22d85a4378df40899b132) --- src/network/bearer/qnetworkconfigmanager_p.cpp | 14 ++++++++++++-- src/network/bearer/qnetworkconfigmanager_p.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index c108ad34cf..e9b6703dd9 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -60,7 +60,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, #endif QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() - : QObject(), mutex(QMutex::Recursive), forcedPolling(0), firstUpdate(true) + : QObject(), pollTimer(0), mutex(QMutex::Recursive), forcedPolling(0), firstUpdate(true) { qRegisterMetaType("QNetworkConfiguration"); qRegisterMetaType("QNetworkConfigurationPrivatePointer"); @@ -442,9 +442,19 @@ void QNetworkConfigurationManagerPrivate::startPolling() { QMutexLocker locker(&mutex); + if(!pollTimer) { + pollTimer = new QTimer(this); + pollTimer->setInterval(10000); + pollTimer->setSingleShot(true); + connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollEngines())); + } + + if(pollTimer->isActive()) + return; + foreach (QBearerEngine *engine, sessionEngines) { if (engine->requiresPolling() && (forcedPolling || engine->configurationsInUse())) { - QTimer::singleShot(10000, this, SLOT(pollEngines())); + pollTimer->start(); break; } } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 81f38c5183..abc4b9b4fa 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -64,6 +64,7 @@ QT_BEGIN_NAMESPACE class QBearerEngine; +class QTimer; class Q_NETWORK_EXPORT QNetworkConfigurationManagerPrivate : public QObject { @@ -107,6 +108,7 @@ private Q_SLOTS: private: void startPolling(); + QTimer *pollTimer; private: mutable QMutex mutex;