[Development] QUdpSocket writeDatagram performace on ARM

Tom Hirst tom.hirst at ipe-systems.co.uk
Thu Oct 9 15:36:27 CEST 2014


I've come across the problem described in QTBUG-37092 and have tracked it down to the fact that writeDatagram ends up calling if_nametoindex with an empty interface name, for some reason on ARM platforms this call takes around 30ms to complete. I would suggest avoiding this call if the interface name (from the IPv6 scopeid) is empty - because it will just return 0 anyway, I don't see any value on making this call on non-ARM platforms either. Patch attached to the bug report and duplicated here.  

For what it is worth, this problem won't occur on Android ARM platforms, as they don't have the call to if_nametoindex.

Is this the correct approach to be taking?


>From 6d82d171b7fcbf4223cb938894684b7efeda0a58 Mon Sep 17 00:00:00 2001
From: Tom Hirst <tom.hirst at ipe-systems.co.uk>
Date: Thu, 9 Oct 2014 11:30:02 +0100
Subject: [PATCH] if_nametoindex being called with empty string

Calling if_nametoindex with an empty string will always return 0, but
on ARM linux platforms this call seems to be very expensive (~30ms),
adding a large overhead to calls such as QUdpSocket::writeDatagram()

Change-Id: I05e644ec284ebcc5688cc108d98f7c36ec12fe90
---
 src/network/socket/qnativesocketengine_unix.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index 65244ce..46d703f 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -383,7 +383,7 @@ bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &addr, quint16
         bool ok;
         sockAddrIPv6.sin6_scope_id = scopeid.toInt(&ok);
 #ifndef QT_NO_IPV6IFNAME
-        if (!ok)
+        if (!ok && !scopeid.isEmpty())
             sockAddrIPv6.sin6_scope_id = ::if_nametoindex(scopeid.toLatin1());
 #endif
         Q_IPV6ADDR ip6 = addr.toIPv6Address();
@@ -907,7 +907,7 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l
         bool ok;
         sockAddrIPv6.sin6_scope_id = scopeid.toInt(&ok);
 #ifndef QT_NO_IPV6IFNAME
-        if (!ok)
+        if (!ok && !scopeid.isEmpty())
             sockAddrIPv6.sin6_scope_id = ::if_nametoindex(scopeid.toLatin1());
 #endif
         sockAddrSize = sizeof(sockAddrIPv6);
-- 
1.8.1.4



More information about the Development mailing list