QAbstractSocket::waitForConnected check if host name is an IP address
authorMartin Petersson <Martin.Petersson@nokia.com>
Fri, 30 Mar 2012 11:07:33 +0000 (13:07 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 2 Apr 2012 12:52:48 +0000 (14:52 +0200)
If the current host name is an ip address we can create the QHostInfo
directly instead of performing a reverse lookup.

Task-number: QTBUG-18881
Change-Id: If239481e455f4f7fb74d978f685dc5d8e9f22c0a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Jonas Gastal <jgastal@profusion.mobi>
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
src/network/socket/qabstractsocket.cpp

index af22b20..0c4eed8 100644 (file)
@@ -1984,7 +1984,16 @@ bool QAbstractSocket::waitForConnected(int msecs)
             d->_q_startConnecting(QHostInfoPrivate::fromName(d->hostName, networkSession));
         } else
 #endif
-        d->_q_startConnecting(QHostInfo::fromName(d->hostName));
+        {
+            QHostAddress temp;
+            if (temp.setAddress(d->hostName)) {
+                QHostInfo info;
+                info.setAddresses(QList<QHostAddress>() << temp);
+                d->_q_startConnecting(info);
+            } else {
+                d->_q_startConnecting(QHostInfo::fromName(d->hostName));
+            }
+        }
     }
     if (state() == UnconnectedState)
         return false; // connect not im progress anymore!