summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorShane Kearns <ext-shane.2.kearns@nokia.com>2012-02-17 15:14:01 +0000
committerQt by Nokia <qt-info@nokia.com>2012-02-17 20:23:25 +0100
commit844b096d674c3b803923357502435ef89ce0c738 (patch)
tree378f6c716f0397c1054a7b5e872ba6496fcc5ec4 /src/network
parent400c865f2994e67189108e36cfa206c365d57274 (diff)
Fix error handling in QHostInfo windows backend
If the DNS server returns a non authoritative host not found response, then windows returns WSATRY_AGAIN error code. This is now reported as HostNotFound and not UnknownError Change-Id: I212985acd4e85ff4b2bdb6c57ec403405a7695fb Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com> Reviewed-by: Richard J. Moore <rich@kde.org>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/kernel/qhostinfo_win.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp
index a00389e3ed..8ace68d961 100644
--- a/src/network/kernel/qhostinfo_win.cpp
+++ b/src/network/kernel/qhostinfo_win.cpp
@@ -95,6 +95,22 @@ static void resolveLibrary()
#endif
}
+static void translateWSAError(int error, QHostInfo *results)
+{
+ switch (error) {
+ case WSAHOST_NOT_FOUND: //authoritative not found
+ case WSATRY_AGAIN: //non authoritative not found
+ case WSANO_DATA: //valid name, no associated address
+ results->setError(QHostInfo::HostNotFound);
+ results->setErrorString(QHostInfoAgent::tr("Host not found"));
+ return;
+ default:
+ results->setError(QHostInfo::UnknownError);
+ results->setErrorString(QHostInfoAgent::tr("Unknown error (%1)").arg(error));
+ return;
+ }
+}
+
QHostInfo QHostInfoAgent::fromName(const QString &hostName)
{
#if defined(Q_OS_WINCE)
@@ -200,12 +216,8 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
}
results.setAddresses(addresses);
local_freeaddrinfo(res);
- } else if (WSAGetLastError() == WSAHOST_NOT_FOUND || WSAGetLastError() == WSANO_DATA) {
- results.setError(QHostInfo::HostNotFound);
- results.setErrorString(tr("Host not found"));
} else {
- results.setError(QHostInfo::UnknownError);
- results.setErrorString(tr("Unknown error"));
+ translateWSAError(WSAGetLastError(), &results);
}
} else {
// Fall back to gethostbyname, which only supports IPv4.
@@ -228,12 +240,8 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
break;
}
results.setAddresses(addresses);
- } else if (WSAGetLastError() == 11001) {
- results.setErrorString(tr("Host not found"));
- results.setError(QHostInfo::HostNotFound);
} else {
- results.setErrorString(tr("Unknown error"));
- results.setError(QHostInfo::UnknownError);
+ translateWSAError(WSAGetLastError(), &results);
}
}