VirtualBox

Changeset 65854 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Feb 23, 2017 11:48:49 AM (8 years ago)
Author:
vboxsync
Message:

Main/USBProxyBackendUsbIp: Don't prevent VBoxSVC from starting when the server is not reachable, just try to reconnect every 3 seconds. Smaller other fixes for stale USB device lists when the server is not reachable and a fix for saving the same USB source multiple times

Location:
trunk/src/VBox/Main
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/USBProxyBackend.h

    r65088 r65854  
    4848
    4949    // public initializer/uninitializer for internal purposes only
    50     virtual int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress);
     50    virtual int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     51                     const com::Utf8Str &strAddress, bool fLoadingSettings);
    5152    virtual void uninit();
    5253
     
    147148    DECLARE_EMPTY_CTOR_DTOR(USBProxyBackendDarwin)
    148149
    149     int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress);
     150    int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     151             const com::Utf8Str &strAddress, bool fLoadingSettings);
    150152    void uninit();
    151153
     
    196198    DECLARE_EMPTY_CTOR_DTOR(USBProxyBackendLinux)
    197199
    198     int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress);
     200    int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     201             const com::Utf8Str &strAddress, bool fLoadingSettings);
    199202    void uninit();
    200203
     
    287290    DECLARE_EMPTY_CTOR_DTOR(USBProxyBackendSolaris)
    288291
    289     int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress);
     292    int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     293             const com::Utf8Str &strAddress, bool fLoadingSettings);
    290294    void uninit();
    291295
     
    322326    DECLARE_EMPTY_CTOR_DTOR(USBProxyBackendWindows)
    323327
    324     int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress);
     328    int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     329             const com::Utf8Str &strAddress, bool fLoadingSettings);
    325330    void uninit();
    326331
     
    353358    DECLARE_EMPTY_CTOR_DTOR(USBProxyBackendFreeBSD)
    354359
    355     int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress);
     360    int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     361             const com::Utf8Str &strAddress, bool fLoadingSettings);
    356362    void uninit();
    357363
     
    404410    DECLARE_EMPTY_CTOR_DTOR(USBProxyBackendUsbIp)
    405411
    406     int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress);
     412    int init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     413             const com::Utf8Str &strAddress, bool fLoadingSettings);
    407414    void uninit();
    408415
  • trunk/src/VBox/Main/include/USBProxyService.h

    r62485 r65854  
    106106    HRESULT createUSBDeviceSource(const com::Utf8Str &aBackend, const com::Utf8Str &aId,
    107107                                  const com::Utf8Str &aAddress, const std::vector<com::Utf8Str> &aPropertyNames,
    108                                   const std::vector<com::Utf8Str> &aPropertyValues);
     108                                  const std::vector<com::Utf8Str> &aPropertyValues, bool fLoadingSettings);
    109109
    110110private:
  • trunk/src/VBox/Main/src-server/HostImpl.cpp

    r65120 r65854  
    17841784
    17851785    data.llUSBDeviceFilters.clear();
     1786    data.llUSBDeviceSources.clear();
    17861787
    17871788    for (USBDeviceFilterList::const_iterator it = m->llUSBDeviceFilters.begin();
  • trunk/src/VBox/Main/src-server/USBProxyBackend.cpp

    r65529 r65854  
    6666 * Stub needed as long as the class isn't virtual
    6767 */
    68 int USBProxyBackend::init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress)
    69 {
     68int USBProxyBackend::init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     69                          const com::Utf8Str &strAddress, bool fLoadingSettings)
     70{
     71    RT_NOREF1(fLoadingSettings);
     72
    7073    m_pUsbProxyService    = pUsbProxyService;
    7174    mThread               = NIL_RTTHREAD;
  • trunk/src/VBox/Main/src-server/USBProxyService.cpp

    r65457 r65854  
    8181# endif
    8282    UsbProxyBackendHost.createObject();
    83     int vrc = UsbProxyBackendHost->init(this, Utf8Str("host"), Utf8Str(""));
     83    int vrc = UsbProxyBackendHost->init(this, Utf8Str("host"), Utf8Str(""), false /* fLoadingSettings */);
    8484    if (RT_FAILURE(vrc))
    8585    {
     
    212212    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    213213
    214     HRESULT hrc = createUSBDeviceSource(aBackend, aId, aAddress, aPropertyNames, aPropertyValues);
     214    HRESULT hrc = createUSBDeviceSource(aBackend, aId, aAddress, aPropertyNames,
     215                                        aPropertyValues, false /* fLoadingSettings */);
    215216    if (SUCCEEDED(hrc))
    216217    {
     
    500501        std::vector<com::Utf8Str> vecPropNames, vecPropValues;
    501502        const settings::USBDeviceSource &src = *it;
    502         hrc = createUSBDeviceSource(src.strBackend, src.strName, src.strAddress, vecPropNames, vecPropValues);
     503        hrc = createUSBDeviceSource(src.strBackend, src.strName, src.strAddress,
     504                                    vecPropNames, vecPropValues, true /* fLoadingSettings */);
    503505    }
    504506
     
    892894 * @param   aPropertyNames    Vector of optional property keys the backend supports.
    893895 * @param   aPropertyValues   Vector of optional property values the backend supports.
     896 * @param   fLoadingSettings  Flag whether the USB device source is created while the
     897 *                            settings are loaded or through the Main API.
    894898 */
    895899HRESULT USBProxyService::createUSBDeviceSource(const com::Utf8Str &aBackend, const com::Utf8Str &aId,
    896900                                               const com::Utf8Str &aAddress, const std::vector<com::Utf8Str> &aPropertyNames,
    897                                                const std::vector<com::Utf8Str> &aPropertyValues)
     901                                               const std::vector<com::Utf8Str> &aPropertyValues,
     902                                               bool fLoadingSettings)
    898903{
    899904    HRESULT hrc = S_OK;
     
    923928
    924929        UsbProxyBackend.createObject();
    925         int vrc = UsbProxyBackend->init(this, aId, aAddress);
     930        int vrc = UsbProxyBackend->init(this, aId, aAddress, fLoadingSettings);
    926931        if (RT_FAILURE(vrc))
    927932            hrc = setError(E_FAIL,
  • trunk/src/VBox/Main/src-server/darwin/USBProxyBackendDarwin.cpp

    r62485 r65854  
    5353 * @returns VBox status code.
    5454 */
    55 int USBProxyBackendDarwin::init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress)
    56 {
    57     USBProxyBackend::init(pUsbProxyService, strId, strAddress);
     55int USBProxyBackendDarwin::init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     56                                const com::Utf8Str &strAddress, bool fLoadingSettings)
     57{
     58    USBProxyBackend::init(pUsbProxyService, strId, strAddress, fLoadingSettings);
    5859
    5960    unconst(m_strBackend) = Utf8Str("host");
  • trunk/src/VBox/Main/src-server/freebsd/USBProxyBackendFreeBSD.cpp

    r65539 r65854  
    7676 * @returns S_OK on success and non-fatal failures, some COM error otherwise.
    7777 */
    78 int USBProxyBackendFreeBSD::init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress)
    79 {
    80     USBProxyBackend::init(pUsbProxyService, strId, strAddress);
     78int USBProxyBackendFreeBSD::init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     79                                 const com::Utf8Str &strAddress, bool fLoadingSettings)
     80{
     81    USBProxyBackend::init(pUsbProxyService, strId, strAddress, fLoadingSettings);
    8182
    8283    unconst(m_strBackend) = Utf8Str("host");
  • trunk/src/VBox/Main/src-server/generic/USBProxyBackendUsbIp.cpp

    r65542 r65854  
    280280 * @returns S_OK on success and non-fatal failures, some COM error otherwise.
    281281 */
    282 int USBProxyBackendUsbIp::init(USBProxyService *aUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress)
     282int USBProxyBackendUsbIp::init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     283                               const com::Utf8Str &strAddress, bool fLoadingSettings)
    283284{
    284285    int rc = VINF_SUCCESS;
    285286
    286     USBProxyBackend::init(aUsbProxyService, strId, strAddress);
     287    USBProxyBackend::init(pUsbProxyService, strId, strAddress, fLoadingSettings);
    287288
    288289    unconst(m_strBackend) = Utf8Str("USBIP");
     
    318319                if (RT_SUCCESS(rc))
    319320                {
    320                     /* Connect to the USB/IP host. */
     321                    /*
     322                     * Connect to the USB/IP host. Be more graceful to connection errors
     323                     * if we are instantiated while the settings are loaded to let
     324                     * VBoxSVC start.
     325                     *
     326                     * The worker thread keeps trying to connect every few seconds until
     327                     * either the USB source is removed by the user or the USB server is
     328                     * reachable.
     329                     */
    321330                    rc = reconnect();
    322                     if (RT_SUCCESS(rc))
     331                    if (RT_SUCCESS(rc) || fLoadingSettings)
    323332                        rc = start(); /* Start service thread. */
    324333                }
     
    448457    /* Try to reconnect once when we enter if we lost the connection earlier. */
    449458    if (m->hSocket == NIL_RTSOCKET)
    450         rc = reconnect();
     459        reconnect();
    451460
    452461    /* Query a new device list upon entering. */
    453     if (   RT_SUCCESS(rc)
     462    if (   m->hSocket != NIL_RTSOCKET
    454463        && m->enmRecvState == kUsbIpRecvState_None)
    455464    {
     
    474483        uint32_t fEventsRecv = 0;
    475484
    476         /* Limit the waiting time to 1sec so we can either reconnect or get a new device list. */
     485        /* Limit the waiting time to 3sec so we can either reconnect or get a new device list. */
    477486        if (m->hSocket == NIL_RTSOCKET || m->enmRecvState == kUsbIpRecvState_None)
    478             msWait = RT_MIN(1000, aMillies);
     487            msWait = RT_MIN(3000, aMillies);
    479488
    480489        rc = RTPoll(m->hPollSet, msWait, &fEventsRecv, &uIdReady);
     
    549558                             || rc == VERR_NET_CONNECTION_RESET_BY_PEER
    550559                             || rc == VERR_NET_CONNECTION_REFUSED)
     560                    {
     561                        /* Make sure the device list is clear. */
     562                        RTSemFastMutexRequest(m->hMtxDevices);
     563                        if (m->pUsbDevicesCur)
     564                        {
     565                            freeDeviceList(m->pUsbDevicesCur);
     566                            fDeviceListChangedOrWokenUp = true;
     567                            m->cUsbDevicesCur = 0;
     568                            m->pUsbDevicesCur = NULL;
     569                        }
     570                        RTSemFastMutexRelease(m->hMtxDevices);
    551571                        rc = VINF_SUCCESS;
     572                    }
    552573                }
    553574            }
     
    815836                     m->hSocket, m->pbRecvBuf, m->cbResidualRecv, cbRecvd, rc));
    816837
    817         if (rc == VINF_SUCCESS)
    818         {
    819             Assert(cbRecvd > 0);
     838        if (   rc == VINF_SUCCESS
     839            && cbRecvd > 0)
     840        {
    820841            m->cbResidualRecv -= cbRecvd;
    821842            m->pbRecvBuf      += cbRecvd;
    822843            /* In case we received everything for the current state process the data. */
    823             if (   !m->cbResidualRecv
    824                 && cbRecvd > 0)
     844            if (!m->cbResidualRecv)
    825845            {
    826846                rc = processData();
  • trunk/src/VBox/Main/src-server/linux/USBProxyBackendLinux.cpp

    r62485 r65854  
    8080 * @returns VBox status code.
    8181 */
    82 int USBProxyBackendLinux::init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress)
    83 {
    84     USBProxyBackend::init(pUsbProxyService, strId, strAddress);
     82int USBProxyBackendLinux::init(USBProxyService *pUsbProxyService, const com::Utf8Str &strId,
     83                              const com::Utf8Str &strAddress, bool fLoadingSettings)
     84{
     85    USBProxyBackend::init(pUsbProxyService, strId, strAddress, fLoadingSettings);
    8586
    8687    unconst(m_strBackend) = Utf8Str("host");
  • trunk/src/VBox/Main/src-server/solaris/USBProxyBackendSolaris.cpp

    r63542 r65854  
    7070 * @returns VBox status code.
    7171 */
    72 int USBProxyBackendSolaris::init(USBProxyService *aUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress)
    73 {
    74     USBProxyBackend::init(aUsbProxyService, strId, strAddress);
     72int USBProxyBackendSolaris::init(USBProxyService *aUsbProxyService, const com::Utf8Str &strId,
     73                                 const com::Utf8Str &strAddress, bool fLoadingSettings)
     74{
     75    USBProxyBackend::init(aUsbProxyService, strId, strAddress, fLoadingSettings);
    7576
    7677    unconst(m_strBackend) = Utf8Str("host");
  • trunk/src/VBox/Main/src-server/win/USBProxyBackendWindows.cpp

    r62485 r65854  
    5353 * @returns S_OK on success and non-fatal failures, some COM error otherwise.
    5454 */
    55 int USBProxyBackendWindows::init(USBProxyService *aUsbProxyService, const com::Utf8Str &strId, const com::Utf8Str &strAddress)
    56 {
    57     USBProxyBackend::init(aUsbProxyService, strId, strAddress);
     55int USBProxyBackendWindows::init(USBProxyService *aUsbProxyService, const com::Utf8Str &strId,
     56                                 const com::Utf8Str &strAddress, bool fLoadingSettings)
     57{
     58    USBProxyBackend::init(aUsbProxyService, strId, strAddress, fLoadingSettings);
    5859
    5960    unconst(m_strBackend) = Utf8Str("host");
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