Skip to content

Commit

Permalink
Merge pull request mavlink#5565 from mavlink/DNSLookup
Browse files Browse the repository at this point in the history
Split internet test into separate DNS lookup and connection.
  • Loading branch information
DonLakeFlyer authored Aug 14, 2017
2 parents 18371ab + 09fcec3 commit 82e01bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/QtLocationPlugin/QGCTileCacheWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ QGCCacheWorker::QGCCacheWorker()
, _defaultCount(0)
, _lastUpdate(0)
, _updateTimeout(SHORT_TIMEOUT)
, _hostLookupID(0)
{

}
Expand All @@ -73,6 +74,9 @@ QGCCacheWorker::setDatabaseFile(const QString& path)
void
QGCCacheWorker::quit()
{
if(_hostLookupID) {
QHostInfo::abortHostLookup(_hostLookupID);
}
_mutex.lock();
while(_taskQueue.count()) {
QGCMapTask* task = _taskQueue.dequeue();
Expand Down Expand Up @@ -1055,12 +1059,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);
Expand Down
5 changes: 5 additions & 0 deletions src/QtLocationPlugin/QGCTileCacheWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QWaitCondition>
#include <QMutexLocker>
#include <QtSql/QSqlDatabase>
#include <QHostInfo>

#include "QGCLoggingCategory.h"

Expand All @@ -49,6 +50,9 @@ class QGCCacheWorker : public QThread
protected:
void run ();

private slots:
void _lookupReady (QHostInfo info);

private:
void _saveTile (QGCMapTask* mtask);
void _getTile (QGCMapTask* mtask);
Expand Down Expand Up @@ -93,6 +97,7 @@ class QGCCacheWorker : public QThread
quint32 _defaultCount;
time_t _lastUpdate;
int _updateTimeout;
int _hostLookupID;
};

#endif // QGC_TILE_CACHE_WORKER_H

0 comments on commit 82e01bb

Please sign in to comment.