mmsharing/mmshmanagercli/src/musmanagerclientsession.cpp
branchRCL_3
changeset 21 33a5d2bbf6fc
parent 0 f0cf47e981f9
--- a/mmsharing/mmshmanagercli/src/musmanagerclientsession.cpp	Thu Jul 15 18:35:08 2010 +0300
+++ b/mmsharing/mmshmanagercli/src/musmanagerclientsession.cpp	Thu Aug 19 09:51:39 2010 +0300
@@ -31,8 +31,10 @@
 */
 #define ASYNCHRONOUS_MESSAGE_SLOTS 255
 
+const TInt KMusServerSessionCreationWaitTimeoutInMicrosecs = 10000000; // 10 secs
+
 // ======== LOCAL FUNCTIONS ========
-
+      
 // ---------------------------------------------------------------------------
 //
 // ---------------------------------------------------------------------------
@@ -40,21 +42,49 @@
 RMusManagerClientSession::RMusManagerClientSession()
     : RSessionBase ()
     {
-
     }
 
+
 // ---------------------------------------------------------------------------
-//
+// Use timeout mechanism for session creation as otherwise it can block
+// so long that WServ terminates the process. There's no way to cancel
+// session creation other than destuction of client session. Therefore, in case
+// of timeout, leave and let creation finish silently or get canceled when
+// user of client session object deletes us.
 // ---------------------------------------------------------------------------
 //
 void RMusManagerClientSession::ConnectL()
     {
-    MUS_LOG( "mus: [MUSCLI]  -> RMusManagerClientSession::ConnectL()" );
-    TRequestStatus s;
+    MUS_LOG( "mus: [MUSCLI]  -> RMusManagerClientSession::ConnectL(), with timeout" );
+
+    if ( iSessionCreationStatus.Int() == KRequestPending )
+        {
+        // Previous creation still pending
+        User::Leave( KErrNotReady );
+        }
+    
+    RTimer timer;
+    CleanupClosePushL( timer );
+    User::LeaveIfError( timer.CreateLocal() );
+    
     User::LeaveIfError( CreateSession( KMusManagerServerName(), Version(),
-                                             ASYNCHRONOUS_MESSAGE_SLOTS, &s ) );
-
-    User::WaitForRequest( s );
+                            ASYNCHRONOUS_MESSAGE_SLOTS, &iSessionCreationStatus) );
+    TRequestStatus timeoutStatus;
+    timer.After( timeoutStatus, KMusServerSessionCreationWaitTimeoutInMicrosecs );
+    User::WaitForRequest( iSessionCreationStatus, timeoutStatus );
+    if ( timeoutStatus.Int() != KRequestPending )
+        {
+        MUS_LOG( "mus: [MUSCLI]  RMusManagerClientSession::ConnectL, timeout" );
+        User::Leave( KErrTimedOut );
+        } 
+    else
+        {
+        MUS_LOG( "mus: [MUSCLI]  RMusManagerClientSession::ConnectL, no timeout" );
+        timer.Cancel();
+        User::WaitForRequest( timeoutStatus );
+        }
+    CleanupStack::PopAndDestroy( &timer );
+    
     MUS_LOG( "mus: [MUSCLI]  <- RMusManagerClientSession::ConnectL()" );
     }