From 4030b6339c3dae4474f60b07700526fccf428b0c Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 4 Feb 2013 22:28:59 +0000 Subject: Allow QHostInfo::lookupHost() with no receiver to warm the DNS cache. This change lets you call QHostInfo::lookupHost() with a null receiver in order to warm up the DNS cache. This allows you to try to get the DNS request in flight early. Change-Id: Icfdd28146479aa534ae9ceb472f75e08aaa39cd2 Reviewed-by: Thiago Macieira --- src/network/kernel/qhostinfo.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index d9d8396011..d25372ece6 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -164,6 +164,9 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver, int id = theIdCounter.fetchAndAddRelaxed(1); // generate unique ID if (name.isEmpty()) { + if (!receiver) + return -1; + QHostInfo hostInfo(id); hostInfo.setError(QHostInfo::HostNotFound); hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given")); @@ -183,6 +186,9 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver, bool valid = false; QHostInfo info = manager->cache.get(name, &valid); if (valid) { + if (!receiver) + return -1; + info.setLookupId(id); QHostInfoResult result; QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); @@ -193,7 +199,8 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver, // cache is not enabled or it was not in the cache, do normal lookup QHostInfoRunnable* runnable = new QHostInfoRunnable(name, id); - QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); + if (receiver) + QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); manager->scheduleLookup(runnable); } return id; -- cgit v1.2.3