datacommsserver/esockserver/core_states/ss_corepractivities.cpp
branchRCL_3
changeset 18 9644881fedd0
parent 17 9ddb1d67ebaf
child 21 07656293a99c
--- a/datacommsserver/esockserver/core_states/ss_corepractivities.cpp	Tue May 11 17:20:19 2010 +0300
+++ b/datacommsserver/esockserver/core_states/ss_corepractivities.cpp	Tue May 25 14:00:39 2010 +0300
@@ -1604,12 +1604,20 @@
 // CommsBinderActivity and CCommsBinderCombiningActivity.
 //
 //-=========================================================
-
+// When I node need to create the data client, this mutex block if the dataclient is leaving.
+// A scenario can arise when a connection is being started, stopped and started again in succession.
+// the stop might interfere with the second start and ccause the second start to fail.
+// this mutex will ensure that the leaving DC is completely destroyed, and then the second start is continued
+// - when any of the data clients is being destroyed 
+// - when a non-leaving data client is present or the activity is already running
+//
 EXPORT_C TBool CCommsBinderActivity::TDataClientMutex::IsBlocked(MeshMachine::TNodeContextBase& aContext)
   	{
   	TInt c = aContext.Node().CountActivities(aContext.iNodeActivity->ActivitySigId());
   	__ASSERT_DEBUG(c>0, User::Panic(KSpecAssert_ESockCrStaCPRAC, 17)); //Diagnostic
-  	if (c == 1 || CCommsBinderActivity::IsDataClientPresent(aContext))
+    TInt numOfLeavingDataClients = aContext.Node().CountClients<TDefaultClientMatchPolicy>(
+                                   /*include*/TClientType(TCFClientType::EData, TCFClientType::ELeaving));
+  	if (numOfLeavingDataClients == 0 && (c == 1 || CCommsBinderActivity::IsDataClientPresent(aContext)))
   		{
   		return EFalse;
   		}
@@ -1620,7 +1628,9 @@
   	{
   	TInt c = aContext.Node().CountActivities(aContext.iNodeActivity->ActivitySigId());
   	__ASSERT_DEBUG(c>0, User::Panic(KSpecAssert_ESockCrStaCPRAC, 18)); //Diagnostic
-  	if (c == 1 || CCommsBinderActivity::IsDataClientPresent(aContext, TCFClientType::EDefault))
+    TInt numOfLeavingDataClients = aContext.Node().CountClients<TDefaultClientMatchPolicy>(
+                                   /*include*/TClientType(TCFClientType::EData, TCFClientType::ELeaving));
+  	if (numOfLeavingDataClients == 0 && (c == 1 || CCommsBinderActivity::IsDataClientPresent(aContext, TCFClientType::EDefault)))
   		{
   		return EFalse;
   		}
@@ -1701,6 +1711,7 @@
 	iPendingBinder->SetFlags(TCFClientType::EActivating);
     }
 
+
 EXPORT_C void CCommsBinderActivity::Cancel(TNodeContextBase& aContext)
     {
     if (iPendingBinder)