diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-03-04 13:23:51 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2010-03-04 13:42:23 (GMT) |
commit | d38158bbba32ce6a80b4443ca92f37f485ebfa93 (patch) | |
tree | 08414392e7cc721e6fdba11fde4c6f50051ed783 /src/network | |
parent | ce7f914e8db0cad698d934569f1c323e5b231bc9 (diff) | |
download | Qt-d38158bbba32ce6a80b4443ca92f37f485ebfa93.zip Qt-d38158bbba32ce6a80b4443ca92f37f485ebfa93.tar.gz Qt-d38158bbba32ce6a80b4443ca92f37f485ebfa93.tar.bz2 |
DNS Cache: Also check inside the DNS threads
Reviewed-by: joao
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 24 |
1 files 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)) { |