Ejemplo n.º 1
0
void CSEIConnector::RunL()
	{
	TInt error = KErrNone;
	switch(iState)
		{
		case EGetByName:
			{
			ConnectSocketL();
			break;
			}
		case ESocketConnect:
			{
			ProcessRequestL();
			break;
			}
		}
	}
TVerdict CEsockTest29::easyTestStepL()
	{

	// Open Sockets, one to manipulate mBufPool and one to send/revieve with tcp or udp
	TESTL( OpenSockets() == KErrNone );

	// Bind Test Socket To local Address
	TInetAddr local;
	SetPort( local, KPort, KLocal );
	iTestSocket.Bind( local );
	
	// Connect Test Socket to LoopBack Address
	TInetAddr loopBack;
	SetPort( loopBack, KPort, KLoopback );
	ConnectSocketL( iTestSocket, loopBack );
	
	// Gobble all the Buf's in the MBuf Pool return the number of mBufs in Use
	TInt totalUsedBufs = iDummySocket.SetOpt( KDummyOptionSetGobbleMBufs, 0, 0 );
	TInt bufsToBeFreed = 0;
	
	// Data to be used during socket Send
	GetIntFromConfig(KSection29, KBufSize, iBufSize);
	TBool keepSending = ETrue;
	TBuf8<4500> recvBuf;
	TBuf8<4500> sendData;
	sendData.Fill(TChar('z'), iBufSize );
	TRequestStatus sendStatus;
	TRequestStatus recvStatus;
	const TInt KOneSecond = 1000000;
	
	
	
	for( TInt freeBufCounter = 0; freeBufCounter < totalUsedBufs && keepSending; freeBufCounter += bufsToBeFreed )
	// OOB loop that will gradually release more MBufs
		{
		
		// release some mBufs and send
		iDummySocket.SetOpt( KDummyOptionSetFreeSomeMBufs, bufsToBeFreed , 0);
		iTestSocket.Send( sendData, 0, sendStatus );
		
		// Wait for a second to allow time for server/protocol to send
		User::After( KOneSecond );
		
		// Cancel the send and start to recv
		iTestSocket.CancelSend();
		User::WaitForRequest(sendStatus);
		
		iTestSocket.Recv(recvBuf, 0, recvStatus);
		
		// Wait for a second to allow time for server/protocol to recieve
		User::After( KOneSecond );
		iTestSocket.CancelRecv();
		User::WaitForRequest( recvStatus );
		
		if( freeBufCounter % 5 == 0 )
			{
			INFO_PRINTF2( _L("freeBufs now >= %d "),  freeBufCounter );
			}
		
		if( recvBuf.Compare(sendData) == 0 )
		// if we have recieved data then exit the loop
			{
			keepSending = EFalse;
			}
			
		bufsToBeFreed = 2;
		
		}
	
	// Now do a regular send for good measure to make sure everything is ok
	sendData.Fill(TChar('c'), iBufSize );
	INFO_PRINTF1( _L("End of Loop, Now sending....") );
	iTestSocket.Send( sendData, 0, sendStatus );
	User::WaitForRequest( sendStatus );
	INFO_PRINTF2( _L("Send Returned %d, now recieving...."), sendStatus.Int() );
	iTestSocket.Recv( recvBuf, 0, recvStatus );
	User::After( KOneSecond ); 
	iTestSocket.CancelRecv();
	User::WaitForRequest( recvStatus );
	
	INFO_PRINTF2( _L("Recieve returned %d ") , recvStatus.Int() );
	if( recvBuf.Compare(sendData) != 0 )
		{
		return EFail;
		}
	
	return EPass;
	
	}