VirtualBox

Changeset 100288 in vbox for trunk/src/VBox/GuestHost


Ignore:
Timestamp:
Jun 26, 2023 8:02:07 AM (20 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158003
Message:

Shared Clipboard: More bugfixes for transfers HTTP server. bugref:9437

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers-http.cpp

    r100239 r100288  
    9393static const char *shClTransferHttpServerGetHost(PSHCLHTTPSERVER pSrv);
    9494static int shClTransferHttpServerDestroyTransfer(PSHCLHTTPSERVER pSrv, PSHCLHTTPSERVERTRANSFER pSrvTx);
    95 static SHCLHTTPSERVERSTATUS shclTransferHttpServerSetStatusLocked(PSHCLHTTPSERVER pSrv, SHCLHTTPSERVERSTATUS enmStatus);
     95static SHCLHTTPSERVERSTATUS shclTransferHttpServerSetStatusLocked(PSHCLHTTPSERVER pSrv, SHCLHTTPSERVERSTATUS fStatus);
    9696
    9797
     
    430430}
    431431
    432 /** @copydoc RTHTTPSERVERCALLBACKS::pfnDestroy */
    433 static DECLCALLBACK(int) shClTransferHttpDestroy(PRTHTTPCALLBACKDATA pData)
    434 {
    435     PSHCLHTTPSERVER pThis = (PSHCLHTTPSERVER)pData->pvUser;
    436     Assert(pData->cbUser == sizeof(SHCLHTTPSERVER));
    437 
    438     return shClTransferHttpServerDestroyInternal(pThis);
    439 }
    440 
    441432
    442433/*********************************************************************************************************************************
     
    449440 * @returns VBox status code.
    450441 * @param   pSrv                Shared Clipboard HTTP server instance to destroy.
     442 *
     443 * @note    Caller needs to take the critical section.
    451444 */
    452445static int shClTransferHttpServerDestroyInternal(PSHCLHTTPSERVER pSrv)
    453446{
     447    Assert(RTCritSectIsOwner(&pSrv->CritSect));
     448
    454449    LogFlowFuncEnter();
    455450
    456     if (!ASMAtomicReadBool(&pSrv->fInitialized))
    457         return VINF_SUCCESS;
    458 
    459451    ASMAtomicXchgBool(&pSrv->fInitialized, false);
    460 
    461     shClTransferHttpServerLock(pSrv);
    462452
    463453    int rc = VINF_SUCCESS;
     
    475465    pSrv->hHTTPServer = NIL_RTHTTPSERVER;
    476466
    477     shClTransferHttpServerUnlock(pSrv);
     467    shClTransferHttpServerUnlock(pSrv); /* Unlock critical section taken by the caller before deleting it. */
    478468
    479469    if (RTCritSectIsInitialized(&pSrv->CritSect))
     
    572562    AssertReturn(!shClTransferHttpServerPortIsBuggy(uPort), VERR_ADDRESS_CONFLICT);
    573563
     564    shClTransferHttpServerLock(pSrv);
     565
    574566    RTHTTPSERVERCALLBACKS Callbacks;
    575567    RT_ZERO(Callbacks);
     
    581573    Callbacks.pfnClose         = shClTransferHttpClose;
    582574    Callbacks.pfnQueryInfo     = shClTransferHttpQueryInfo;
    583     Callbacks.pfnDestroy       = shClTransferHttpDestroy;
    584575
    585576    /* Note: The server always and *only* runs against the localhost interface. */
     
    592583
    593584        LogRel2(("Shared Clipboard: HTTP server started at port %RU16\n", pSrv->uPort));
    594     }
     585
     586        rc = shclTransferHttpServerSetStatusLocked(pSrv, SHCLHTTPSERVERSTATUS_STARTED);
     587    }
     588
     589    shClTransferHttpServerUnlock(pSrv);
    595590
    596591    if (RT_FAILURE(rc))
     
    661656int ShClTransferHttpServerStop(PSHCLHTTPSERVER pSrv)
    662657{
    663      if (!ASMAtomicReadBool(&pSrv->fRunning))
    664          return VINF_SUCCESS;
    665 
    666      Assert(pSrv->hHTTPServer != NIL_RTHTTPSERVER);
    667 
    668      int rc = RTHttpServerDestroy(pSrv->hHTTPServer);
    669      if (RT_SUCCESS(rc))
     658     LogFlowFuncEnter();
     659
     660     shClTransferHttpServerLock(pSrv);
     661
     662     int rc = VINF_SUCCESS;
     663
     664     if (ASMAtomicReadBool(&pSrv->fRunning))
    670665     {
    671          pSrv->hHTTPServer = NIL_RTHTTPSERVER;
    672          ASMAtomicXchgBool(&pSrv->fRunning, false);
    673          LogRel2(("Shared Clipboard: HTTP server stopped\n"));
     666         Assert(pSrv->hHTTPServer != NIL_RTHTTPSERVER);
     667
     668         rc = RTHttpServerDestroy(pSrv->hHTTPServer);
     669         if (RT_SUCCESS(rc))
     670         {
     671             pSrv->hHTTPServer = NIL_RTHTTPSERVER;
     672             pSrv->fRunning    = false;
     673
     674             /* Let any eventual waiters know. */
     675             shclTransferHttpServerSetStatusLocked(pSrv, SHCLHTTPSERVERSTATUS_STOPPED);
     676
     677             LogRel2(("Shared Clipboard: HTTP server stopped\n"));
     678         }
    674679     }
    675      else
     680
     681     if (RT_FAILURE(rc))
    676682         LogRel(("Shared Clipboard: HTTP server failed to stop, rc=%Rrc\n", rc));
    677683
     684     shClTransferHttpServerUnlock(pSrv);
     685
     686     LogFlowFuncLeaveRC(rc);
    678687     return rc;
    679688}
     
    693702        return rc;
    694703
     704    if (!ASMAtomicReadBool(&pSrv->fInitialized))
     705        return VINF_SUCCESS;
     706
     707    shClTransferHttpServerLock(pSrv);
     708
    695709    rc = shClTransferHttpServerDestroyInternal(pSrv);
     710
     711    /* Unlock not needed anymore, as the critical section got destroyed. */
     712
    696713    return rc;
    697714}
     
    719736 *                              The pointer will be invalid on success.
    720737 *
    721  * @note    Caller must take the server critical section.
     738 * @note    Caller needs to take the server critical section.
    722739 */
    723740static int shClTransferHttpServerDestroyTransfer(PSHCLHTTPSERVER pSrv, PSHCLHTTPSERVERTRANSFER pSrvTx)
     
    834851    shClTransferHttpServerLock(pSrv);
    835852
    836     AssertReturn(pSrv->cTransfers, VERR_WRONG_ORDER);
    837 
    838853    int rc = VINF_SUCCESS;
    839854
     
    862877 * @returns New status set.
    863878 * @param   pSrv                HTTP server instance to set status for.
    864  * @param   enmStatus           New status to set.
     879 * @param   fStatus             New status to set.
    865880 *
    866881 * @note    Caller needs to take critical section.
     
    968983
    969984    const uint32_t cTransfers = pSrv->cTransfers;
     985    LogFlowFunc(("cTransfers=%RU32\n", cTransfers));
    970986
    971987    shClTransferHttpServerUnlock(pSrv);
     
    10441060 *
    10451061 * @returns VBox status code.
     1062 * @retval  VERR_STATE_CHANGED if the HTTP server status has changed (not running anymore).
    10461063 * @param   pSrv                HTTP server instance to wait for.
    10471064 * @param   fStatus             Status to wait for.
     
    10521069{
    10531070    AssertPtrReturn(pSrv, VERR_INVALID_POINTER);
     1071    AssertMsgReturn(ASMAtomicReadBool(&pSrv->fInitialized), ("Server not initialized yet\n"), VERR_WRONG_ORDER);
    10541072
    10551073    shClTransferHttpServerLock(pSrv);
     
    10631081    while (RTTimeMilliTS() - tsStartMs <= msTimeout)
    10641082    {
     1083        if (   !pSrv->fInitialized
     1084            || !pSrv->fRunning)
     1085        {
     1086            rc = VERR_STATE_CHANGED;
     1087            break;
     1088        }
     1089
    10651090        shClTransferHttpServerUnlock(pSrv); /* Leave lock before waiting. */
    10661091
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