mtpfws/mtpfw/src/cmtpconnection.cpp
changeset 37 d9d8313203af
parent 31 a26669f87b46
child 49 c20dd21d1eb4
--- a/mtpfws/mtpfw/src/cmtpconnection.cpp	Fri Jul 23 18:35:35 2010 +0800
+++ b/mtpfws/mtpfw/src/cmtpconnection.cpp	Mon Aug 09 12:19:11 2010 +0800
@@ -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);