From e29e13ff537a92f7d2afe34893d8bae8a6788bed Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Fri, 18 Mar 2011 11:45:52 +0000 Subject: Add explicit network session support for async QHostInfo Pass the shared network session pointer into the QSymbianHostResolver (which maintains a reference for its lifetime). This is used to open the RHostResolver handle, in order to get a host resolver which is associated with a particular session. The session is obtained from the _q_networksession property of the QAbstractSocket, as in the symbian socket engine Reviewed-by: Markus Goetz --- src/network/kernel/qhostinfo.cpp | 10 +++++++++- src/network/kernel/qhostinfo_p.h | 3 ++- src/network/kernel/qhostinfo_symbian.cpp | 18 +++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index 7a15a05..1ae0bbd 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #ifdef Q_OS_UNIX # include @@ -219,8 +220,15 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver, } // cache is not enabled or it was not in the cache, do normal lookup +#ifndef QT_NO_BEARERMANAGEMENT + QSharedPointer networkSession; + QVariant v(receiver->property("_q_networksession")); + if (v.isValid()) + networkSession = qvariant_cast< QSharedPointer >(v); +#endif + QSymbianHostResolver *symbianResolver = 0; - QT_TRAP_THROWING(symbianResolver = new QSymbianHostResolver(name, id)); + QT_TRAP_THROWING(symbianResolver = new QSymbianHostResolver(name, id, networkSession)); QObject::connect(&symbianResolver->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); manager->scheduleLookup(symbianResolver); } diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index 909bd03..e3f7f19 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -225,7 +225,7 @@ private slots: class QSymbianHostResolver : public CActive { public: - QSymbianHostResolver(const QString &hostName, int id); + QSymbianHostResolver(const QString &hostName, int id, QSharedPointer networkSession); ~QSymbianHostResolver(); void requestHostLookup(); @@ -247,6 +247,7 @@ private: RSocketServ& iSocketServ; RHostResolver iHostResolver; + QSharedPointer iNetworkSession; TRequestStatus iStatus; diff --git a/src/network/kernel/qhostinfo_symbian.cpp b/src/network/kernel/qhostinfo_symbian.cpp index 54ec33c..12e59c6 100644 --- a/src/network/kernel/qhostinfo_symbian.cpp +++ b/src/network/kernel/qhostinfo_symbian.cpp @@ -51,6 +51,7 @@ #include "qhostinfo_p.h" #include #include +#include QT_BEGIN_NAMESPACE @@ -216,9 +217,9 @@ QString QHostInfo::localDomainName() } -QSymbianHostResolver::QSymbianHostResolver(const QString &hostName, int identifier) +QSymbianHostResolver::QSymbianHostResolver(const QString &hostName, int identifier, QSharedPointer networkSession) : CActive(CActive::EPriorityStandard), iHostName(hostName), - iSocketServ(qt_symbianGetSocketServer()), iResults(identifier) + iSocketServ(qt_symbianGetSocketServer()), iNetworkSession(networkSession), iResults(identifier) { CActiveScheduler::Add(this); } @@ -241,7 +242,18 @@ void QSymbianHostResolver::requestHostLookup() iHostName.toLatin1().constData(), id()); #endif - int err = iHostResolver.Open(iSocketServ, KAfInet, KProtocolInetUdp); + int err; + if (iNetworkSession) { + err = QNetworkSessionPrivate::nativeOpenHostResolver(*iNetworkSession, iHostResolver, KAfInet, KProtocolInetUdp); +#if defined(QHOSTINFO_DEBUG) + qDebug("using resolver from session (err = %d)", err); +#endif + } else { + err = iHostResolver.Open(iSocketServ, KAfInet, KProtocolInetUdp); +#if defined(QHOSTINFO_DEBUG) + qDebug("using default resolver (err = %d)", err); +#endif + } if (err) { // What are we doing with iResults?? iResults.setError(QHostInfo::UnknownError); -- cgit v0.12