From e0bc5834ce26f91e60d8ca839f8a80ffd6f11c90 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Wed, 18 May 2011 15:33:56 +0100 Subject: 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 --- src/network/kernel/qhostaddress_p.h | 5 +++++ src/network/kernel/qhostinfo_symbian.cpp | 21 ++++++--------------- 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 #include #include +#include // Header does not exist in the S60 5.0 SDK //#include @@ -152,23 +153,17 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointer 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()); -- cgit v0.12