Index: /trunk/include/iprt/socket.h
===================================================================
--- /trunk/include/iprt/socket.h	(revision 53535)
+++ /trunk/include/iprt/socket.h	(revision 53536)
@@ -44,4 +44,7 @@
  * @{
  */
+
+/** Use the system default timeout for the connet attempt. */
+#define RT_SOCKETCONNECT_DEFAULT_WAIT (RT_INDEFINITE_WAIT - 1)
 
 /**
Index: /trunk/include/iprt/tcp.h
===================================================================
--- /trunk/include/iprt/tcp.h	(revision 53535)
+++ /trunk/include/iprt/tcp.h	(revision 53536)
@@ -181,4 +181,8 @@
  * @param   uPort           The port to connect to.
  * @param   pSock           Where to store the handle to the established connection.
+ * @param   cMillies        Number of milliseconds to wait for the connect attempt to complete.
+ *                          Use RT_INDEFINITE_WAIT to wait for ever.
+ *                          Use RT_SOCKETCONNECT_DEFAULT_WAIT to wait for the default time
+ *                          configured on the running system.
  * @param   ppCancelCookie  Where to store information for canceling the
  *                          operation (from a different thread). Optional.
@@ -194,5 +198,5 @@
  */
 RTR3DECL(int) RTTcpClientConnectEx(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock,
-                                   PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie);
+                                   RTMSINTERVAL cMillies, PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie);
 
 /**
Index: /trunk/src/VBox/Runtime/include/internal/socket.h
===================================================================
--- /trunk/src/VBox/Runtime/include/internal/socket.h	(revision 53535)
+++ /trunk/src/VBox/Runtime/include/internal/socket.h	(revision 53536)
@@ -59,5 +59,5 @@
 int rtSocketListen(RTSOCKET hSocket, int cMaxPending);
 int rtSocketAccept(RTSOCKET hSocket, PRTSOCKET phClient, struct sockaddr *pAddr, size_t *pcbAddr);
-int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr);
+int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr, RTMSINTERVAL cMillies);
 int rtSocketSetOpt(RTSOCKET hSocket, int iLevel, int iOption, void const *pvValue, int cbValue);
 #endif /* IPRT_INTERNAL_SOCKET_POLLING_ONLY */
Index: /trunk/src/VBox/Runtime/r3/socket.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/socket.cpp	(revision 53535)
+++ /trunk/src/VBox/Runtime/r3/socket.cpp	(revision 53536)
@@ -679,5 +679,5 @@
     {
         rc = rtSocketResolverError();
-        AssertMsgFailed(("Could not resolve '%s', rc=%Rrc\n", pszAddress, rc));
+        //AssertMsgFailed(("Could not resolve '%s', rc=%Rrc\n", pszAddress, rc));
         return rc;
     }
@@ -1722,6 +1722,10 @@
  * @param   hSocket             The socket handle.
  * @param   pAddr               The socket address to connect to.
- */
-int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr)
+ * @param   cMillies            Number of milliseconds to wait for the connect attempt to complete.
+ *                              Use RT_INDEFINITE_WAIT to wait for ever.
+ *                              Use RT_TCPCLIENTCONNECT_DEFAULT_WAIT to wait for the default time
+ *                              configured on the running system.
+ */
+int rtSocketConnect(RTSOCKET hSocket, PCRTNETADDR pAddr, RTMSINTERVAL cMillies)
 {
     /*
@@ -1738,6 +1742,71 @@
     if (RT_SUCCESS(rc))
     {
-        if (connect(pThis->hNative, &u.Addr, cbAddr) != 0)
-            rc = rtSocketError();
+        if (cMillies == RT_SOCKETCONNECT_DEFAULT_WAIT)
+        {
+            if (connect(pThis->hNative, &u.Addr, cbAddr) != 0)
+                rc = rtSocketError();
+        }
+        else
+        {
+            /*
+             * Switch the socket to nonblocking mode, initiate the connect
+             * and wait for the socket to become writable or until the timeout
+             * expires.
+             */
+            rc = rtSocketSwitchBlockingMode(pThis, false /* fBlocking */);
+            if (RT_SUCCESS(rc))
+            {
+                if (connect(pThis->hNative, &u.Addr, cbAddr) != 0)
+                {
+                    rc = rtSocketError();
+                    if (rc == VERR_TRY_AGAIN || rc == VERR_NET_IN_PROGRESS)
+                    {
+                        int rcSock = 0;
+                        fd_set FdSetWriteable;
+                        struct timeval TvTimeout;
+
+                        TvTimeout.tv_sec = cMillies / RT_MS_1SEC;
+                        TvTimeout.tv_usec = (cMillies % RT_MS_1SEC) * RT_US_1MS;
+
+                        FD_ZERO(&FdSetWriteable);
+                        FD_SET(pThis->hNative, &FdSetWriteable);
+                        do
+                        {
+                            rcSock = select(pThis->hNative + 1, NULL, &FdSetWriteable, NULL,
+                                              cMillies == RT_INDEFINITE_WAIT || cMillies >= INT_MAX
+                                            ? NULL
+                                            : &TvTimeout);
+                            if (rcSock > 0)
+                            {
+                                int iSockError = 0;
+                                socklen_t cbSockOpt = sizeof(iSockError);
+                                rcSock = getsockopt(pThis->hNative, SOL_SOCKET, SO_ERROR, &iSockError, &cbSockOpt);
+                                if (rcSock == 0)
+                                {
+                                    if (iSockError == 0)
+                                        rc = VINF_SUCCESS;
+                                    else
+                                    {
+#ifdef RT_OS_WINDOWS
+                                        rc = RTErrConvertFromWin32(iSockError);
+#else
+                                        rc = RTErrConvertFromErrno(iSockError);
+#endif
+                                    }
+                                }
+                                else
+                                    rc = rtSocketError();
+                            }
+                            else if (rcSock == 0)
+                                rc = VERR_TIMEOUT;
+                            else
+                                rc = rtSocketError();
+                        } while (rc == VERR_INTERRUPTED);
+                    }
+                }
+
+                rtSocketSwitchBlockingMode(pThis, true /* fBlocking */);
+            }
+        }
     }
 
