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)
This commit is contained in:
Martin Petersson 2011-04-27 12:36:53 +02:00
parent 5be54b220a
commit 5aaa38c7ac
2 changed files with 14 additions and 2 deletions

View File

@ -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>("QNetworkConfiguration");
qRegisterMetaType<QNetworkConfigurationPrivatePointer>("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;
}
}

View File

@ -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;