mtpfws/mtpfw/src/cmtpconnection.cpp
branchRCL_3
changeset 45 74aa6861c87d
parent 43 4a793f564d72
child 58 142dacf7b30e
--- a/mtpfws/mtpfw/src/cmtpconnection.cpp	Wed Sep 01 12:20:56 2010 +0100
+++ b/mtpfws/mtpfw/src/cmtpconnection.cpp	Tue Sep 14 22:52:29 2010 +0300
@@ -82,17 +82,9 @@
     __FLOG(_L8("~CMTPConnection - Entry"));
     CloseAllSessions();
     
-    // Remove any events not associated 
-    // with a session
-    TSglQueIter<CMTPEventLink> iter(iEventQ);
-    iter.SetToFirst();
-    CMTPEventLink* link = NULL;
-    
-    while ((link = iter++) != NULL)
-    	{
-    	delete link;
-    	}
-    
+	//remove all events
+    DequeueAllEvents();
+	
     iSessions.ResetAndDestroy();
     
     if (iTransportConnection != NULL)
@@ -667,9 +659,16 @@
     DequeueEvent(iEventQ.First());       
    	if (iPendingEventCount > 0)
    		{
-   		// Forward the event to the transport connection layer.
-   		__FLOG(_L8("Sending queued event"));
- 	    iTransportConnection->SendEventL(iEventQ.First()->iEvent);
+		if (NULL != iTransportConnection)
+			{
+			// Forward the event to the transport connection layer.
+			__FLOG(_L8("Sending queued event"));
+			iTransportConnection->SendEventL(iEventQ.First()->iEvent);
+			}
+		else
+			{
+			DequeueAllEvents();
+			}
    		}
     
     __FLOG(_L8("SendEventCompleteL - Exit"));
@@ -1046,6 +1045,19 @@
     __FLOG(_L8("RemoveEventsForSession - Exit"));
 	}
 
+void CMTPConnection::DequeueAllEvents()
+	{
+	TSglQueIter<CMTPEventLink> iter(iEventQ);
+    iter.SetToFirst();
+    CMTPEventLink* link = NULL;
+    
+    while ((link = iter++) != NULL)
+    	{
+    	delete link;
+    	}
+	iPendingEventCount = 0;
+	}
+	
 void CMTPConnection::DequeueEvent(CMTPEventLink* aLink)
 	{
 	iEventQ.Remove(*aLink);