summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
diff options
context:
space:
mode:
authorAaron Tunney <ext-aaron.2.tunney@nokia.com>2011-03-30 15:46:10 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2011-03-31 14:42:28 (GMT)
commit6022cd668435d1dda127e26e71de01982c7441a3 (patch)
tree5de814f9f175ef915c867ab465a0182ed513e214 /src/network/kernel
parent2c09d9c463aeff4888e7b694351d15cbb760ccdf (diff)
downloadQt-6022cd668435d1dda127e26e71de01982c7441a3.zip
Qt-6022cd668435d1dda127e26e71de01982c7441a3.tar.gz
Qt-6022cd668435d1dda127e26e71de01982c7441a3.tar.bz2
Ayschronous Next() change for DNS resolution.
Reviewed-By: Shane Kearns
Diffstat (limited to 'src/network/kernel')
-rw-r--r--src/network/kernel/qhostinfo_p.h12
-rw-r--r--src/network/kernel/qhostinfo_symbian.cpp116
2 files changed, 77 insertions, 51 deletions
diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h
index a7e83da..ab3e809 100644
--- a/src/network/kernel/qhostinfo_p.h
+++ b/src/network/kernel/qhostinfo_p.h
@@ -236,6 +236,8 @@ public:
void requestHostLookup();
int id();
+ void returnResults();
+
QHostInfoResult resultEmitter;
private:
@@ -244,10 +246,13 @@ private:
void run();
TInt RunError(TInt aError);
- void processNameResults();
- void processAddressResults();
+ void processNameResult();
+ void nextNameResult();
+ void processAddressResult();
private:
+ int iId;
+
const QString iHostName;
QString iEncodedHostName;
TPtrC iHostNamePtr;
@@ -263,10 +268,13 @@ private:
QHostInfo iResults;
+ QList<QHostAddress> iHostAddresses;
+
enum {
EIdle,
EGetByName,
EGetByAddress,
+ EGetMoreNames,
EError
} iState;
};
diff --git a/src/network/kernel/qhostinfo_symbian.cpp b/src/network/kernel/qhostinfo_symbian.cpp
index 02bef40..70ee5b8 100644
--- a/src/network/kernel/qhostinfo_symbian.cpp
+++ b/src/network/kernel/qhostinfo_symbian.cpp
@@ -53,9 +53,12 @@
#include <private/qsystemerror_p.h>
#include <private/qnetworksession_p.h>
-QT_BEGIN_NAMESPACE
-
+// Header does not exist in the S60 5.0 SDK
+//#include <networking/dnd_err.h>
+const TInt KErrDndNameNotFound = -5120; // Returned when no data found for GetByName
+const TInt KErrDndAddrNotFound = -5121; // Returned when no data found for GetByAddr
+QT_BEGIN_NAMESPACE
QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointer<QNetworkSession> networkSession)
{
@@ -88,15 +91,14 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointer<QNetw
QHostAddress address;
if (address.setAddress(hostName)) {
// Reverse lookup
-
TInetAddr IpAdd;
IpAdd.Input(qt_QString2TPtrC(hostName));
// Synchronous request. nameResult returns Host Name.
- hostResolver.GetByAddress(IpAdd, nameResult);
+ err = hostResolver.GetByAddress(IpAdd, nameResult);
if (err) {
// TODO - Could there be other errors? Symbian docs don't say.
- if (err == KErrNotFound) {
+ if (err == KErrDndAddrNotFound) {
results.setError(QHostInfo::HostNotFound);
results.setErrorString(tr("Host not found"));
} else {
@@ -131,7 +133,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointer<QNetw
err = hostResolver.GetByName(qt_QString2TPtrC(QString::fromLatin1(aceHostname)), nameResult);
if (err) {
// TODO - Could there be other errors? Symbian docs don't say.
- if (err == KErrNotFound) {
+ if (err == KErrDndNameNotFound) {
results.setError(QHostInfo::HostNotFound);
results.setErrorString(tr("Host not found"));
} else {
@@ -159,7 +161,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointer<QNetw
hostAdd.Output(ipAddr);
// Ensure that record is valid (not an alias and with length greater than 0)
- if (!(nameResult().iFlags & TNameRecord::EAlias) && (ipAddr.Length() > 0)) {
+ if (!(nameResult().iFlags & TNameRecord::EAlias) && !(hostAdd.IsUnspecified())) {
hostAddresses.append(QHostAddress(qt_TDesC2QString(ipAddr)));
}
}
@@ -244,7 +246,6 @@ void QSymbianHostResolver::requestHostLookup()
#endif
}
if (err) {
- // What are we doing with iResults??
iResults.setError(QHostInfo::UnknownError);
iResults.setErrorString(QSystemError(err, QSystemError::NativeError).toString());
@@ -252,7 +253,6 @@ void QSymbianHostResolver::requestHostLookup()
if (iAddress.setAddress(iHostName)) {
// Reverse lookup
-
IpAdd.Input(qt_QString2TPtrC(iHostName));
// Asynchronous request.
@@ -297,7 +297,7 @@ void QSymbianHostResolver::DoCancel()
#if defined(QHOSTINFO_DEBUG)
qDebug() << "QSymbianHostResolver::DoCancel" << QThread::currentThreadId() << id() << (int)iState << this;
#endif
- if (iState == EGetByAddress || iState == EGetByName) {
+ if (iState == EGetByAddress || iState == EGetByName || iState == EGetMoreNames) {
//these states have made an async request to host resolver
iHostResolver.Cancel();
} else {
@@ -313,11 +313,25 @@ void QSymbianHostResolver::RunL()
void QSymbianHostResolver::run()
{
- if (iState == EGetByName)
- processNameResults();
- else if (iState == EGetByAddress)
- processAddressResults();
+ switch (iState) {
+ case EGetByName:
+ processNameResult();
+ break;
+ case EGetByAddress:
+ processAddressResult();
+ break;
+ case EError:
+ returnResults();
+ break;
+ default:
+ iResults.setError(QHostInfo::UnknownError);
+ iResults.setErrorString(QSystemError(KErrCorrupt,QSystemError::NativeError).toString());
+ returnResults();
+ }
+}
+void QSymbianHostResolver::returnResults()
+{
iState = EIdle;
QSymbianHostInfoLookupManger *manager = QSymbianHostInfoLookupManger::globalInstance();
@@ -348,55 +362,57 @@ TInt QSymbianHostResolver::RunError(TInt aError)
return KErrNone;
}
-void QSymbianHostResolver::processNameResults()
+void QSymbianHostResolver::processNameResult()
{
- TInt err = iStatus.Int();
- if (err < 0) {
- // TODO - Could there be other errors? Symbian docs don't say.
- if (err == KErrNotFound) {
- iResults.setError(QHostInfo::HostNotFound);
- iResults.setErrorString(QObject::tr("Host not found"));
- } else {
- iResults.setError(QHostInfo::UnknownError);
- iResults.setErrorString(QSystemError(err,QSystemError::NativeError).toString());
- }
-
- iHostResolver.Close();
- return;
- }
-
- QList<QHostAddress> hostAddresses;
-
- TInetAddr hostAdd = iNameResult().iAddr;
- // 39 is the maximum length of an IPv6 address.
- TBuf<39> ipAddr;
-
- // Fill ipAddr with the IP address from hostAdd
- hostAdd.Output(ipAddr);
- if (ipAddr.Length() > 0)
- hostAddresses.append(QHostAddress(qt_TDesC2QString(ipAddr)));
+ if (iStatus.Int() == KErrNone) {
+ TInetAddr hostAdd = iNameResult().iAddr;
+ // 39 is the maximum length of an IPv6 address.
+ TBuf<39> ipAddr;
- // Check if there's more than one IP address linkd to this name
- while (iHostResolver.Next(iNameResult) == KErrNone) {
- hostAdd = iNameResult().iAddr;
hostAdd.Output(ipAddr);
// Ensure that record is valid (not an alias and with length greater than 0)
- if (!(iNameResult().iFlags & TNameRecord::EAlias) && (ipAddr.Length() > 0)) {
- hostAddresses.append(QHostAddress(qt_TDesC2QString(ipAddr)));
+ if (!(iNameResult().iFlags & TNameRecord::EAlias) && !(hostAdd.IsUnspecified())) {
+ if (iNameResult().iAddr.Family() == KAfInet) {
+ // IPv4 - prepend
+ iHostAddresses.prepend(QHostAddress(qt_TDesC2QString(ipAddr)));
+ } else {
+ // IPv6 - append
+ iHostAddresses.append(QHostAddress(qt_TDesC2QString(ipAddr)));
+ }
}
- }
- iResults.setAddresses(hostAddresses);
+ iState = EGetByName;
+ iHostResolver.Next(iNameResult, iStatus);
+ SetActive();
+ }
+ else if (iStatus.Int() == KErrDndNameNotFound) {
+ // No more addresses, so return the results (or an error if there aren't any).
+ if (iHostAddresses.count() > 0) {
+ iResults.setAddresses(iHostAddresses);
+ } else {
+ iState = EError;
+ iResults.setError(QHostInfo::HostNotFound);
+ iResults.setErrorString(QObject::tr("Host not found"));
+ }
+ returnResults();
+ }
+ else {
+ // Unknown error
+ iState = EError;
+ iResults.setError(QHostInfo::UnknownError);
+ iResults.setErrorString(QSystemError(iStatus.Int(),QSystemError::NativeError).toString());
+ returnResults();
+ }
}
-void QSymbianHostResolver::processAddressResults()
+void QSymbianHostResolver::processAddressResult()
{
TInt err = iStatus.Int();
if (err < 0) {
// TODO - Could there be other errors? Symbian docs don't say.
- if (err == KErrNotFound) {
+ if (err == KErrDndAddrNotFound) {
iResults.setError(QHostInfo::HostNotFound);
iResults.setErrorString(QObject::tr("Host not found"));
} else {
@@ -404,11 +420,13 @@ void QSymbianHostResolver::processAddressResults()
iResults.setErrorString(QSystemError(err,QSystemError::NativeError).toString());
}
+ returnResults();
return;
}
iResults.setHostName(qt_TDesC2QString(iNameResult().iName));
iResults.setAddresses(QList<QHostAddress>() << iAddress);
+ returnResults();
}