Index: /trunk/src/VBox/Devices/Serial/DrvTCP.cpp
===================================================================
--- /trunk/src/VBox/Devices/Serial/DrvTCP.cpp	(revision 84156)
+++ /trunk/src/VBox/Devices/Serial/DrvTCP.cpp	(revision 84157)
@@ -133,4 +133,46 @@
 
 
+/**
+ * Checks the wakeup pipe for events.
+ *
+ * @returns VBox status code.
+ * @param   pThis                   The TCP driver instance.
+ * @param   fEvts                   Event mask to set if a new connection arrived.
+ */
+static int drvTcpWakeupPipeCheckForRequest(PDRVTCP pThis, uint32_t fEvts)
+{
+    uint8_t bReason;
+    size_t cbRead = 0;
+    int rc = RTPipeRead(pThis->hPipeWakeR, &bReason, 1, &cbRead);
+    if (rc == VINF_TRY_AGAIN) /* Nothing there so we are done here. */
+        rc = VINF_SUCCESS;
+    else if (RT_SUCCESS(rc))
+    {
+        if (bReason == DRVTCP_WAKEUP_REASON_EXTERNAL)
+            rc = VERR_INTERRUPTED;
+        else if (bReason == DRVTCP_WAKEUP_REASON_NEW_CONNECTION)
+        {
+            Assert(pThis->hTcpSock == NIL_RTSOCKET);
+
+            /* Read the socket handle. */
+            RTSOCKET hTcpSockNew = NIL_RTSOCKET;
+            rc = RTPipeReadBlocking(pThis->hPipeWakeR, &hTcpSockNew, sizeof(hTcpSockNew), NULL);
+            AssertRC(rc);
+
+            /* Always include error event. */
+            fEvts |= RTPOLL_EVT_ERROR;
+            rc = RTPollSetAddSocket(pThis->hPollSet, hTcpSockNew,
+                                    fEvts, DRVTCP_POLLSET_ID_SOCKET);
+            if (RT_SUCCESS(rc))
+                pThis->hTcpSock = hTcpSockNew;
+        }
+        else
+            AssertMsgFailed(("Unknown wakeup reason in pipe %u\n", bReason));
+    }
+
+    return rc;
+}
+
+
 /** @interface_method_impl{PDMISTREAM,pfnPoll} */
 static DECLCALLBACK(int) drvTcpPoll(PPDMISTREAM pInterface, uint32_t fEvts, uint32_t *pfEvts, RTMSINTERVAL cMillies)
@@ -147,4 +189,22 @@
         rc = RTPollSetEventsChange(pThis->hPollSet, DRVTCP_POLLSET_ID_SOCKET, fEvts);
         AssertRC(rc);
+    }
+    else
+    {
+        /*
+         * Check whether new connection arrived first so we don't miss it in case
+         * the guest is constantly writing data and we always end up here.
+         */
+        rc = drvTcpWakeupPipeCheckForRequest(pThis, fEvts);
+        if (   pThis->hTcpSock == NIL_RTSOCKET
+            && (fEvts & RTPOLL_EVT_WRITE))
+        {
+            /*
+             * Just pretend we can always write to not fill up any buffers and block the guest
+             * from sending data.
+             */
+            *pfEvts |= RTPOLL_EVT_WRITE;
+            return rc;
+        }
     }
 
@@ -181,29 +241,5 @@
                 {
                     /* We got woken up, drain the pipe and return. */
-                    uint8_t bReason;
-                    size_t cbRead = 0;
-                    rc = RTPipeRead(pThis->hPipeWakeR, &bReason, 1, &cbRead);
-                    AssertRC(rc);
-
-                    if (bReason == DRVTCP_WAKEUP_REASON_EXTERNAL)
-                        rc = VERR_INTERRUPTED;
-                    else if (bReason == DRVTCP_WAKEUP_REASON_NEW_CONNECTION)
-                    {
-                        Assert(pThis->hTcpSock == NIL_RTSOCKET);
-
-                        /* Read the socket handle. */
-                        RTSOCKET hTcpSockNew = NIL_RTSOCKET;
-                        rc = RTPipeReadBlocking(pThis->hPipeWakeR, &hTcpSockNew, sizeof(hTcpSockNew), NULL);
-                        AssertRC(rc);
-
-                        /* Always include error event. */
-                        fEvts |= RTPOLL_EVT_ERROR;
-                        rc = RTPollSetAddSocket(pThis->hPollSet, hTcpSockNew,
-                                                fEvts, DRVTCP_POLLSET_ID_SOCKET);
-                        if (RT_SUCCESS(rc))
-                            pThis->hTcpSock = hTcpSockNew;
-                    }
-                    else
-                        AssertMsgFailed(("Unknown wakeup reason in pipe %u\n", bReason));
+                    rc = drvTcpWakeupPipeCheckForRequest(pThis, fEvts);
                 }
                 else
@@ -319,6 +355,5 @@
         }
     }
-    else
-        *pcbWrite = 0;
+    /* else Just pretend we wrote everything to not block. */
 
     LogFlow(("%s: returns %Rrc *pcbWrite=%zu\n", __FUNCTION__, rc, *pcbWrite));
