Index: /trunk/src/VBox/Devices/Network/slirp/slirp.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 38089)
+++ /trunk/src/VBox/Devices/Network/slirp/slirp.c	(revision 38090)
@@ -1044,4 +1044,61 @@
 }
 
+
+static bool slirpConnectOrWrite(PNATState pData, struct socket *so, bool fConnectOnly)
+{
+    int ret;
+    LogFlowFunc(("ENTER: so:%R[natsock], fConnectOnly:%RTbool\n", so, fConnectOnly));
+    /*
+     * Check for non-blocking, still-connecting sockets
+     */
+    if (so->so_state & SS_ISFCONNECTING)
+    {
+        Log2(("connecting %R[natsock] catched\n", so));
+        /* Connected */
+        so->so_state &= ~SS_ISFCONNECTING;
+
+        /*
+         * This should be probably guarded by PROBE_CONN too. Anyway,
+         * we disable it on OS/2 because the below send call returns
+         * EFAULT which causes the opened TCP socket to close right
+         * after it has been opened and connected.
+         */
+#ifndef RT_OS_OS2
+    ret = send(so->s, (const char *)&ret, 0, 0);
+    if (ret < 0)
+    {
+        /* XXXXX Must fix, zero bytes is a NOP */
+        if (   errno == EAGAIN
+            || errno == EWOULDBLOCK
+            || errno == EINPROGRESS
+            || errno == ENOTCONN)
+        {
+            LogFlowFunc(("LEAVE: true"));
+            return false;
+        }
+
+        /* else failed */
+        so->so_state = SS_NOFDREF;
+    }
+    /* else so->so_state &= ~SS_ISFCONNECTING; */
+#endif
+
+        /*
+         * Continue tcp_input
+         */
+        TCP_INPUT(pData, (struct mbuf *)NULL, sizeof(struct ip), so);
+        /* continue; */
+    }
+    else if (!fConnectOnly)
+        SOWRITE(ret, pData, so);
+    /*
+     * XXX If we wrote something (a lot), there could be the need
+     * for a window update. In the worst case, the remote will send
+     * a window probe to get things going again.
+     */
+    LogFlowFunc(("LEAVE: true"));
+    return true;
+}
+
 #if defined(RT_OS_WINDOWS)
 void slirp_select_poll(PNATState pData, int fTimeout, int fIcmp)
@@ -1195,6 +1252,8 @@
             if (WIN_CHECK_FD_SET(so, NetworkEvents, connectfds))
             {
-                TCP_ENGAGE_EVENT2(so, readfds, acceptds);
-                goto dont_read_now;
+                /* Finish connection first */
+                /* should we ignore return value? */
+                bool fRet = slirpConnectOrWrite(pData, so, true);
+                LogFunc(("fRet:%RTbool\n", fRet));
             }
 #endif
@@ -1213,7 +1272,4 @@
             if (RT_LIKELY(ret > 0))
                 TCP_OUTPUT(pData, sototcpcb(so));
-#ifdef NAT_CONNECT_EXPERIMENT
-dont_read_now:;
-#endif
         }
 
@@ -1259,49 +1315,6 @@
             )
         {
-            /*
-             * Check for non-blocking, still-connecting sockets
-             */
-            if (so->so_state & SS_ISFCONNECTING)
-            {
-                Log2(("connecting %R[natsock] catched\n", so));
-                /* Connected */
-                so->so_state &= ~SS_ISFCONNECTING;
-
-                /*
-                 * This should be probably guarded by PROBE_CONN too. Anyway,
-                 * we disable it on OS/2 because the below send call returns
-                 * EFAULT which causes the opened TCP socket to close right
-                 * after it has been opened and connected.
-                 */
-#ifndef RT_OS_OS2
-                ret = send(so->s, (const char *)&ret, 0, 0);
-                if (ret < 0)
-                {
-                    /* XXXXX Must fix, zero bytes is a NOP */
-                    if (   errno == EAGAIN
-                        || errno == EWOULDBLOCK
-                        || errno == EINPROGRESS
-                        || errno == ENOTCONN)
-                        CONTINUE(tcp);
-
-                    /* else failed */
-                    so->so_state = SS_NOFDREF;
-                }
-                /* else so->so_state &= ~SS_ISFCONNECTING; */
-#endif
-
-                /*
-                 * Continue tcp_input
-                 */
-                TCP_INPUT(pData, (struct mbuf *)NULL, sizeof(struct ip), so);
-                /* continue; */
-            }
-            else
-                SOWRITE(ret, pData, so);
-            /*
-             * XXX If we wrote something (a lot), there could be the need
-             * for a window update. In the worst case, the remote will send
-             * a window probe to get things going again.
-             */
+            if(!slirpConnectOrWrite(pData, so, false))
+                CONTINUE(tcp);
         }
 
