From a04905c2bb5caac9c9c0a3d0928f6fdfb4600cb9 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Fri, 1 Apr 2011 11:08:39 +0100 Subject: Implement cache support for the async resolver Add additional check when starting a queued request, as the cache may have been populated while the request was queued. Put completed requests in the cache (note cache code internally discards errored results and only caches successful results) Reviewed-by: Aaron Tunney Reviewed-by: Markus Goetz --- src/network/kernel/qhostinfo_p.h | 2 +- src/network/kernel/qhostinfo_symbian.cpp | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index ab3e809..ceec04d 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -274,7 +274,7 @@ private: EIdle, EGetByName, EGetByAddress, - EGetMoreNames, + ECompleteFromCache, EError } iState; }; diff --git a/src/network/kernel/qhostinfo_symbian.cpp b/src/network/kernel/qhostinfo_symbian.cpp index 73fed16..a38a845 100644 --- a/src/network/kernel/qhostinfo_symbian.cpp +++ b/src/network/kernel/qhostinfo_symbian.cpp @@ -108,6 +108,9 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointercache.isEnabled()) { + //check if name has been put in the cache while this request was queued + bool valid; + QHostInfo cachedResult = manager->cache.get(iHostName, &valid); + if (valid) { +#if defined(QHOSTINFO_DEBUG) + qDebug("...found in cache"); +#endif + iResults = cachedResult; + iState = ECompleteFromCache; + SetActive(); + TRequestStatus* stat = &iStatus; + User::RequestComplete(stat, KErrNone); + return; + } + } + int err; if (iNetworkSession) { err = QNetworkSessionPrivate::nativeOpenHostResolver(*iNetworkSession, iHostResolver, KAfInet, KProtocolInetUdp); @@ -295,12 +316,12 @@ void QSymbianHostResolver::DoCancel() #if defined(QHOSTINFO_DEBUG) qDebug() << "QSymbianHostResolver::DoCancel" << QThread::currentThreadId() << id() << (int)iState << this; #endif - if (iState == EGetByAddress || iState == EGetByName || iState == EGetMoreNames) { + if (iState == EGetByAddress || iState == EGetByName) { //these states have made an async request to host resolver iHostResolver.Cancel(); } else { //for the self completing states there is nothing to cancel - Q_ASSERT(iState == EError); + Q_ASSERT(iState == EError || iState == ECompleteFromCache); } } @@ -318,6 +339,7 @@ void QSymbianHostResolver::run() case EGetByAddress: processAddressResult(); break; + case ECompleteFromCache: case EError: returnResults(); break; @@ -339,6 +361,9 @@ void QSymbianHostResolver::returnResults() iState = EIdle; QSymbianHostInfoLookupManger *manager = QSymbianHostInfoLookupManger::globalInstance(); + if (manager->cache.isEnabled()) { + manager->cache.put(iHostName, iResults); + } manager->lookupFinished(this); resultEmitter.emitResultsReady(iResults); -- cgit v0.12