×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Aug 2006
    Location
    Egypt, Cairo
    Posts
    37

    class connection engine problem

    dear all

    this class produce memory leak when using one time by calling IssueHTTPPostL() function and if called many times it crashed and produce

    Unhandled exception at 0x1127980b in epoc.exe: 0xC0000005: Access violation reading location 0x00000000.

    the class implementation is as follow

    Code:
    CConnectionEngine* CConnectionEngine::NewL(MClientObserver& aObserver)
    {
    	CConnectionEngine* self = CConnectionEngine::NewLC(aObserver);
    	CleanupStack::Pop(self);
    	return self;
    }
    
    CConnectionEngine* CConnectionEngine::NewLC(MClientObserver& aObserver)
    {
    CConnectionEngine* self = new (ELeave) CConnectionEngine(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }
    
    CConnectionEngine::CConnectionEngine(MClientObserver& aObserver) : iObserver(aObserver), iPostData(NULL), iRunning(EFalse)
    {
    }
    
    CConnectionEngine::~CConnectionEngine()
    {
    	if (iglobalNote)
    	{
    		delete iglobalNote;
    		iglobalNote = NULL;
    	}
    
    	if(iPostData)
    	{
    		delete iPostData;
    		iPostData = NULL;
    	}
    
    	iSession.Close();
    	iConnection.Close();
    	iSocketServ.Close();
    }
    
    void CConnectionEngine::ConstructL()
    {
    	// Open RHTTPSession with default protocol ("HTTP/TCP")
    	TRAPD(err, iSession.OpenL());
    	if(err != KErrNone) 
    	{
    _LIT(KErrMsg,"Cannot create session. Is internet access point configured?");
    _LIT(KExitingApp, "Exiting app.");
    CEikonEnv::Static()->InfoWinL(KErrMsg, KExitingApp);
    	User::Leave(err);
    	}
    }
    
    void CConnectionEngine::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
    	{
    		RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue);
    		CleanupClosePushL(valStr);
    		THTTPHdrVal val(valStr);
    		aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField, RHTTPSession::GetTable()), val);
    		CleanupStack::PopAndDestroy(); // valStr
    	}
    void CConnectionEngine::IssueHTTPPostL(const TDesC8& aUri, const TDesC8& aContentType, const TDesC8& aBody, TDesC& aAction, TInt32& aAccessPoint)
    {
    	// Parse string to URI
    	TUriParser8 uri; 
    	uri.Parse(aUri);
    
    	delete iPostData;
    	iPostData = aBody.AllocL();
    
    	User::LeaveIfError(iSocketServ.Connect());
    	User::LeaveIfError(iConnection.Open(iSocketServ));		
    
    	// open the IAP communications database 
    	CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
    	CleanupStack::PushL(commDB);
    
    	// initialize a view 
    	CCommsDbConnectionPrefTableView* commDBView = commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionOutgoing);
    	// go to the first record 
    	User::LeaveIfError(commDBView->GotoFirstRecord());
    
    	// Declare a prefTableView Object.
    	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
    
    	// read the connection preferences 
    	commDBView->ReadConnectionPreferenceL(pref);
    	iIapId = pref.iBearer.iIapId; 
    
    	CleanupStack::PopAndDestroy(commDBView);
    	CleanupStack::PopAndDestroy(commDB);
    
    	/////-0-----------0--------------
    
    	iConnPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    	iConnPref.SetDirection(ECommDbConnectionDirectionOutgoing);
    	iConnPref.SetBearerSet(ECommDbBearerGPRS);
    
    	if(aAccessPoint < 0)
    	{
    		SelectAccessPointL(iIapId);
    		aAccessPoint = iIapId;
    	}
    	else
    	{
    		iIapId = aAccessPoint;
    	}
    
    	iConnPref.SetIapId(iIapId);
    	// start a synchronous connection
    	TInt errConnect = iConnection.Start(iConnPref); 
    
    	RStringPool strP = iSession.StringPool();
    	RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
    	connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ,	RHTTPSession::GetTable()), THTTPHdrVal (iSocketServ.Handle()));
    	TInt connPtr = REINTERPRET_CAST(TInt, &(iConnection));
    	connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal(connPtr));
    
    	//==========================
    	RStringF method = iSession.StringPool().StringF(HTTP::EPOST, RHTTPSession::GetTable());
    	iTransaction = iSession.OpenTransactionL(uri, *this, method);
    
    	RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    	SetHeaderL(hdr, HTTP::EAccept, KAccept);
    	SetHeaderL(hdr, HTTP::EContentType, aContentType);
    
    	MHTTPDataSupplier* dataSupplier = this;
    	iTransaction.Request().SetBody(*dataSupplier);
    
    	iTransaction.SubmitL();
    
    	if (!iglobalNote)
    	{
    		iglobalNote = CAknGlobalNote::NewL();
    	}
    	
    	iNoteId= iglobalNote->ShowNoteL( EAknGlobalWaitNote , aAction);
    
    	iRunning = ETrue;
    	_LIT(KConnecting,"Connecting...");
    	iObserver.ClientEvent(KConnecting);
    }
    
    void CConnectionEngine::CancelTransaction()
    	{
    		if(!iRunning) 
    			return;
    
    		iTransaction.Close();
    
    		iRunning = EFalse;
    		_LIT(KTransactionCancelled, "Transaction cancelled");
    		if(iNoteId > 0)
    		{
    			iglobalNote->CancelNoteL( iNoteId );
    			delete iglobalNote;
    			iglobalNote = NULL;
    		}
    	}
    
    
    void CConnectionEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
    	{
    		switch (aEvent.iStatus) 
    		{
    		case THTTPEvent::EGotResponseHeaders:
    			{ 
    			}
    			break;
    
    	case THTTPEvent::EGotResponseBodyData:
    	{
    	MHTTPDataSupplier* body = aTransaction.Response().Body();
    	TPtrC8 dataChunk;
    	TBool isLast = body->GetNextDataPart(dataChunk);
    	iObserver.ClientBodyReceived(dataChunk);
    	body->ReleaseData();
    	}
    	break;
    
    	case THTTPEvent::EResponseComplete:
    	{
    	_LIT(KTransactionComplete, "Transaction Complete");
    	iObserver.ClientEvent(KTransactionComplete);
    	}
    	break;
    
            case THTTPEvent::ESucceeded:
    	{
    	_LIT(KTransactionSuccessful, "Transaction Successful");
    	iObserver.ClientEvent(KTransactionSuccessful);
    
    	aTransaction.Close();
    	iRunning = EFalse;
    								if(iNoteId > 0)
    	{
    	iglobalNote->CancelNoteL( iNoteId );
    	delete iglobalNote;
    	iglobalNote = NULL;
    	}
    	iObserver.TransactionCompletedSuccessfuly();
    
    	}
    	break;
    
    	case THTTPEvent::EFailed:
    	{
    	_LIT(KTransactionFailed, "Transaction Failed");			aTransaction.Close();
    	iRunning = EFalse;
    			
    	if(iNoteId > 0)
    	{
    		iglobalNote->CancelNoteL( iNoteId );
    		delete iglobalNote;
    		iglobalNote = NULL;
    	}
    
    	}
    	break;
    
    	default:
    	{
    	TBuf<64> text;
    	if (aEvent.iStatus < 0)
    	{
    	_LIT(KErrorStr, "Error: %d");
    	text.Format(KErrorStr, aEvent.iStatus);
    						aTransaction.Close();
    	iRunning = EFalse;
    	}
    	else 
    	{
    	_LIT(KUnrecognisedEvent, "Unrecognised event: %d");
    	text.Format(KUnrecognisedEvent, aEvent.iStatus);
    	}
    	if(iNoteId > 0)
    	{
    	iglobalNote->CancelNoteL( iNoteId );
    	delete iglobalNote;
    	iglobalNote = NULL;
    	
    	}
    	}
    	break;
    }
    }
    
    TInt CConnectionEngine::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/)
    	{
    		TBuf<64>	text;
    		_LIT(KRunError, "MHFRunError: %d");
    		text.Format(KRunError, aError);
    		return KErrNone;
    	}
    
    TBool CConnectionEngine::GetNextDataPart(TPtrC8& aDataPart)
    	{
    		if(iPostData) 
    			{
    			aDataPart.Set(iPostData->Des());
    			}
    		return ETrue;
    	}
    
    void CConnectionEngine::ReleaseData()
    	{
    		delete iPostData;
    		iPostData = NULL;
    	}
    TInt CConnectionEngine::Reset()
    	{
    		return KErrNone;
    	}
    TInt CConnectionEngine::OverallDataSize()
    	{
    		if(iPostData)		
    			return iPostData->Length();
    		else
    			return KErrNotFound ;
    	}
    TBool CConnectionEngine::GetCredentialsL(const TUriC8& aURI,RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword) 
    	{
    		TBuf<128> authType;
    		TBuf<128> uri;
    		TBuf<256> authText;
    		authType.Copy(aAuthenticationType.DesC());
    		uri.Copy(aURI.UriDes());
    		_LIT(KAuthRequired, "%S requires %S authentication.");
    		authText.Format(KAuthRequired, &uri, &authType);
    		TBuf<256> userName;
    		TBuf<256> password;
    		CAknMultiLineDataQueryDialog* dlg = CAknMultiLineDataQueryDialog::NewL(userName, password);
    
    		if (!dlg->ExecuteLD(R_DIALOG_USER_PASSWORD_QUERY))
    			return EFalse; 
    		TBuf8<256> temp;
    		temp.Copy(userName);
    		TRAPD(err, aUsername = aRealm.Pool().OpenStringL(temp));
    		if (!err) 
    			{
    			temp.Copy(password);
    			TRAP(err, aPassword = aRealm.Pool().OpenStringL(temp));
    			if (!err) return ETrue;
    			}
    
    		return EFalse;
    	}
    
    void CConnectionEngine::SelectAccessPointL(TUint32& aIap)
    	{
    		// Create Ap Settings Handler. See SDK Help for parameters.
    		CApSettingsHandler* settingsHandler = CApSettingsHandler::NewLC(ETrue, EApSettingsSelListIsPopUp, 
    		EApSettingsSelMenuSelectNormal, KEApIspTypeAll, EApBearerTypeAll,  KEApSortNameAscending);
    
    		TUint32 originallyFocused(0);
    		TUint32 aSelectedIap(0); 
    
    		// Show the dialog
    		settingsHandler->RunSettingsL(originallyFocused, aSelectedIap);
    
    		// Original value 0 is not valid IAP id, so failed if 0 after RunSettingsL().
    		if (aSelectedIap)
    		{
    			CCommsDatabase* db = CCommsDatabase::NewL();
    			CleanupStack::PushL(db);
    			CApUtils* apUtils = CApUtils::NewLC(*db);
    			// Convert IAP id to CommsDb id
    			aIap = apUtils->IapIdFromWapIdL(aSelectedIap); 
    			CleanupStack::PopAndDestroy(2);
    		}
    		else
    		{
    		aIap = 0 /*IAP_NONE*/;
    		}
    
    		CleanupStack::PopAndDestroy();
    	}
    Regards,
    Fathi S. el3ashery

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

    Re: class connection engine problem

    Hi,
    Looks to me, if you call IssueHTTPPostL(...) then you have to delete your CConnectionEngine each time other wise the Close() is not called, since in IssueHTTPPostL () you have Conect() and Open().

    Regards
    -Mahbub

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,672

    Re: class connection engine problem

    If you run the code in a debugger, you will see where your code fails. It will be also possible to press continue, and see the related Symbian panic, however it is likely going to be KERN-EXEC 3.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Location
    Egypt, Cairo
    Posts
    37

    Re: class connection engine problem

    hi every one
    thanks for your reply

    for mahbub_s60 i already open and close the connection every time i call the connection, and i also try deleting the whole object and create ite again before calling issue every time

    and about wizard_hu_ reply

    when this error apear it you can not press continue it will stop again and again and it stop in random places in code and each place is different from the other
    Regards,
    Fathi S. el3ashery

  5. #5
    Registered User
    Join Date
    Aug 2006
    Location
    Egypt, Cairo
    Posts
    37

    Re: class connection engine problem

    ho every one

    i found the problem

    it was about CAknGlobalNote with note type waiting note it crashed random i did note know why but it was it
    Regards,
    Fathi S. el3ashery

Similar Threads

  1. Need one HTTP client example
    By vinayakak in forum Symbian Networking & Messaging (Closed)
    Replies: 15
    Last Post: 2008-01-06, 06:44
  2. need information about j2me polish
    By rathikathangaraj in forum Mobile Java General
    Replies: 4
    Last Post: 2007-12-19, 09:01
  3. Can we use CSecureSocket class for Bluetooth connection????
    By lal.rajan in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2007-03-09, 04:45
  4. Problem deriving a class from CAknForm
    By T_N_Shetty@yahoo.com in forum Symbian User Interface
    Replies: 2
    Last Post: 2003-07-05, 07:31
  5. Exceptions while loading application
    By avinash_rs in forum Mobile Java General
    Replies: 0
    Last Post: 2003-06-09, 10:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×