VirtualBox

Ignore:
Timestamp:
May 2, 2016 11:58:20 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106983
Message:

Main/USBProxyBackendUsbIp: Fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/generic/USBProxyBackendUsbIp.cpp

    r60755 r60785  
    499499                    rc = VERR_NET_SHUTDOWN;
    500500
    501                 if (RT_SUCCESS(rc))
     501                /*
     502                 * If we are in the none state again we received the previous request
     503                 * and have a new device list to compare the old against.
     504                 */
     505                if (m->enmRecvState == kUsbIpRecvState_None)
    502506                {
    503                     /*
    504                      * If we are in the none state again we received the previous request
    505                      * and have a new device list to compare the old against.
    506                      */
    507                     if (m->enmRecvState == kUsbIpRecvState_None)
    508                     {
    509                         if (hasDevListChanged(m->pHead))
    510                             fDeviceListChangedOrWokenUp = true;
    511 
    512                         /* Update to the new list in any case now that we have it anyway. */
    513                         RTSemFastMutexRequest(m->hMtxDevices);
    514                         freeDeviceList(m->pUsbDevicesCur);
    515                         m->cUsbDevicesCur = m->cDevicesCur;
    516                         m->pUsbDevicesCur = m->pHead;
    517                         RTSemFastMutexRelease(m->hMtxDevices);
    518 
    519                         m->pHead = NULL;
    520                         resetRecvState();
    521                     }
     507                    if (hasDevListChanged(m->pHead))
     508                        fDeviceListChangedOrWokenUp = true;
     509
     510                    /* Update to the new list in any case now that we have it anyway. */
     511                    RTSemFastMutexRequest(m->hMtxDevices);
     512                    freeDeviceList(m->pUsbDevicesCur);
     513                    m->cUsbDevicesCur = m->cDevicesCur;
     514                    m->pUsbDevicesCur = m->pHead;
     515                    RTSemFastMutexRelease(m->hMtxDevices);
     516
     517                    m->pHead = NULL;
     518                    resetRecvState();
    522519                }
    523                 else if (rc == VERR_NET_SHUTDOWN || rc == VERR_BROKEN_PIPE || rc == VERR_NET_CONNECTION_RESET_BY_PEER)
     520
     521                /* Current USB/IP server closes the connection after each request, don't abort but try again. */
     522                if (rc == VERR_NET_SHUTDOWN || rc == VERR_BROKEN_PIPE || rc == VERR_NET_CONNECTION_RESET_BY_PEER)
    524523                {
    525524                    Log(("USB/IP: Lost connection to host \"%s\", trying to reconnect...\n", m->pszHost));
     
    573572    PUSBDEVICE pFirst = NULL;
    574573    PUSBDEVICE *ppNext = &pFirst;
     574
     575    LogFlowThisFunc(("\n"));
    575576
    576577    /* Create a deep copy of the device list. */
     
    614615    RTSemFastMutexRelease(m->hMtxDevices);
    615616
     617    LogFlowThisFunc(("returning %#p\n", pFirst));
    616618    return pFirst;
    617619}
     
    641643void USBProxyBackendUsbIp::resetRecvState()
    642644{
     645    LogFlowFunc(("\n"));
    643646    freeDeviceList(m->pHead);
    644647    m->pHead          = NULL;
     
    649652    m->pbRecvBuf      = &m->Scratch.abRecv[0];
    650653    m->cDevicesLeft   = 0;
     654    LogFlowFunc(("\n"));
    651655}
    652656
     
    658662void USBProxyBackendUsbIp::disconnect()
    659663{
     664    LogFlowFunc(("\n"));
     665
    660666    if (m->hSocket != NIL_RTSOCKET)
    661667    {
     
    668674
    669675    resetRecvState();
     676    LogFlowFunc(("returns\n"));
    670677}
    671678
     
    677684int USBProxyBackendUsbIp::reconnect()
    678685{
     686    LogFlowFunc(("\n"));
     687
    679688    /* Make sure we are disconnected. */
    680689    disconnect();
     
    699708    }
    700709
     710    LogFlowFunc(("returns rc=%Rrc\n", rc));
    701711    return rc;
    702712}
     
    710720{
    711721    int rc = VINF_SUCCESS;
     722
     723    LogFlowFunc(("\n"));
    712724
    713725    /*
     
    731743    }
    732744
     745    LogFlowFunc(("returns rc=%Rrc\n", rc));
    733746    return rc;
    734747}
     
    742755void USBProxyBackendUsbIp::advanceState(USBIPRECVSTATE enmRecvState)
    743756{
     757    LogFlowFunc(("enmRecvState=%u\n", enmRecvState));
     758
    744759    switch (enmRecvState)
    745760    {
     
    770785
    771786    m->enmRecvState = enmRecvState;
     787    LogFlowFunc(("returns\n"));
    772788}
    773789
     
    783799    size_t cbRecvd = 0;
    784800
     801    LogFlowFunc(("\n"));
     802
    785803    do
    786804    {
    787805        rc = RTTcpReadNB(m->hSocket, m->pbRecvBuf, m->cbResidualRecv, &cbRecvd);
     806
     807        LogFlowFunc(("RTTcpReadNB(%#p, %#p, %zu, %zu) -> %Rrc\n",
     808                     m->hSocket, m->pbRecvBuf, m->cbResidualRecv, cbRecvd));
     809
    788810        if (RT_SUCCESS(rc))
    789811        {
     
    791813            m->pbRecvBuf      += cbRecvd;
    792814            /* In case we received everything for the current state process the data. */
    793             if (!m->cbResidualRecv)
     815            if (   !m->cbResidualRecv
     816                && cbRecvd > 0)
    794817            {
    795818                rc = processData();
     
    801824    } while (RT_SUCCESS(rc) && cbRecvd > 0);
    802825
     826    LogFlowFunc(("returns rc=%Rrc\n", rc));
    803827    return rc;
    804828}
     
    899923int USBProxyBackendUsbIp::addDeviceToList(PUsbIpExportedDevice pDev)
    900924{
     925    int rc = VINF_SUCCESS;
    901926    PUSBDEVICE pNew = (PUSBDEVICE)RTMemAllocZ(sizeof(USBDEVICE));
    902927    if (!pNew)
     
    910935    /* Make sure the Bus id is 0 terminated. */
    911936    pDev->szBusId[31] = '\0';
    912     int rc = RTStrAPrintf((char **)&pNew->pszAddress, "usbip://%s:%u:%s", m->pszHost, m->uPort, &pDev->szBusId[0]);
    913     if (RT_SUCCESS(rc))
     937    pNew->pszAddress = RTStrAPrintf2("usbip://%s:%u:%s", m->pszHost, m->uPort, &pDev->szBusId[0]);
     938    if (RT_LIKELY(pNew->pszAddress))
    914939    {
    915940        pNew->idVendor           = pDev->u16VendorId;
     
    966991        m->cDevicesCur++;
    967992    }
     993    else
     994        rc = VERR_NO_STR_MEMORY;
    968995
    969996    if (RT_FAILURE(rc))
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette