Problem Ctimer

Login to reply to this topic.
Wed, 2007-12-05 17:16
Joined: 2006-07-21
Forum posts: 158

Hi, i have a problem with CTimer.
I try to connect with a server by gprs, i use a timer of 30 second if connection is not possible.
I test my application with a not exist server. The first time ther is timeout, but the second time timeout not work and go to setActive and application crash.
I write a code of example:

void CgprsConnection::ConnectL()
    {
   
    // Initiate connection process
    if ( iEngineStatus == ENotConnected )
        {
        isConnect=1;
        TInt code = 55;
         while((code = iSocketServ.Connect()) != KErrNone)
            {
                    User::After(3000000);
            }
      
       
        RConnection conn;

        _LIT(KRasAddr,"127.0.0.1");
       
        destAddr.Input(KRasAddr);
        destAddr.SetPort(KDefaultPortNumber);
      
    
        // Connect to the socket server
        // Open an RConnection object. Note that you must provide the RSocketServ object
        conn.Open(iSocketServ);
        conn.GetIntSetting(KSetting, codice);

      
        // Start an Outgoing Connection with overrides
        conn.Start(prefs);

        // Open a Host Resolver associated with the connection
        RHostResolver hr;
        hr.Open(iSocketServ, KAfInet, KProtocolInetTcp, conn);

        // Open a Socket associated with the connection
        User::LeaveIfError(sock.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, conn));
               
        sock.Connect(destAddr, iStatus);
       
        ChangeStatus( EConnecting );
          
        // Request time out
        iTimer->After( KTimeOut );
       
          }
            SetActive();
    }


void CgprsConnection::TimerExpired()
        {
    Cancel();
    Disconnect();
  User::After(3000000);
ConnectL();
   }

What is the problem?
Many thanks
SIlvia


Wed, 2007-12-05 23:29
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2009
Re: Problem Ctimer

At least you should not create your RConnection object in a local variable. Same for the Host Resolver (btw, you do not seem to use it )


Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Thu, 2007-12-06 06:26
Joined: 2007-09-20
Forum posts: 116
Re: Problem Ctimer

Hi,

Keep the "SetActive()" method inside the "if" condition.

if ( iEngineStatus == ENotConnected )
{
.....
.....
.....
// Request time out
iTimer->After( KTimeOut );
SetActive();
}


Chao,
Raghav

Thu, 2007-12-06 10:56
Joined: 2006-07-21
Forum posts: 158
Re: Problem Ctimer

I try to use RTimer, and the first time work, but the second time phone reboot.
I use itimer->after(status, time) to start timer and itimer->cancel for delete timer pendent.
After cancel i must restart timer? I think that application chrash when recall itimer->after(status, time), but why? Sad
Thanks
Silvia

Thu, 2007-12-06 14:09
Joined: 2007-09-20
Forum posts: 116
Re: Problem Ctimer

Hi Silvia,

Will you tell why are you calling "SetActive()" for cases where "iEngineStatus != ENotConnected".

Are you requesting other asynchronous service other than "CTimer", if this is the case then you need to have a seperate AOs for each asynch service requests.


Chao,
Raghav

Thu, 2007-12-06 16:46
Joined: 2006-07-21
Forum posts: 158
Re: Problem Ctimer

I return to use CTimer, now application go to timeExipred for two time, but the therd time jump to runL without give timeexpired, why?
Its a very very problem for me Sad

My code:

