Changeset 58290 in vbox for trunk/src/VBox
- Timestamp:
- Oct 17, 2015 9:52:28 PM (9 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
r58089 r58290 1014 1014 #endif 1015 1015 int rc2 = RTLocalIpcSessionClose(hSession); 1016 if (RT_SUCCESS(rc) )1016 if (RT_SUCCESS(rc) && RT_FAILURE(rc2)) 1017 1017 rc = rc2; 1018 1018 } -
trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp
r58282 r58290 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #define LOG_GROUP RTLOGGROUP_LOCALIPC 31 32 #include "internal/iprt.h" 32 33 #include <iprt/localipc.h> … … 37 38 #include <iprt/critsect.h> 38 39 #include <iprt/mem.h> 40 #include <iprt/log.h> 39 41 #include <iprt/poll.h> 40 42 #include <iprt/socket.h> … … 44 46 #include <sys/socket.h> 45 47 #include <sys/un.h> 48 #ifndef RT_OS_OS2 49 # include <sys/poll.h> 50 # include <errno.h> 51 #endif 46 52 #include <fcntl.h> 47 53 #include <unistd.h> … … 226 232 if (RT_SUCCESS(rc)) 227 233 { 234 LogFlow(("RTLocalIpcServerCreate: Created %p (%s)\n", pThis, pThis->Name.sun_path)); 228 235 *phServer = pThis; 229 236 return VINF_SUCCESS; … … 239 246 rc = VERR_NO_MEMORY; 240 247 } 248 Log(("RTLocalIpcServerCreate: failed, rc=%Rrc\n", rc)); 241 249 return rc; 242 250 } … … 258 266 /** 259 267 * Server instance destructor. 268 * 269 * @returns VINF_OBJECT_DESTROYED 260 270 * @param pThis The server instance. 261 271 */ 262 static voidrtLocalIpcServerDtor(PRTLOCALIPCSERVERINT pThis)272 static int rtLocalIpcServerDtor(PRTLOCALIPCSERVERINT pThis) 263 273 { 264 274 pThis->u32Magic = ~RTLOCALIPCSERVER_MAGIC; 265 RTSocketRelease(pThis->hSocket); 275 if (RTSocketRelease(pThis->hSocket) == 0) 276 Log(("rtLocalIpcServerDtor: Released socket\n")); 277 else 278 Log(("rtLocalIpcServerDtor: Socket still has references (impossible?)\n")); 266 279 RTCritSectDelete(&pThis->CritSect); 267 280 unlink(pThis->Name.sun_path); 268 281 RTMemFree(pThis); 282 return VINF_OBJECT_DESTROYED; 269 283 } 270 284 … … 273 287 * Releases a reference to the server instance. 274 288 * 289 * @returns VINF_SUCCESS if only release, VINF_OBJECT_DESTROYED if destroyed. 275 290 * @param pThis The server instance. 276 291 */ 277 DECLINLINE( void) rtLocalIpcServerRelease(PRTLOCALIPCSERVERINT pThis)292 DECLINLINE(int) rtLocalIpcServerRelease(PRTLOCALIPCSERVERINT pThis) 278 293 { 279 294 uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs); 280 295 Assert(cRefs < UINT32_MAX / 2); 281 296 if (!cRefs) 282 rtLocalIpcServerDtor(pThis); 297 return rtLocalIpcServerDtor(pThis); 298 return VINF_SUCCESS; 283 299 } 284 300 … … 294 310 RTCritSectEnter(&pThis->CritSect); 295 311 pThis->fCancelled = true; 312 Log(("rtLocalIpcServerCancel:\n")); 296 313 if (pThis->hListenThread != NIL_RTTHREAD) 297 314 RTThreadPoke(pThis->hListenThread); … … 320 337 321 338 rtLocalIpcServerCancel(pThis); 322 rtLocalIpcServerRelease(pThis); 323 324 return VINF_SUCCESS; 339 return rtLocalIpcServerRelease(pThis); 325 340 } 326 341 … … 385 400 size_t cbAddr = sizeof(Addr); 386 401 RTSOCKET hClient; 402 Log(("RTLocalIpcServerListen: Calling rtSocketAccept...\n")); 387 403 rc = rtSocketAccept(pThis->hSocket, &hClient, (struct sockaddr *)&Addr, &cbAddr); 404 Log(("RTLocalIpcServerListen: rtSocketAccept returns %Rrc.\n", rc)); 388 405 389 406 int rc2 = RTCritSectEnter(&pThis->CritSect); … … 407 424 rc = RTCritSectInit(&pSession->CritSect); 408 425 if (RT_SUCCESS(rc)) 426 { 427 Log(("RTLocalIpcServerListen: Returning new client session: %p\n", pSession)); 409 428 *phClientSession = pSession; 410 else 411 RTMemFree(pSession); 429 break; 430 } 431 432 RTMemFree(pSession); 412 433 } 413 434 else … … 440 461 rtLocalIpcServerRelease(pThis); 441 462 463 Log(("RTLocalIpcServerListen: returns %Rrc\n", rc)); 442 464 return rc; 443 465 } … … 491 513 { 492 514 *phSession = pThis; 515 Log(("RTLocalIpcSessionConnect: Returns new session %p\n", pThis)); 493 516 return VINF_SUCCESS; 494 517 } … … 502 525 rc = VERR_NO_MEMORY; 503 526 } 527 Log(("RTLocalIpcSessionConnect: returns %Rrc\n", rc)); 504 528 return rc; 505 529 } … … 520 544 /** 521 545 * Session instance destructor. 546 * 547 * @returns VINF_OBJECT_DESTROYED 522 548 * @param pThis The server instance. 523 549 */ 524 static voidrtLocalIpcSessionDtor(PRTLOCALIPCSESSIONINT pThis)550 static int rtLocalIpcSessionDtor(PRTLOCALIPCSESSIONINT pThis) 525 551 { 526 552 pThis->u32Magic = ~RTLOCALIPCSESSION_MAGIC; 527 553 if (RTSocketRelease(pThis->hSocket) == 0) 528 pThis->hSocket = NIL_RTSOCKET; 554 Log(("rtLocalIpcSessionDtor: Released socket\n")); 555 else 556 Log(("rtLocalIpcSessionDtor: Socket still has references (impossible?)\n")); 529 557 RTCritSectDelete(&pThis->CritSect); 530 558 RTMemFree(pThis); 559 return VINF_OBJECT_DESTROYED; 531 560 } 532 561 … … 535 564 * Releases a reference to the session instance. 536 565 * 566 * @returns VINF_SUCCESS or VINF_OBJECT_DESTROYED as appropriate. 537 567 * @param pThis The session instance. 538 568 */ 539 DECLINLINE( void) rtLocalIpcSessionRelease(PRTLOCALIPCSESSIONINT pThis)569 DECLINLINE(int) rtLocalIpcSessionRelease(PRTLOCALIPCSESSIONINT pThis) 540 570 { 541 571 uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs); 542 572 Assert(cRefs < UINT32_MAX / 2); 543 573 if (!cRefs) 544 rtLocalIpcSessionDtor(pThis); 574 return rtLocalIpcSessionDtor(pThis); 575 Log(("rtLocalIpcSessionRelease: %u refs left\n", cRefs)); 576 return VINF_SUCCESS; 545 577 } 546 578 … … 556 588 RTCritSectEnter(&pThis->CritSect); 557 589 pThis->fCancelled = true; 590 Log(("rtLocalIpcSessionCancel:\n")); 558 591 if (pThis->hReadThread != NIL_RTTHREAD) 559 592 RTThreadPoke(pThis->hReadThread); … … 581 614 */ 582 615 AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, ~RTLOCALIPCSESSION_MAGIC, RTLOCALIPCSESSION_MAGIC), VERR_WRONG_ORDER); 616 Log(("RTLocalIpcSessionClose:\n")); 583 617 584 618 rtLocalIpcSessionCancel(pThis); 585 rtLocalIpcSessionRelease(pThis); 586 587 return VINF_SUCCESS; 619 return rtLocalIpcSessionRelease(pThis); 588 620 } 589 621 … … 606 638 return VINF_SUCCESS; 607 639 } 640 641 642 #if 0 /* maybe later */ 643 /** 644 * Checks if the socket has has a HUP condition. 645 * 646 * @returns true if HUP, false if no. 647 * @param pThis The IPC session handle. 648 */ 649 static bool rtLocalIpcPosixHasHup(PRTLOCALIPCSESSIONINT pThis) 650 { 651 # ifndef RT_OS_OS2 652 struct pollfd PollFd; 653 RT_ZERO(PollFd); 654 PollFd.fd = RTSocketToNative(pThis->hSocket); 655 PollFd.events = POLLHUP; 656 return poll(&PollFd, 1, 0) >= 1 657 && (PollFd.revents & POLLHUP); 658 659 # else /* RT_OS_OS2: */ 660 return false; 661 # endif 662 } 663 #endif 608 664 609 665 … … 779 835 780 836 uint32_t fEvents = 0; 837 #ifdef RT_OS_OS2 838 /* This doesn't give us any error condition on hangup. */ 839 Log(("RTLocalIpcSessionWaitForData: Calling RTSocketSelectOneEx...\n")); 781 840 rc = RTSocketSelectOneEx(pThis->hSocket, RTPOLL_EVT_READ | RTPOLL_EVT_ERROR, &fEvents, cMillies); 841 Log(("RTLocalIpcSessionWaitForData: RTSocketSelectOneEx returns %Rrc, fEvents=%#x\n", rc, fEvents)); 842 #else 843 /** @todo RTSocketPoll */ 844 /* POLLHUP will be set on hangup. */ 845 struct pollfd PollFd; 846 RT_ZERO(PollFd); 847 PollFd.fd = RTSocketToNative(pThis->hSocket); 848 PollFd.events = POLLHUP | POLLERR | POLLIN; 849 Log(("RTLocalIpcSessionWaitForData: Calling poll...\n")); 850 int cFds = poll(&PollFd, 1, cMillies == RT_INDEFINITE_WAIT ? -1 : cMillies); 851 if (cFds >= 1) 852 { 853 fEvents = PollFd.revents & (POLLHUP | POLLERR) ? RTPOLL_EVT_ERROR : RTPOLL_EVT_READ; 854 rc = VINF_SUCCESS; 855 } 856 else if (rc == 0) 857 rc = VERR_TIMEOUT; 858 else 859 rc = RTErrConvertFromErrno(errno); 860 Log(("RTLocalIpcSessionWaitForData: poll returns %u (rc=%%d), revents=%#x\n", cFds, rc, PollFd.revents)); 861 #endif 782 862 783 863 int rc2 = RTCritSectEnter(&pThis->CritSect); -
trunk/src/VBox/Runtime/r3/win/localipc-win.cpp
r58288 r58290 401 401 /** 402 402 * Call when the reference count reaches 0. 403 * 403 404 * Caller owns the critsect. 405 * 406 * @returns VINF_OBJECT_DESTROYED 404 407 * @param pThis The instance to destroy. 405 408 */ 406 static voidrtLocalIpcServerWinDestroy(PRTLOCALIPCSERVERINT pThis)409 static int rtLocalIpcServerWinDestroy(PRTLOCALIPCSERVERINT pThis) 407 410 { 408 411 BOOL fRc = CloseHandle(pThis->hNmPipe); … … 418 421 419 422 RTMemFree(pThis); 423 return VINF_OBJECT_DESTROYED; 420 424 } 421 425 … … 450 454 } 451 455 else 452 rtLocalIpcServerWinDestroy(pThis); 453 456 return rtLocalIpcServerWinDestroy(pThis); 454 457 return VINF_SUCCESS; 455 458 } … … 735 738 /** 736 739 * Call when the reference count reaches 0. 740 * 737 741 * Caller owns the critsect. 742 * 743 * @returns VINF_OBJECT_DESTROYED 738 744 * @param pThis The instance to destroy. 739 745 */ 740 static voidrtLocalIpcSessionWinDestroy(PRTLOCALIPCSESSIONINT pThis)746 static int rtLocalIpcSessionWinDestroy(PRTLOCALIPCSESSIONINT pThis) 741 747 { 742 748 BOOL fRc = CloseHandle(pThis->hNmPipe); … … 752 758 753 759 RTMemFree(pThis); 760 return VINF_OBJECT_DESTROYED; 754 761 } 755 762 … … 783 790 } 784 791 else 785 rtLocalIpcSessionWinDestroy(pThis); 786 792 return rtLocalIpcSessionWinDestroy(pThis); 787 793 return VINF_SUCCESS; 788 794 } -
trunk/src/VBox/Runtime/testcase/tstRTLocalIpc.cpp
r58289 r58290 74 74 RTTESTI_CHECK_RC_RETV(RTLocalIpcServerCreate(&hIpcServer, "BasicTest", RTLOCALIPC_FLAGS_MULTI_SESSION), VINF_SUCCESS); 75 75 RTTESTI_CHECK_RC(RTLocalIpcServerCancel(hIpcServer), VINF_SUCCESS); 76 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_ SUCCESS);76 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_OBJECT_DESTROYED); 77 77 78 78 /* Client-side (per session). */ … … 120 120 RTThreadSleep(8); /* windows output fudge (purely esthetical) */ 121 121 RTTestIPrintf(RTTESTLVL_INFO, "testServerListenThread: Got new client connection.\n"); 122 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hIpcSession), VINF_ SUCCESS);122 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hIpcSession), VINF_OBJECT_DESTROYED); 123 123 } 124 124 else … … 143 143 VINF_SUCCESS, rcCheck); 144 144 RTTEST_CHECK_RC_RET(g_hTest, RTLocalIpcSessionClose(hClientSession), 145 VINF_ SUCCESS, rcCheck);145 VINF_OBJECT_DESTROYED, rcCheck); 146 146 147 147 return VINF_SUCCESS; … … 214 214 } 215 215 216 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_ SUCCESS);216 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_OBJECT_DESTROYED); 217 217 } 218 218 … … 242 242 RTTESTI_CHECK_RC(RTLocalIpcSessionWaitForData(hIpcSession, RT_MS_1MIN), VINF_SUCCESS); 243 243 244 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hIpcSession), VINF_ SUCCESS);244 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hIpcSession), VINF_OBJECT_DESTROYED); 245 245 RTTESTI_CHECK_RC_OK(RTThreadUserSignal(hSelf)); 246 246 } … … 288 288 } 289 289 290 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hClientSession), VINF_ SUCCESS);290 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hClientSession), VINF_OBJECT_DESTROYED); 291 291 292 292 return VINF_SUCCESS; … … 347 347 RTTESTI_CHECK_RC(rcThread, VERR_CANCELLED); 348 348 349 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_ SUCCESS);349 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_OBJECT_DESTROYED); 350 350 351 351 /* … … 521 521 } 522 522 523 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hIpcSession), VINF_ SUCCESS);523 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hIpcSession), VINF_OBJECT_DESTROYED); 524 524 RTTESTI_CHECK_RC_OK(RTThreadUserSignal(hSelf)); 525 525 } … … 567 567 } 568 568 569 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hClientSession), VINF_ SUCCESS);569 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hClientSession), VINF_OBJECT_DESTROYED); 570 570 571 571 return rc; … … 625 625 RTTESTI_CHECK_RC(rcThread, VERR_CANCELLED); 626 626 627 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_ SUCCESS);627 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_OBJECT_DESTROYED); 628 628 629 629 /* … … 702 702 if (cNsElapsed > 2*RT_NS_1SEC_64) 703 703 { 704 u int32_t uMsg = IPC_PERF_LAST_MSG;704 uMsg = IPC_PERF_LAST_MSG; 705 705 RTTESTI_CHECK_RC_BREAK(rc = RTLocalIpcSessionWrite(hIpcSession, &uMsg, sizeof(uMsg)), VINF_SUCCESS); 706 706 break; … … 715 715 } 716 716 717 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hIpcSession), VINF_ SUCCESS);717 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hIpcSession), VINF_OBJECT_DESTROYED); 718 718 RTTESTI_CHECK_RC_OK(RTThreadUserSignal(hSelf)); 719 719 } … … 767 767 } 768 768 769 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hClientSession), VINF_ SUCCESS);769 RTTESTI_CHECK_RC(RTLocalIpcSessionClose(hClientSession), VINF_OBJECT_DESTROYED); 770 770 return rc; 771 771 } … … 824 824 RTTESTI_CHECK_RC(rcThread, VERR_CANCELLED); 825 825 826 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_ SUCCESS);826 RTTESTI_CHECK_RC(RTLocalIpcServerDestroy(hIpcServer), VINF_OBJECT_DESTROYED); 827 827 828 828 /*
Note:
See TracChangeset
for help on using the changeset viewer.