src/network/socket/qabstractsocket.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 23 89e065397ea6
--- a/src/network/socket/qabstractsocket.cpp	Fri Apr 16 15:50:13 2010 +0300
+++ b/src/network/socket/qabstractsocket.cpp	Mon May 03 13:17:34 2010 +0300
@@ -172,6 +172,10 @@
     This signal is emitted after connectToHost() has been called and
     the host lookup has succeeded.
 
+    \note Since Qt 4.6.3 QAbstractSocket may emit hostFound()
+    directly from the connectToHost() call since a DNS result could have been
+    cached.
+
     \sa connected()
 */
 
@@ -181,6 +185,10 @@
     This signal is emitted after connectToHost() has been called and
     a connection has been successfully established.
 
+    \note On some operating systems the connected() signal may
+    be directly emitted from the connectToHost() call for connections
+    to the localhost.
+
     \sa connectToHost(), disconnected()
 */
 
@@ -354,6 +362,8 @@
 #include "qabstractsocket.h"
 #include "qabstractsocket_p.h"
 
+#include "private/qhostinfo_p.h"
+
 #include <qabstracteventdispatcher.h>
 #include <qdatetime.h>
 #include <qhostaddress.h>
@@ -1369,8 +1379,20 @@
         return;
 #endif
     } else {
-        if (d->threadData->eventDispatcher)
-            d->hostLookupId = QHostInfo::lookupHost(hostName, this, SLOT(_q_startConnecting(QHostInfo)));
+        if (d->threadData->eventDispatcher) {
+            // this internal API for QHostInfo either immediatly gives us the desired
+            // QHostInfo from cache or later calls the _q_startConnecting slot.
+            bool immediateResultValid = false;
+            QHostInfo hostInfo = qt_qhostinfo_lookup(hostName,
+                                                     this,
+                                                     SLOT(_q_startConnecting(QHostInfo)),
+                                                     &immediateResultValid,
+                                                     &d->hostLookupId);
+            if (immediateResultValid) {
+                d->hostLookupId = -1;
+                d->_q_startConnecting(hostInfo);
+            }
+        }
     }
 
 #if defined(QABSTRACTSOCKET_DEBUG)