Changeset 43917 in vbox for trunk/src/VBox/HostServices/HostChannel/HostChannel.cpp
- Timestamp:
- Nov 20, 2012 9:11:14 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/HostChannel/HostChannel.cpp
r43899 r43917 229 229 static void vhcInstanceDestroy(VBOXHOSTCHINSTANCE *pInstance) 230 230 { 231 /* @todo free u32Handle? */231 HOSTCHLOG(("HostChannel: destroy %p\n", pInstance)); 232 232 } 233 233 234 234 static int32_t vhcInstanceAddRef(VBOXHOSTCHINSTANCE *pInstance) 235 235 { 236 HOSTCHLOG(("INST: %p %d addref\n", pInstance, pInstance->cRefs)); 236 237 return ASMAtomicIncS32(&pInstance->cRefs); 237 238 } … … 240 241 { 241 242 int32_t c = ASMAtomicDecS32(&pInstance->cRefs); 243 HOSTCHLOG(("INST: %p %d release\n", pInstance, pInstance->cRefs)); 242 244 Assert(c >= 0); 243 245 if (c == 0) … … 264 266 if (RT_SUCCESS(rc)) 265 267 { 268 /* Used by the client, that is in the list of channels. */ 266 269 vhcInstanceAddRef(pInstance); 267 270 /* Add to the list of created channel instances. It is inactive while pClient is 0. */ 271 RTListAppend(&pClient->listChannels, &pInstance->nodeClient); 272 273 /* Return to the caller. */ 274 vhcInstanceAddRef(pInstance); 268 275 *ppInstance = pInstance; 269 276 } … … 296 303 RTListForEach(&pClient->listChannels, pIter, VBOXHOSTCHINSTANCE, nodeClient) 297 304 { 298 if (pIter->u32Handle == u32Handle) 305 if ( pIter->pClient 306 && pIter->u32Handle == u32Handle) 299 307 { 300 308 pInstance = pIter; … … 328 336 RTListForEach(&pClient->listChannels, pIter, VBOXHOSTCHINSTANCE, nodeClient) 329 337 { 330 if (pIter->pvChannel == pvChannel) 338 if ( pIter->pClient 339 && pIter->pvChannel == pvChannel) 331 340 { 332 341 pInstance = pIter; … … 346 355 static void vhcInstanceDetach(VBOXHOSTCHINSTANCE *pInstance) 347 356 { 357 HOSTCHLOG(("HostChannel: detach %p\n", pInstance)); 358 348 359 if (pInstance->pProvider) 349 360 { … … 351 362 RTListNodeRemove(&pInstance->nodeProvider); 352 363 vhcProviderRelease(pInstance->pProvider); 353 vhcInstanceRelease(pInstance); /* Not in the list anymore. */ 354 } 355 356 RTListNodeRemove(&pInstance->nodeClient); 357 vhcInstanceRelease(pInstance); /* Not in the list anymore. */ 364 pInstance->pProvider = NULL; 365 vhcInstanceRelease(pInstance); /* Not in the provider's list anymore. */ 366 } 367 368 int rc = vboxHostChannelLock(); 369 370 if (RT_SUCCESS(rc)) 371 { 372 RTListNodeRemove(&pInstance->nodeClient); 373 374 vboxHostChannelUnlock(); 375 376 vhcInstanceRelease(pInstance); /* Not used by the client anymore. */ 377 } 358 378 } 359 379 … … 497 517 void vboxHostChannelClientDisconnect(VBOXHOSTCHCLIENT *pClient) 498 518 { 499 /* Clear the list of contexts . */519 /* Clear the list of contexts and prevent acceess to the client. */ 500 520 int rc = vboxHostChannelLock(); 501 521 if (RT_SUCCESS(rc)) 502 522 { 503 523 VBOXHOSTCHCALLBACKCTX *pIter; 504 RTListForEach(&pClient->listContexts, pIter, VBOXHOSTCHCALLBACKCTX, nodeClient) 524 VBOXHOSTCHCALLBACKCTX *pNext; 525 RTListForEachSafe(&pClient->listContexts, pIter, pNext, VBOXHOSTCHCALLBACKCTX, nodeClient) 505 526 { 506 527 pIter->pClient = NULL; 528 RTListNodeRemove(&pIter->nodeClient); 507 529 } 508 530 … … 558 580 pInstance->pvChannel = pvChannel; 559 581 560 vhcInstanceAddRef(pInstance); /* Referenced by the list client's channels. */ 561 RTListAppend(&pClient->listChannels, &pInstance->nodeClient); 582 /* It is already in the channels list of the client. */ 562 583 563 584 vhcInstanceAddRef(pInstance); /* Referenced by the list of provider's channels. */ … … 575 596 } 576 597 598 if (RT_FAILURE(rc)) 599 { 600 vhcInstanceDetach(pInstance); 601 } 602 577 603 vhcInstanceRelease(pInstance); 578 604 } … … 622 648 VBOXHOSTCHINSTANCE *pInstance = vhcInstanceFind(pClient, u32Handle); 623 649 624 if ( pInstance 625 && pInstance->pProvider) 626 { 627 pInstance->pProvider->iface.HostChannelSend(pInstance->pvChannel, pvData, cbData); 650 if (pInstance) 651 { 652 if (pInstance->pProvider) 653 { 654 pInstance->pProvider->iface.HostChannelSend(pInstance->pvChannel, pvData, cbData); 655 } 628 656 629 657 vhcInstanceRelease(pInstance); … … 650 678 VBOXHOSTCHINSTANCE *pInstance = vhcInstanceFind(pClient, u32Handle); 651 679 652 if ( pInstance 653 && pInstance->pProvider) 654 { 655 rc = pInstance->pProvider->iface.HostChannelRecv(pInstance->pvChannel, pvData, cbData, 656 pu32SizeReceived, pu32SizeRemaining); 657 658 HOSTCHLOG(("HostChannel: Recv: (%d) handle %d, rc %Rrc, recv %d, rem %d\n", 659 pClient->u32ClientID, u32Handle, rc, cbData, *pu32SizeReceived, *pu32SizeRemaining)); 680 if (pInstance) 681 { 682 if (pInstance->pProvider) 683 { 684 rc = pInstance->pProvider->iface.HostChannelRecv(pInstance->pvChannel, pvData, cbData, 685 pu32SizeReceived, pu32SizeRemaining); 686 687 HOSTCHLOG(("HostChannel: Recv: (%d) handle %d, rc %Rrc, recv %d, rem %d\n", 688 pClient->u32ClientID, u32Handle, rc, cbData, *pu32SizeReceived, *pu32SizeRemaining)); 689 } 660 690 661 691 vhcInstanceRelease(pInstance); … … 684 714 VBOXHOSTCHINSTANCE *pInstance = vhcInstanceFind(pClient, u32Handle); 685 715 686 if ( pInstance 687 && pInstance->pProvider) 688 { 689 pInstance->pProvider->iface.HostChannelControl(pInstance->pvChannel, u32Code, 690 pvParm, cbParm, 691 pvData, cbData, pu32SizeDataReturned); 716 if (pInstance) 717 { 718 if (pInstance->pProvider) 719 { 720 pInstance->pProvider->iface.HostChannelControl(pInstance->pvChannel, u32Code, 721 pvParm, cbParm, 722 pvData, cbData, pu32SizeDataReturned); 723 } 692 724 693 725 vhcInstanceRelease(pInstance); … … 785 817 } 786 818 787 788 819 /* @thread provider */ 789 820 static DECLCALLBACK(void) HostChannelCallbackEvent(void *pvCallbacks, void *pvChannel, … … 844 875 if (!pInstance) 845 876 { 846 vboxHostChannelUnlock(); 847 848 #ifdef DEBUG_sunlover 849 AssertFailed(); 850 #endif 877 /* Instance was already detached. Skip the event. */ 878 vboxHostChannelUnlock(); 879 851 880 return; 852 881 } … … 887 916 pEvent->cbEvent = cbEvent; 888 917 889 if (RT_SUCCESS(rc)) 890 { 891 RTListAppend(&pClient->listEvents, &pEvent->NodeEvent); 892 } 893 else 894 { 895 RTMemFree(pEvent); 896 } 918 RTListAppend(&pClient->listEvents, &pEvent->NodeEvent); 897 919 } 898 920 } 899 921 900 922 vboxHostChannelUnlock(); 901 } 902 923 924 vhcInstanceRelease(pInstance); 925 } 926 927 /* @thread provider */ 903 928 static DECLCALLBACK(void) HostChannelCallbackDeleted(void *pvCallbacks, void *pvChannel) 904 929 {
Note:
See TracChangeset
for help on using the changeset viewer.