Index: trunk/src/VBox/Main/src-server/generic/USBProxyBackendUsbIp.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/generic/USBProxyBackendUsbIp.cpp	(revision 60755)
+++ trunk/src/VBox/Main/src-server/generic/USBProxyBackendUsbIp.cpp	(revision 60785)
@@ -499,27 +499,26 @@
                     rc = VERR_NET_SHUTDOWN;
 
-                if (RT_SUCCESS(rc))
+                /*
+                 * If we are in the none state again we received the previous request
+                 * and have a new device list to compare the old against.
+                 */
+                if (m->enmRecvState == kUsbIpRecvState_None)
                 {
-                    /*
-                     * If we are in the none state again we received the previous request
-                     * and have a new device list to compare the old against.
-                     */
-                    if (m->enmRecvState == kUsbIpRecvState_None)
-                    {
-                        if (hasDevListChanged(m->pHead))
-                            fDeviceListChangedOrWokenUp = true;
-
-                        /* Update to the new list in any case now that we have it anyway. */
-                        RTSemFastMutexRequest(m->hMtxDevices);
-                        freeDeviceList(m->pUsbDevicesCur);
-                        m->cUsbDevicesCur = m->cDevicesCur;
-                        m->pUsbDevicesCur = m->pHead;
-                        RTSemFastMutexRelease(m->hMtxDevices);
-
-                        m->pHead = NULL;
-                        resetRecvState();
-                    }
+                    if (hasDevListChanged(m->pHead))
+                        fDeviceListChangedOrWokenUp = true;
+
+                    /* Update to the new list in any case now that we have it anyway. */
+                    RTSemFastMutexRequest(m->hMtxDevices);
+                    freeDeviceList(m->pUsbDevicesCur);
+                    m->cUsbDevicesCur = m->cDevicesCur;
+                    m->pUsbDevicesCur = m->pHead;
+                    RTSemFastMutexRelease(m->hMtxDevices);
+
+                    m->pHead = NULL;
+                    resetRecvState();
                 }
-                else if (rc == VERR_NET_SHUTDOWN || rc == VERR_BROKEN_PIPE || rc == VERR_NET_CONNECTION_RESET_BY_PEER)
+
+                /* Current USB/IP server closes the connection after each request, don't abort but try again. */
+                if (rc == VERR_NET_SHUTDOWN || rc == VERR_BROKEN_PIPE || rc == VERR_NET_CONNECTION_RESET_BY_PEER)
                 {
                     Log(("USB/IP: Lost connection to host \"%s\", trying to reconnect...\n", m->pszHost));
@@ -573,4 +572,6 @@
     PUSBDEVICE pFirst = NULL;
     PUSBDEVICE *ppNext = &pFirst;
+
+    LogFlowThisFunc(("\n"));
 
     /* Create a deep copy of the device list. */
@@ -614,4 +615,5 @@
     RTSemFastMutexRelease(m->hMtxDevices);
 
+    LogFlowThisFunc(("returning %#p\n", pFirst));
     return pFirst;
 }
@@ -641,4 +643,5 @@
 void USBProxyBackendUsbIp::resetRecvState()
 {
+    LogFlowFunc(("\n"));
     freeDeviceList(m->pHead);
     m->pHead          = NULL;
@@ -649,4 +652,5 @@
     m->pbRecvBuf      = &m->Scratch.abRecv[0];
     m->cDevicesLeft   = 0;
+    LogFlowFunc(("\n"));
 }
 
@@ -658,4 +662,6 @@
 void USBProxyBackendUsbIp::disconnect()
 {
+    LogFlowFunc(("\n"));
+
     if (m->hSocket != NIL_RTSOCKET)
     {
@@ -668,4 +674,5 @@
 
     resetRecvState();
+    LogFlowFunc(("returns\n"));
 }
 
@@ -677,4 +684,6 @@
 int USBProxyBackendUsbIp::reconnect()
 {
+    LogFlowFunc(("\n"));
+
     /* Make sure we are disconnected. */
     disconnect();
@@ -699,4 +708,5 @@
     }
 
+    LogFlowFunc(("returns rc=%Rrc\n", rc));
     return rc;
 }
@@ -710,4 +720,6 @@
 {
     int rc = VINF_SUCCESS;
+
+    LogFlowFunc(("\n"));
 
     /*
@@ -731,4 +743,5 @@
     }
 
+    LogFlowFunc(("returns rc=%Rrc\n", rc));
     return rc;
 }
@@ -742,4 +755,6 @@
 void USBProxyBackendUsbIp::advanceState(USBIPRECVSTATE enmRecvState)
 {
+    LogFlowFunc(("enmRecvState=%u\n", enmRecvState));
+
     switch (enmRecvState)
     {
@@ -770,4 +785,5 @@
 
     m->enmRecvState = enmRecvState;
+    LogFlowFunc(("returns\n"));
 }
 
@@ -783,7 +799,13 @@
     size_t cbRecvd = 0;
 
+    LogFlowFunc(("\n"));
+
     do
     {
         rc = RTTcpReadNB(m->hSocket, m->pbRecvBuf, m->cbResidualRecv, &cbRecvd);
+
+        LogFlowFunc(("RTTcpReadNB(%#p, %#p, %zu, %zu) -> %Rrc\n",
+                     m->hSocket, m->pbRecvBuf, m->cbResidualRecv, cbRecvd));
+
         if (RT_SUCCESS(rc))
         {
@@ -791,5 +813,6 @@
             m->pbRecvBuf      += cbRecvd;
             /* In case we received everything for the current state process the data. */
-            if (!m->cbResidualRecv)
+            if (   !m->cbResidualRecv
+                && cbRecvd > 0)
             {
                 rc = processData();
@@ -801,4 +824,5 @@
     } while (RT_SUCCESS(rc) && cbRecvd > 0);
 
+    LogFlowFunc(("returns rc=%Rrc\n", rc));
     return rc;
 }
@@ -899,4 +923,5 @@
 int USBProxyBackendUsbIp::addDeviceToList(PUsbIpExportedDevice pDev)
 {
+    int rc = VINF_SUCCESS;
     PUSBDEVICE pNew = (PUSBDEVICE)RTMemAllocZ(sizeof(USBDEVICE));
     if (!pNew)
@@ -910,6 +935,6 @@
     /* Make sure the Bus id is 0 terminated. */
     pDev->szBusId[31] = '\0';
-    int rc = RTStrAPrintf((char **)&pNew->pszAddress, "usbip://%s:%u:%s", m->pszHost, m->uPort, &pDev->szBusId[0]);
-    if (RT_SUCCESS(rc))
+    pNew->pszAddress = RTStrAPrintf2("usbip://%s:%u:%s", m->pszHost, m->uPort, &pDev->szBusId[0]);
+    if (RT_LIKELY(pNew->pszAddress))
     {
         pNew->idVendor           = pDev->u16VendorId;
@@ -966,4 +991,6 @@
         m->cDevicesCur++;
     }
+    else
+        rc = VERR_NO_STR_MEMORY;
 
     if (RT_FAILURE(rc))