void CgprsConnection::ConnectL()
    {
    
    // Initiate connection process
    if ( iEngineStatus == ENotConnected )
        {
        isConnect=1;
        TInt code = 55;
        while((code = iSocketServ.Connect()) != KErrNone)
    	{
    		User::After(3000000); 
		
    	}
       
        
		
        
        
        RConnection conn;

        _LIT(KRasAddr,"ip");
        
        destAddr.Input(KRasAddr);
        destAddr.SetPort(KDefaultPortNumber);
       
     
        // Connect to the socket server
        // Open an RConnection object. Note that you must provide the RSocketServ object
        conn.Open(iSocketServ);
        conn.GetIntSetting(KSetting, codice);

       
        // Start an Outgoing Connection with overrides
        conn.Start(prefs);

        // Open a Host Resolver associated with the connection
        RHostResolver hr;
        hr.Open(iSocketServ, KAfInet, KProtocolInetTcp, conn);

        // Open a Socket associated with the connection
        User::LeaveIfError(sock.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, conn));
	    
        
        sock.Connect(destAddr, iStatus);
        ChangeStatus( EConnecting );
           
        // Request time out
        
        iTimer->After( /*timerStatus,*/KTimeOut );
               	
        
		    	
		SetActive();
	  	
	      }
    
  
    
    	
    }



void CgprsConnection::TimerExpired()
	{

    Cancel();
    Disconnect();
	ChangeStatus( ENotConnected );
	
	ConnectL();
   }


void CgprsConnection::Disconnect()
    {
	delete iTimer;
	iTimer = NULL;
	iTimer = CTimeOutTimer::NewL( EPriorityHigh, *this );
	sock.CancelAll();
	sock.CancelConnect();
	sock.Close();
	iSocketServ.Close();
	ChangeStatus( ENotConnected );
    isConnect=1;
    }

Some idea? Sad
Many thanks
Silvia

Thu, 2007-12-06 17:24
Joined: 2007-09-20
Forum posts: 116
Re: Problem Ctimer

Hi,

I return to use CTimer, now application go to timeExipred for two time, but the therd time jump to runL without give timeexpired, why?

Its almost impossible to answer this without looking into the code of RunL().
You may get some response by posting the implementation of RunL() method. Eye-wink


Chao,
Raghav

Thu, 2007-12-06 17:28
Joined: 2006-07-21
Forum posts: 158
Re: Problem Ctimer

ok, sorry Smiling



void CgprsConnection::RunL()
{
iTimer->Cancel();

switch( iEngineStatus )
{
    case EConnecting: 
    	{
			if ( iStatus == KErrNone )
			{
				ChangeStatus( EConnected );
				isConnect =0;
				SendMessage();
			}
			else
			{
				ChangeStatus( ENotConnected );
				isConnect=1;
				Disconnect();
				User::After(1000000); //3000000 
				delete iTimer;
				iTimer = NULL;
				iTimer = CTimeOutTimer::NewL( EPriorityHigh, *this );
				ConnectL(); //riprovo a connettermi
			}
    	
        break;
    	}
     case EControl:
     {
		
     	 if ( iStatus == KErrNone )
         { 
	         ChangeStatus(EConnected);
	         isConnect=0;
	         ReadMessage(); 
		 
	   }
		else
		{
			ChangeStatus( ENotConnected );
			isConnect=1;
			Disconnect();
			User::After(1000000); //3000000 
			ConnectL(); //riprovo a connettermi
		}	
		break;
     }    
     case EClosed:
     {
       	Disconnect();
     	break;
     }   
     case ENotConnected:
    	 {
    	 isConnect=1;
	 	Disconnect();
			User::After(1000000); //3000000 
			delete iTimer;
			iTimer = NULL;
			iTimer = CTimeOutTimer::NewL( EPriorityHigh, *this );
			
			
			ConnectL(); //riprovo a connettermi
    	  break;
    	 }
     	
     default:
     {
		
	 	
     } 
     break;

 };
    

}


Many Thanks
Silvia

Fri, 2007-12-07 06:07
Joined: 2007-09-20
Forum posts: 116
Re: Problem Ctimer

Hi,

Check for the state of "iEngineStatus" to make sure all possible states are handled properly in the switch statement.


Chao,
Raghav

Fri, 2007-12-07 09:35
Joined: 2006-07-21
Forum posts: 158
Re: Problem Ctimer

The strange event is that for 4 time application go to inside timeexpired (and is correct!!!) ,instead the 5 time application go inside runL, is very very strange Sad

But is problem of socket or timer? Sad

  • Login to reply to this topic.