Index: trunk/src/VBox/Runtime/r3/win/poll-win.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/win/poll-win.cpp	(revision 31955)
+++ trunk/src/VBox/Runtime/r3/win/poll-win.cpp	(revision 31956)
@@ -65,4 +65,6 @@
     /** The events we're waiting for here. */
     uint32_t        fEvents;
+    /** Saved events. */
+    uint32_t        fEventsSaved;
     /** Set if this is the final entry for this handle.
      * If the handle is entered more than once, this will be clear for all but
@@ -94,4 +96,59 @@
 } RTPOLLSETINTERNAL;
 
+/**
+ * Starts polling based on the handle type.
+ */
+static uint32_t rtPollHndStart(RTPOLLSETINTERNAL *pThis, PRTPOLLSETHNDENT pHnd, bool fNoWait)
+{
+    uint32_t fEvents = 0;
+
+    switch (pHnd->enmType)
+    {
+        case RTHANDLETYPE_PIPE:
+            fEvents = rtPipePollStart(pHnd->u.hPipe, pThis, pHnd->fEvents,
+                                      pHnd->fFinalEntry, fNoWait);
+        break;
+
+        case RTHANDLETYPE_SOCKET:
+            fEvents = rtSocketPollStart(pHnd->u.hSocket, pThis, pHnd->fEvents,
+                                        pHnd->fFinalEntry, fNoWait);
+            break;
+
+        default:
+            AssertFailed();
+            fEvents = UINT32_MAX;
+            break;
+    }
+
+    return fEvents;
+}
+
+/**
+ * Cleans up polling based on the handle type.
+ */
+static uint32_t rtPollHndDone(PRTPOLLSETHNDENT pHnd)
+{
+    uint32_t fEvents = 0;
+
+    switch (pHnd->enmType)
+    {
+        case RTHANDLETYPE_PIPE:
+            fEvents = rtPipePollDone(pHnd->u.hPipe, pHnd->fEvents,
+                                     pHnd->fFinalEntry);
+            break;
+
+        case RTHANDLETYPE_SOCKET:
+            fEvents = rtSocketPollDone(pHnd->u.hSocket, pHnd->fEvents,
+                                       pHnd->fFinalEntry);
+            break;
+
+        default:
+            AssertFailed();
+            fEvents = UINT32_MAX;
+            break;
+    }
+
+    return fEvents;
+}
 
 /**
@@ -125,21 +182,12 @@
     for (i = 0; i < cHandles; i++)
     {
-        switch (pThis->aHandles[i].enmType)
-        {
-            case RTHANDLETYPE_PIPE:
-                fEvents = rtPipePollStart(pThis->aHandles[i].u.hPipe, pThis, pThis->aHandles[i].fEvents,
-                                          pThis->aHandles[i].fFinalEntry, fNoWait);
-                break;
-
-            case RTHANDLETYPE_SOCKET:
-                fEvents = rtSocketPollStart(pThis->aHandles[i].u.hSocket, pThis, pThis->aHandles[i].fEvents,
-                                            pThis->aHandles[i].fFinalEntry, fNoWait);
-                break;
-
-            default:
-                AssertFailed();
-                fEvents = UINT32_MAX;
-                break;
-        }
+        if (pThis->aHandles[i].fEventsSaved)
+        {
+            fEvents = pThis->aHandles[i].fEventsSaved;
+            pThis->aHandles[i].fEventsSaved = 0;
+            break;
+        }
+
+        fEvents = rtPollHndStart(pThis, &pThis->aHandles[i], fNoWait);
         if (fEvents)
             break;
@@ -163,20 +211,5 @@
             while (i-- > 0)
             {
-                switch (pThis->aHandles[i].enmType)
-                {
-                    case RTHANDLETYPE_PIPE:
-                        rtPipePollDone(pThis->aHandles[i].u.hPipe, pThis->aHandles[i].fEvents,
-                                       pThis->aHandles[i].fFinalEntry);
-                        break;
-
-                    case RTHANDLETYPE_SOCKET:
-                        rtSocketPollDone(pThis->aHandles[i].u.hSocket, pThis->aHandles[i].fEvents,
-                                         pThis->aHandles[i].fFinalEntry);
-                        break;
-
-                    default:
-                        AssertFailed();
-                        break;
-                }
+                pThis->aHandles[i].fEventsSaved = rtPollHndDone(&pThis->aHandles[i]);
             }
 
@@ -209,36 +242,22 @@
      * Get event (if pending) and do wait cleanup.
      */
-    /** @todo r=aeichner: The loop below overwrites events if
-     *  more than one source has events pending.
-     */
-    i = cHandles;
-    while (i-- > 0)
-    {
-        fEvents = 0;
-        switch (pThis->aHandles[i].enmType)
-        {
-            case RTHANDLETYPE_PIPE:
-                fEvents = rtPipePollDone(pThis->aHandles[i].u.hPipe, pThis->aHandles[i].fEvents,
-                                         pThis->aHandles[i].fFinalEntry);
-                break;
-
-            case RTHANDLETYPE_SOCKET:
-                fEvents = rtSocketPollDone(pThis->aHandles[i].u.hSocket, pThis->aHandles[i].fEvents,
-                                           pThis->aHandles[i].fFinalEntry);
-                break;
-
-            default:
-                AssertFailed();
-                break;
-        }
-        if (fEvents)
-        {
-            Assert(fEvents != UINT32_MAX);
-            if (pfEvents)
-                *pfEvents = fEvents;
-            if (pid)
-                *pid = pThis->aHandles[i].id;
-            rc = VINF_SUCCESS;
-        }
+    for (unsigned i = 0; i < cHandles; i++)
+    {
+        if (!fEvents)
+        {
+            fEvents = rtPollHndDone(&pThis->aHandles[i]);
+
+            if (fEvents)
+            {
+                Assert(fEvents != UINT32_MAX);
+                if (pfEvents)
+                 *pfEvents = fEvents;
+                if (pid)
+                 *pid = pThis->aHandles[i].id;
+                rc = VINF_SUCCESS;
+            }
+        }
+        else
+            pThis->aHandles[i].fEventsSaved = rtPollHndDone(&pThis->aHandles[i]);
     }
 
