コード例 #1
0
void CGetPortCommand::DoExecuteL()
    {
	TInt errorCode = KErrNone;
	RSocketServ	socketServer;
	errorCode = socketServer.Connect();
	if(errorCode  == KErrNone)
		{
	    RSocket listeningSocket;
		TSockAddr localAddress;
		//TODO: add retrying to find ports
		for(int i = 0; errorCode == KErrNone && i < iFreePortsNum; i++)
			{
			TInt port = iDriver->NextRandomPort();
			listeningSocket.Open(socketServer, KAfInet, KSockStream, KProtocolInetTcp);
			localAddress.SetPort(port); 
			errorCode = listeningSocket.Bind(localAddress);
			if(errorCode == KErrNone)
				{
				iFreePorts.Append(port);
				}
			listeningSocket.Close();
			}
		}
	socketServer.Close();
	User::LeaveIfError(errorCode);
    }
コード例 #2
0
ファイル: Server.cpp プロジェクト: kkskipper/KNOWME
void CServer::ListenL() // for local client
    {
	_LIT(KTCP, "tcp");
    TSockAddr sockAddr;
    sockAddr.SetPort(CProperties::KLocalPort);
	iListener->StartListeningL(KTCP, sockAddr, KMaxConn);
    }
コード例 #3
0
ファイル: IPC_PRVD.CPP プロジェクト: cdaffara/symbiandump-os1
void CIpcProvdBase::LocalName(TSockAddr &anAddr)const
//
//  Get hte local name
//
	{
	anAddr.SetPort(iLocalAddr);
	}
コード例 #4
0
ファイル: IPC_PRVD.CPP プロジェクト: cdaffara/symbiandump-os1
void CIpcProvdBase::RemName(TSockAddr &anAddr)const
//
// Get the remote name we would connect to
//
	{
	anAddr.SetPort(iRemoteAddr);
	}
コード例 #5
0
ファイル: AsyncConnect.cpp プロジェクト: Danewalker/ahr
void CAsyncConnect::startConnect(TSockAddr addr)
{
	debug_out(">>-->>>>> CAsyncConnect::startConnect 00 \n");
	if (inProgress)
	{
		DBG_C("EE: cntr busy");
		debug_out(">>-->>>>> CAsyncConnect::startConnect 01 \n");
		return;
	}

	this->addr = addr;

	connected = false;

	_LIT(KL2Cap, "L2CAP");
	if (error0)
	{
		DBG_C("EE:CAsyncCC error0");
		debug_out(">>-->>>>> CAsyncConnect::startConnect 02 \n");
		return;
	}

	SAFE_CLOSEDEL(sock);
	sock =  new RSocket();

	if (sock->Open(ss, KL2Cap) != KErrNone)
	{
		error0 = true;
		DBG_C("EE: CAsyncCC");
		SAFE_DEL(sock);
		debug_out(">>-->>>>> CAsyncConnect::startConnect 03 \n");
		return;
	}
	addr.SetPort(7);

	CAsyncAccept::disableSecurity((TBTSockAddr*)&addr);

//	char tmp[128];
//	resolve(addr, tmp);
//	//DBG_C("II: !con to [%s]", tmp);

	inProgress = true;
	state = S_CONNECTING;
	sock->Connect(addr, iStatus);
	//DBG_C("II: wait con ...");
	debug_out("sock->Connect: %d", iStatus);
	SetActive();
	//debug_out(">>-->>>>> CAsyncConnect::startConnect 04 \n");
}
コード例 #6
0
// -----------------------------------------------------------------------------
// CTCPPortListener::ConstructL
// -----------------------------------------------------------------------------
//
void CTCPPortListener::ConstructL()
    {
    //Message slots needed is two per socket (read and write) + 1 for
    //synchronous requests.
    User::LeaveIfError(
        iSocketServer.Connect( 2 * KMaxConnectionsInQueue + 1 ) );

    User::LeaveIfError( iListeningSocket.Open(
        iSocketServer, KAfInet, KSockStream, KProtocolInetTcp ) );

    iAcceptedSocket = new (ELeave) RSocket;
    User::LeaveIfError( iAcceptedSocket->Open( iSocketServer ) );

    TSockAddr addr;
    addr.SetPort( iPort );
    User::LeaveIfError( iListeningSocket.Bind( addr ) );

    CActiveScheduler::Add( this );
    }
