Changeset 100288 in vbox for trunk/src/VBox/GuestHost
- Timestamp:
- Jun 26, 2023 8:02:07 AM (20 months ago)
- svn:sync-xref-src-repo-rev:
- 158003
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers-http.cpp
r100239 r100288 93 93 static const char *shClTransferHttpServerGetHost(PSHCLHTTPSERVER pSrv); 94 94 static int shClTransferHttpServerDestroyTransfer(PSHCLHTTPSERVER pSrv, PSHCLHTTPSERVERTRANSFER pSrvTx); 95 static SHCLHTTPSERVERSTATUS shclTransferHttpServerSetStatusLocked(PSHCLHTTPSERVER pSrv, SHCLHTTPSERVERSTATUS enmStatus);95 static SHCLHTTPSERVERSTATUS shclTransferHttpServerSetStatusLocked(PSHCLHTTPSERVER pSrv, SHCLHTTPSERVERSTATUS fStatus); 96 96 97 97 … … 430 430 } 431 431 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 441 432 442 433 /********************************************************************************************************************************* … … 449 440 * @returns VBox status code. 450 441 * @param pSrv Shared Clipboard HTTP server instance to destroy. 442 * 443 * @note Caller needs to take the critical section. 451 444 */ 452 445 static int shClTransferHttpServerDestroyInternal(PSHCLHTTPSERVER pSrv) 453 446 { 447 Assert(RTCritSectIsOwner(&pSrv->CritSect)); 448 454 449 LogFlowFuncEnter(); 455 450 456 if (!ASMAtomicReadBool(&pSrv->fInitialized))457 return VINF_SUCCESS;458 459 451 ASMAtomicXchgBool(&pSrv->fInitialized, false); 460 461 shClTransferHttpServerLock(pSrv);462 452 463 453 int rc = VINF_SUCCESS; … … 475 465 pSrv->hHTTPServer = NIL_RTHTTPSERVER; 476 466 477 shClTransferHttpServerUnlock(pSrv); 467 shClTransferHttpServerUnlock(pSrv); /* Unlock critical section taken by the caller before deleting it. */ 478 468 479 469 if (RTCritSectIsInitialized(&pSrv->CritSect)) … … 572 562 AssertReturn(!shClTransferHttpServerPortIsBuggy(uPort), VERR_ADDRESS_CONFLICT); 573 563 564 shClTransferHttpServerLock(pSrv); 565 574 566 RTHTTPSERVERCALLBACKS Callbacks; 575 567 RT_ZERO(Callbacks); … … 581 573 Callbacks.pfnClose = shClTransferHttpClose; 582 574 Callbacks.pfnQueryInfo = shClTransferHttpQueryInfo; 583 Callbacks.pfnDestroy = shClTransferHttpDestroy;584 575 585 576 /* Note: The server always and *only* runs against the localhost interface. */ … … 592 583 593 584 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); 595 590 596 591 if (RT_FAILURE(rc)) … … 661 656 int ShClTransferHttpServerStop(PSHCLHTTPSERVER pSrv) 662 657 { 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)) 670 665 { 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 } 674 679 } 675 else 680 681 if (RT_FAILURE(rc)) 676 682 LogRel(("Shared Clipboard: HTTP server failed to stop, rc=%Rrc\n", rc)); 677 683 684 shClTransferHttpServerUnlock(pSrv); 685 686 LogFlowFuncLeaveRC(rc); 678 687 return rc; 679 688 } … … 693 702 return rc; 694 703 704 if (!ASMAtomicReadBool(&pSrv->fInitialized)) 705 return VINF_SUCCESS; 706 707 shClTransferHttpServerLock(pSrv); 708 695 709 rc = shClTransferHttpServerDestroyInternal(pSrv); 710 711 /* Unlock not needed anymore, as the critical section got destroyed. */ 712 696 713 return rc; 697 714 } … … 719 736 * The pointer will be invalid on success. 720 737 * 721 * @note Caller musttake the server critical section.738 * @note Caller needs to take the server critical section. 722 739 */ 723 740 static int shClTransferHttpServerDestroyTransfer(PSHCLHTTPSERVER pSrv, PSHCLHTTPSERVERTRANSFER pSrvTx) … … 834 851 shClTransferHttpServerLock(pSrv); 835 852 836 AssertReturn(pSrv->cTransfers, VERR_WRONG_ORDER);837 838 853 int rc = VINF_SUCCESS; 839 854 … … 862 877 * @returns New status set. 863 878 * @param pSrv HTTP server instance to set status for. 864 * @param enmStatusNew status to set.879 * @param fStatus New status to set. 865 880 * 866 881 * @note Caller needs to take critical section. … … 968 983 969 984 const uint32_t cTransfers = pSrv->cTransfers; 985 LogFlowFunc(("cTransfers=%RU32\n", cTransfers)); 970 986 971 987 shClTransferHttpServerUnlock(pSrv); … … 1044 1060 * 1045 1061 * @returns VBox status code. 1062 * @retval VERR_STATE_CHANGED if the HTTP server status has changed (not running anymore). 1046 1063 * @param pSrv HTTP server instance to wait for. 1047 1064 * @param fStatus Status to wait for. … … 1052 1069 { 1053 1070 AssertPtrReturn(pSrv, VERR_INVALID_POINTER); 1071 AssertMsgReturn(ASMAtomicReadBool(&pSrv->fInitialized), ("Server not initialized yet\n"), VERR_WRONG_ORDER); 1054 1072 1055 1073 shClTransferHttpServerLock(pSrv); … … 1063 1081 while (RTTimeMilliTS() - tsStartMs <= msTimeout) 1064 1082 { 1083 if ( !pSrv->fInitialized 1084 || !pSrv->fRunning) 1085 { 1086 rc = VERR_STATE_CHANGED; 1087 break; 1088 } 1089 1065 1090 shClTransferHttpServerUnlock(pSrv); /* Leave lock before waiting. */ 1066 1091
Note:
See TracChangeset
for help on using the changeset viewer.