From d38158bbba32ce6a80b4443ca92f37f485ebfa93 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 4 Mar 2010 14:23:51 +0100 Subject: DNS Cache: Also check inside the DNS threads Reviewed-by: joao --- src/network/kernel/qhostinfo.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index a65ca50..9c559ec 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -435,12 +435,24 @@ void QHostInfoRunnable::run() return; } - // if not in cache: OS lookup - QHostInfo hostInfo = QHostInfoAgent::fromName(toBeLookedUp); - - // save to cache - if (manager->cache.isEnabled()) - manager->cache.put(toBeLookedUp, hostInfo); + QHostInfo hostInfo; + + // QHostInfo::lookupHost already checks the cache. However we need to check + // it here too because it might have been cache saved by another QHostInfoRunnable + // in the meanwhile while this QHostInfoRunnable was scheduled but not running + if (manager->cache.isEnabled()) { + // check the cache first + bool valid = false; + hostInfo = manager->cache.get(toBeLookedUp, &valid); + if (!valid) { + // not in cache, we need to do the lookup and store the result in the cache + hostInfo = QHostInfoAgent::fromName(toBeLookedUp); + manager->cache.put(toBeLookedUp, hostInfo); + } + } else { + // cache is not enabled, just do the lookup and continue + hostInfo = QHostInfoAgent::fromName(toBeLookedUp); + } // check aborted again if (manager->wasAborted(id)) { -- cgit v0.12