コード例 #7
0
enum TVerdict CTest02IPCSimpleDataTransfer::InternalDoTestStepL(void)
	{
	
	//-------------------substep 00-----------------------------	
	_LIT(aLog00,"00 Open socket server:");Logger().Write(aLog00);
	
	TInt err;
	RSocketServ ss;
	CleanupClosePushL(ss);
	if ( (err = OptimalConnect(ss)) != KErrNone )
		{
		Logger().WriteFormat(_L("Connecting to socket server failed with %d"), err);
		User::Leave(EFail);
		}
	
	//-------------------substep 01-----------------------------	
	_LIT(aLog01,"01 Create a single client/server connection:");
	Logger().Write(aLog01);

	RSocket aClientSock, aNewConn, aServerSock;
	CleanupClosePushL(aNewConn);
	CleanupClosePushL(aClientSock);
	CleanupClosePushL(aServerSock);
	
	TRequestStatus aAcceptStat, aConnectStat;
	TSockAddr aAddr;
	
	if ( (err=aServerSock.Open(ss, iProt)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not open server socket. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	if ( (err=aServerSock.SetLocalPort(1)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not set port. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	if ( (err=aServerSock.Listen(1)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not set up socket to listen. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	if ( (err=aNewConn.Open(ss)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not open blank socket. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	aServerSock.Accept(aNewConn, aAcceptStat);
	
	if ( (err=aClientSock.Open(ss, iProt)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not open client socket. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	aAddr.SetPort(1);
	aClientSock.Connect(aAddr, aConnectStat);
	
	User::WaitForRequest(aConnectStat);
	User::WaitForRequest(aAcceptStat);
	TVerdict verdict = EPass;

	err = aConnectStat.Int();
    if (aConnectStat != KErrNone)
		{
		_LIT(aLog,"Error:Client socket not connected. err = %d");
		Logger().WriteFormat(aLog, err);
		verdict = EFail;
		}
    
    err = aAcceptStat.Int();
    if (aAcceptStat != KErrNone)
		{
		_LIT(aLog,"Error:Connection not accepted on server side. err = %d");
		Logger().WriteFormat(aLog, err);
		verdict = EFail;
		}
    
    if (verdict == EFail)
    	User::Leave(EFail);
	
    CleanupStack::PopAndDestroy(&aServerSock);
	
	//-------------------substep 02-----------------------------	
	_LIT(aLog02,"02 Send 0x100 bytes to the client. Check the content on arrival:");
	Logger().Write(aLog02);
	
	TBuf8<0x100>* aOut, *aIn;
	CleanupStack::PushL( aOut = new (ELeave) TBuf8<0x100>);
	CleanupStack::PushL( aIn  = new (ELeave) TBuf8<0x100>);
	aOut->SetMax();
	aOut->Fill('a');
	aIn->SetMax();
	aIn->Fill('b');
	
	TRequestStatus aWriteStat, aReadStat;
	aClientSock.Read(*aIn, aReadStat);
	aNewConn.Write(*aOut, aWriteStat);
	
	User::WaitForRequest(aWriteStat);
	err = aWriteStat.Int();
    if (err != KErrNone)
		{
		_LIT(aLog,"Error:Failed to write. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}

    User::WaitForRequest(aReadStat);
    err = aReadStat.Int();
    if (err != KErrNone)
		{
		_LIT(aLog,"Error:Failed to read. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
    
	if (aIn->Compare(*aOut))
		{
		_LIT(aLog,"Error:Data received on clent side corrupted. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	//-------------------substep 03-----------------------------	
	_LIT(aLog03_1,"03 Send 0x100 bytes to the client partially (a byte after byte). Then ...");
	Logger().Write(aLog03_1);
	_LIT(aLog03_2,"   ...receive them on client side and check the content.");
	Logger().Write(aLog03_2);

	TInt i;
	aIn->Fill('b');
	aClientSock.Read(*aIn, aReadStat);
	
	aOut->SetLength(1);
	for (i=0;i<0x100;i++)
		{
		aNewConn.Write(*aOut, aWriteStat);
		User::WaitForRequest(aWriteStat);
		err = aWriteStat.Int();
		if (err != KErrNone)
			{
			_LIT(aLog,"Error:Failed to write. err = %d");
			Logger().WriteFormat(aLog, err);
			User::Leave(EFail);
			}
		}
	
	User::WaitForRequest(aReadStat);
	err = aReadStat.Int();
    if (err != KErrNone)
		{
		_LIT(aLog,"Error:Failed to read. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	aOut->SetMax();
	if (aIn->Compare(*aOut))
		{
		_LIT(aLog,"Error:Data received on clent side corrupted. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	//-------------------substep 04-----------------------------	
	_LIT(aLog04_1,"04 Send 0x100 bytes to the server. Then...");
	Logger().Write(aLog04_1);
	_LIT(aLog04_2,"   ...receive them partially(byte after byte) on the server side and check the content.");
	Logger().Write(aLog04_2);
	
	aIn->Fill('b');
	aClientSock.Write(*aOut, aWriteStat);
	
	User::WaitForRequest(aWriteStat);
	err = aWriteStat.Int();
	if (err != KErrNone)
		{
		_LIT(aLog,"Error:Failed to write. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	TBuf8<0x01> aInSmall;
	for (i=0;i<0x100;i++)
		{
		aNewConn.Read(aInSmall, aReadStat);
		User::WaitForRequest(aReadStat);
		err = aReadStat.Int();
		if (err != KErrNone)
			{
			_LIT(aLog,"Error:Failed to read. err = %d");
			Logger().WriteFormat(aLog, err);
			User::Leave(EFail);
			}
		(*aIn)[i] = aInSmall[0];
		}
	
	if (aIn->Compare(*aOut))
		{
		_LIT(aLog,"Error:Data received on clent side corrupted. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	//-------------------substep 05-----------------------------	
	_LIT(aLog05,"05 Cleanup stack. Close all sockets.  Close socket server");
	Logger().Write(aLog05);
    CleanupStack::PopAndDestroy(5, &ss);
	return EPass;
	}