From 587c6f9cc65dd6c7e1ba42b9d972608f36b24aea Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Sun, 13 Aug 2017 13:58:44 -0400 Subject: [PATCH] Split internet test into separate DNS lookup and connection. --- src/QtLocationPlugin/QGCTileCacheWorker.cpp | 27 ++++++++++++++++----- src/QtLocationPlugin/QGCTileCacheWorker.h | 5 ++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/QtLocationPlugin/QGCTileCacheWorker.cpp b/src/QtLocationPlugin/QGCTileCacheWorker.cpp index eca022cbe..a65ab83b9 100644 --- a/src/QtLocationPlugin/QGCTileCacheWorker.cpp +++ b/src/QtLocationPlugin/QGCTileCacheWorker.cpp @@ -73,6 +73,9 @@ QGCCacheWorker::setDatabaseFile(const QString& path) void QGCCacheWorker::quit() { + if(_hostLookupID) { + QHostInfo::abortHostLookup(_hostLookupID); + } _mutex.lock(); while(_taskQueue.count()) { QGCMapTask* task = _taskQueue.dequeue(); @@ -1055,12 +1058,24 @@ QGCCacheWorker::_createDB(QSqlDatabase* db, bool createDefault) void QGCCacheWorker::_testInternet() { - QTcpSocket socket; - socket.connectToHost("www.github.com", 80); - if (socket.waitForConnected(2500)) { - qCDebug(QGCTileCacheLog) << "Yes Internet Access"; - emit internetStatus(true); - return; + if(!_hostLookupID) { + _hostLookupID = QHostInfo::lookupHost("www.github.com", this, SLOT(_lookupReady(QHostInfo))); + } +} + +//----------------------------------------------------------------------------- +void +QGCCacheWorker::_lookupReady(QHostInfo info) +{ + _hostLookupID = 0; + if(info.error() == QHostInfo::NoError && info.addresses().size()) { + QTcpSocket socket; + socket.connectToHost(info.addresses().first(), 80); + if (socket.waitForConnected(2000)) { + qCDebug(QGCTileCacheLog) << "Yes Internet Access"; + emit internetStatus(true); + return; + } } qWarning() << "No Internet Access"; emit internetStatus(false); diff --git a/src/QtLocationPlugin/QGCTileCacheWorker.h b/src/QtLocationPlugin/QGCTileCacheWorker.h index d53f5ba97..a46a91117 100644 --- a/src/QtLocationPlugin/QGCTileCacheWorker.h +++ b/src/QtLocationPlugin/QGCTileCacheWorker.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "QGCLoggingCategory.h" @@ -49,6 +50,9 @@ public: protected: void run (); +private slots: + void _lookupReady (QHostInfo info); + private: void _saveTile (QGCMapTask* mtask); void _getTile (QGCMapTask* mtask); @@ -93,6 +97,7 @@ private: quint32 _defaultCount; time_t _lastUpdate; int _updateTimeout; + int _hostLookupID; }; #endif // QGC_TILE_CACHE_WORKER_H -- 2.22.0