diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2011-05-18 14:33:56 (GMT) |
---|---|---|
committer | Shane Kearns <shane.kearns@accenture.com> | 2011-05-25 14:36:29 (GMT) |
commit | e0bc5834ce26f91e60d8ca839f8a80ffd6f11c90 (patch) | |
tree | 21e7cc1184d589551791ceac243360428c33b1ad /src/network | |
parent | 06d32b235a21fb612972d248089805423a97bc18 (diff) | |
download | Qt-e0bc5834ce26f91e60d8ca839f8a80ffd6f11c90.zip Qt-e0bc5834ce26f91e60d8ca839f8a80ffd6f11c90.tar.gz Qt-e0bc5834ce26f91e60d8ca839f8a80ffd6f11c90.tar.bz2 |
symbian socket engine: share ip address conversion code
The helper function for converting TInetAddr -> QHostAddress is now
used in qhostinfo_symbian.cpp as well.
This should slightly improve performance by avoiding conversion to/from
strings, and also remove some duplicated code.
Reviewed-by: Markus Goetz
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/kernel/qhostaddress_p.h | 5 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo_symbian.cpp | 21 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface_symbian.cpp | 4 |
3 files changed, 12 insertions, 18 deletions
diff --git a/src/network/kernel/qhostaddress_p.h b/src/network/kernel/qhostaddress_p.h index 255d706..0349ff3 100644 --- a/src/network/kernel/qhostaddress_p.h +++ b/src/network/kernel/qhostaddress_p.h @@ -71,6 +71,11 @@ public: void setPrefixLength(QAbstractSocket::NetworkLayerProtocol proto, int len); }; +#ifdef Q_OS_SYMBIAN +class TInetAddr; +QHostAddress qt_QHostAddressFromTInetAddr(const TInetAddr& addr); +#endif + QT_END_NAMESPACE #endif diff --git a/src/network/kernel/qhostinfo_symbian.cpp b/src/network/kernel/qhostinfo_symbian.cpp index 042899d..86c157c 100644 --- a/src/network/kernel/qhostinfo_symbian.cpp +++ b/src/network/kernel/qhostinfo_symbian.cpp @@ -52,6 +52,7 @@ #include <private/qcore_symbian_p.h> #include <private/qsystemerror_p.h> #include <private/qnetworksession_p.h> +#include <private/qhostaddress_p.h> // Header does not exist in the S60 5.0 SDK //#include <networking/dnd_err.h> @@ -152,23 +153,17 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointer<QNetw QList<QHostAddress> hostAddresses; TInetAddr hostAdd = nameResult().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 (!(nameResult().iFlags & TNameRecord::EAlias) && !(hostAdd.IsUnspecified())) + hostAddresses.append(qt_QHostAddressFromTInetAddr(hostAdd)); // Check if there's more than one IP address linkd to this name while (hostResolver.Next(nameResult) == KErrNone) { hostAdd = nameResult().iAddr; - hostAdd.Output(ipAddr); // Ensure that record is valid (not an alias and with length greater than 0) - if (!(nameResult().iFlags & TNameRecord::EAlias) && !(hostAdd.IsUnspecified())) { - hostAddresses.append(QHostAddress(qt_TDesC2QString(ipAddr))); - } + if (!(nameResult().iFlags & TNameRecord::EAlias) && !(hostAdd.IsUnspecified())) + hostAddresses.append(qt_QHostAddressFromTInetAddr(hostAdd)); } hostResolver.Close(); @@ -414,14 +409,10 @@ void QSymbianHostResolver::processNameResult() { if (iStatus.Int() == KErrNone) { TInetAddr hostAdd = iNameResult().iAddr; - // 39 is the maximum length of an IPv6 address. - TBuf<39> ipAddr; - - hostAdd.Output(ipAddr); // Ensure that record is valid (not an alias and with length greater than 0) if (!(iNameResult().iFlags & TNameRecord::EAlias) && !(hostAdd.IsUnspecified())) { - iHostAddresses.append(QHostAddress(qt_TDesC2QString(ipAddr))); + iHostAddresses.append(qt_QHostAddressFromTInetAddr(hostAdd)); } iState = EGetByName; diff --git a/src/network/kernel/qnetworkinterface_symbian.cpp b/src/network/kernel/qnetworkinterface_symbian.cpp index e7d3ca9..dca6cf4 100644 --- a/src/network/kernel/qnetworkinterface_symbian.cpp +++ b/src/network/kernel/qnetworkinterface_symbian.cpp @@ -67,10 +67,8 @@ static QNetworkInterface::InterfaceFlags convertFlags(const TSoInetInterfaceInfo return flags; } -//TODO: share this, at least QHostInfo needs to do the same thing -static QHostAddress qt_QHostAddressFromTInetAddr(const TInetAddr& addr) +QHostAddress qt_QHostAddressFromTInetAddr(const TInetAddr& addr) { - //TODO: do we want to call v4 mapped addresses v4 or v6 outside of this file? if (addr.IsV4Mapped() || addr.Family() == KAfInet) { //convert v4 host address return QHostAddress(addr.Address()); |