Index: /trunk/src/VBox/Runtime/r3/tcp.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/tcp.cpp	(revision 53535)
+++ /trunk/src/VBox/Runtime/r3/tcp.cpp	(revision 53536)
@@ -806,10 +806,10 @@
 RTR3DECL(int) RTTcpClientConnect(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock)
 {
-    return RTTcpClientConnectEx(pszAddress, uPort, pSock, NULL);
+    return RTTcpClientConnectEx(pszAddress, uPort, pSock, RT_SOCKETCONNECT_DEFAULT_WAIT, NULL);
 }
 
 
 RTR3DECL(int) RTTcpClientConnectEx(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock,
-                                   PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie)
+                                   RTMSINTERVAL cMillies, PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie)
 {
     /*
@@ -838,5 +838,5 @@
 
         if (!ppCancelCookie)
-            rc = rtSocketConnect(Sock, &Addr);
+            rc = rtSocketConnect(Sock, &Addr, cMillies);
         else
         {
@@ -844,5 +844,5 @@
             if (ASMAtomicCmpXchgPtr(ppCancelCookie, (PRTTCPCLIENTCONNECTCANCEL)Sock, NULL))
             {
-                rc = rtSocketConnect(Sock, &Addr);
+                rc = rtSocketConnect(Sock, &Addr, cMillies);
                 if (ASMAtomicCmpXchgPtr(ppCancelCookie, NULL, (PRTTCPCLIENTCONNECTCANCEL)Sock))
                     RTSocketRelease(Sock);
Index: /trunk/src/VBox/ValidationKit/utils/TestExecServ/TestExecServiceTcp.cpp
===================================================================
--- /trunk/src/VBox/ValidationKit/utils/TestExecServ/TestExecServiceTcp.cpp	(revision 53535)
+++ /trunk/src/VBox/ValidationKit/utils/TestExecServ/TestExecServiceTcp.cpp	(revision 53536)
@@ -204,5 +204,6 @@
         RTSOCKET hTcpClient;
         Log2(("Calling RTTcpClientConnect(%s, %u,)...\n", g_szTcpConnectAddr, g_uTcpConnectPort));
-        int rc = RTTcpClientConnectEx(g_szTcpConnectAddr, g_uTcpConnectPort, &hTcpClient, &g_pTcpConnectCancelCookie);
+        int rc = RTTcpClientConnectEx(g_szTcpConnectAddr, g_uTcpConnectPort, &hTcpClient,
+                                      RT_SOCKETCONNECT_DEFAULT_WAIT, &g_pTcpConnectCancelCookie);
         Log(("txsTcpRecvPkt: RTTcpClientConnect -> %Rrc\n", rc));
         if (RT_SUCCESS(rc))
@@ -278,5 +279,5 @@
         {
             Log2(("Calling RTTcpClientConnect(%s, %u,)...\n", g_szTcpConnectAddr, g_uTcpConnectPort));
-            rc = RTTcpClientConnectEx(g_szTcpConnectAddr, g_uTcpConnectPort, &g_hTcpClient, NULL);
+            rc = RTTcpClientConnect(g_szTcpConnectAddr, g_uTcpConnectPort, &g_hTcpClient);
             Log(("txsTcpRecvPkt: RTTcpClientConnect -> %Rrc\n", rc));
             if (RT_SUCCESS(rc) || txsTcpIsFatalClientConnectStatus(rc))
