int ILibSocketWrapper_listen(int socketObject,int backlog)
{
	RSocket *s = (RSocket*)SocketArray[socketObject];
	if(s->Listen(backlog)==KErrNone)
	{
		return(0);
	}
	else
	{
		return(-1);
	}
}
Пример #2
0
TInt Finger()
//
//
//
	{
	RTest test(_L("eSock Emulation test - Simple Finger Server"));

	test.Title();

	User::AfterInMicroSeconds(400000);
   
	// Connect to the actual socket server
	TRequestStatus stat;
	RSocketServ ss;
	TInt ret = ss.Connect();
	test(ret==KErrNone);

	test.Start(_L("Create Server Socket")); // {

	RSocket server;
	ret = server.Open(ss, KAFInet, KSockStream, KProtocolInetTCP);
	test(ret==KErrNone);

	test.Next(_L("Starting server"));
	TInetAddr svraddr(NULL_ADDR, TCP_PORT_FINGER);

	server.Bind(svraddr, stat);
	User::WaitForRequest(stat);
	test(stat==KErrNone);

	// Set client to non-blocking
	server.SetOpt(KSOBlockingIO,NULL,KSOLSocket);

	server.Listen(5, stat);
	User::WaitForRequest(stat);
	test(stat==KErrNone);


	FOREVER
		{
		const TInt KBufLen=256;
		RSocket client;
		TSockAddr cliaddr;

		test.Next(_L("Opening null socket to accept with"));

		ret=client.Open(ss);
		test(ret==KErrNone);

		test.Next(_L("Awaiting connection"));
		// Wait for connection request
		server.SetOpt(KSOBlockingIO,NULL,KSOLSocket);
		client.Accept(server, cliaddr, stat);		
		User::WaitForRequest(stat);
		test(stat==KErrNone);

		test.Next(_L("Get request string"));
		// Set client to non-blocking
		server.SetOpt(KSONonBlockingIO,NULL,KSOLSocket);

		// Read request string from remote client
		TBuf<KBufLen> reqbuf;
  		reqbuf.SetLength(KBufLen);

		test(RecvLine(test, reqbuf, client)>0);
		test.Printf(_L("Request: %s\n"), reqbuf.PtrZ());

		test.Next(_L("Send answer text"));
		TBuf<100> tmpbuf;
  		tmpbuf.SetLength(0);
		tmpbuf.Format(_L("No information available on user \"%s\".\r\n"), reqbuf.PtrZ());
		client.Write(tmpbuf,stat);
		User::WaitForRequest(stat);
		test(stat==KErrNone);
		tmpbuf.Format(_L("\r\n"), reqbuf.PtrZ());
		client.Write(tmpbuf,stat);
		User::WaitForRequest(stat);
		test(stat==KErrNone);

		test.Next(_L("Close"));
		test(client.Close()==KErrNone);
		// break;
		}

	test.Next(_L("Closing"));
	test(server.Close()==KErrNone);

	test.End(); // }

   	return 0;
    
    }
Пример #3
0
int CTcpSock::Listen(int backlog)
{
	return kerr2errno(iSocket.Listen(backlog));
}
Пример #4
0
enum TVerdict CTestStepLoopback::doTestStepL()
	{
	SetTestStepResult(EFail);
	
//	const TUid KPktTxKey = {0x104045dd};
//	const TUid KPktRxKey = {0x104045de};
//	const TUid KMeUid = {0x101F529F};
//	TSecurityPolicy readPolicy(ECapability_None);
//	TSecurityPolicy writePolicy(ECapability_None);
//	TInt result = RProperty::Define(KMeUid, KPktTxKey .iUid, RProperty::EInt, readPolicy, writePolicy);
//	result = RProperty::Define(KMeUid, KPktRxKey .iUid, RProperty::EInt, readPolicy, writePolicy);
	
	
	RSocketServ ss;
	CleanupClosePushL(ss);
	Logger().WriteFormat(_L("Start: creating + starting connection"));
	User::LeaveIfError(ss.Connect());
	RConnection conn;
	CleanupClosePushL(conn);
	User::LeaveIfError(conn.Open(ss));
	User::LeaveIfError(conn.Start());

	TInt srvPort;
	if(!GetIntFromConfig(_L("TcpLoop"), _L("Port"), srvPort))
		{
		srvPort = 5002;
		}
	Logger().WriteFormat(_L("Start: creating server socket listening on %d"), srvPort);
	RSocket srv;
	CleanupClosePushL(srv);
	User::LeaveIfError(srv.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn));
	TInetAddr srvAddr(KAfInet);
	srvAddr.SetPort(srvPort);
	User::LeaveIfError(srv.Bind(srvAddr));
	User::LeaveIfError(srv.Listen(5));
	RSocket acc;
	CleanupClosePushL(acc);
	User::LeaveIfError(acc.Open(ss));
	TRequestStatus accStat;
	srv.Accept(acc, accStat);
	
	Logger().WriteFormat(_L("Start: connecting client socket"));
	RSocket cli;
	CleanupClosePushL(cli);
	User::LeaveIfError(cli.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn));
	srvAddr.SetAddress(0xC0A80707);
	TRequestStatus cliStat;
	cli.Connect(srvAddr, cliStat);
	User::WaitForRequest(cliStat, accStat);
	User::WaitForRequest(cliStat, accStat);
	User::LeaveIfError(cliStat.Int());
	User::LeaveIfError(accStat.Int());

	//_LIT8(KTest, "jackdaws love my big sphinx of quartz");
	
	TInt xferSize = 0;
	if(!GetIntFromConfig(_L("TcpLoop"), _L("xferSize"), xferSize))
		{
		xferSize = 1 * 1000 * 1000;
		}
	TInt fc = User::FastCounter();
	TInt txSize = 0;
	TInt txCnt = 0;
	TRequestStatus txStat(KErrNone);
	TBuf8<4096> txBuf;
	txBuf.SetMax();
	TInt rxSize = 0;
	TInt rxCnt = -1;
	TRequestStatus rxStat(KErrNone);
	TBuf8<4096> rxBuf;
	
	Logger().WriteFormat(_L("Transferring %d bytes"), xferSize);
	while(rxSize < xferSize)
		{
		fc = User::FastCounter();
		if(txStat.Int() != KRequestPending)
			{
			RDebug::Printf("tx status:%d, ", txStat.Int());
			cli.Send(txBuf, 0, txStat);
			++txCnt;
			txSize += txBuf.Length();
			RDebug::Printf("tx #%d, %d, +%d\n", txCnt, fc, txBuf.Length());
			}
		if(rxStat.Int() != KRequestPending)
			{
			RDebug::Printf("rx status:%d, ", rxStat.Int());
			++rxCnt;
			rxSize += rxBuf.Length();
			RDebug::Printf("rx #%d, %d, +%d\n", rxCnt, fc, rxBuf.Length());
			TSockXfrLength dummy;
			acc.RecvOneOrMore(rxBuf, 0, rxStat, dummy);
			}
		User::WaitForRequest(rxStat, txStat);
		}
	
	Logger().WriteFormat(_L("Transferred; %d writes, %d reads"), txCnt, rxCnt);
	
//	RProperty::Get(KUidSystemCategory, KPktTxKey .iUid, txCnt);
//	RProperty::Define(KUidSystemCategory, KPktRxKey .iUid, rxCnt);
//	Logger().WriteFormat(_L("Packet counts; %d sends, %d processes"), txCnt, rxCnt);
	
	
	CleanupStack::PopAndDestroy(5, &ss);
	
	SetTestStepResult(EPass);
	return TestStepResult();
	};