示例#1
0
void HXSymbianTCPWriter::Write(RSocket& socket, IHXBuffer* pBuffer)
{
    HX_RELEASE(m_pBuffer);
    m_pBuffer = pBuffer;

    if (m_pBuffer)
    {
	m_pBuffer->AddRef();

	m_bufDes.Set(m_pBuffer->GetBuffer(), m_pBuffer->GetSize());

	iStatus = KRequestPending;
	socket.Write(m_bufDes, iStatus);
	SetActive();
    }
}
示例#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
TVerdict CPPPMinMaxMMU::doTestStepL()
	{
	const TInt KMaxMMU = 4000;
	const TInt KMinMMU = 1;

	TBuf8<KMaxMMU> *sendBuf = new(ELeave) TBuf8<KMaxMMU>();
	CleanupStack::PushL(sendBuf);
	
	TBuf8<KMaxMMU> *recvBuf = new(ELeave) TBuf8<KMaxMMU>();
	CleanupStack::PushL(recvBuf);
	
	TBuf8<KMaxMMU> *recvBuf2 = new(ELeave) TBuf8<KMaxMMU>();
	CleanupStack::PushL(recvBuf2);

    //initialize COMM
    //CommInitL(EFalse);
    
	//Start Comms server
// 	_LIT(KPhbkSyncCMI, "phbsync.cmi");
//    (void)StartC32WithCMISuppressions(KPhbkSyncCMI);
	
	SetTestStepResult(EPass);
    INFO_PRINTF1(_L("Starting: Socket Server\n"));
    
    RSocketServ ss;

    // Start the socket server
    TEST(KErrNone == ss.Connect());
    RSocket sock;
    TRequestStatus sta;
	INFO_PRINTF1(_L("Open a socket\n"));
    
    // Get the test address
    TInetAddr RemAddr(7);
    TPtrC testAddr;
	TEST(GetStringFromConfig(_L("AddressInfo"), _L("TestPPPIPAddr"), testAddr));
	
    if(testAddr.Length())
		{
		RemAddr.Input(testAddr); 
		}
    else
		{
		INFO_PRINTF1(_L("Test FAILED\nMissing address information in config file: "));
		return EFail;
		}
    
    // Open a socket
    TEST(KErrNone == sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp)); 
    INFO_PRINTF1(_L("Connecting Socket to:"));
	
    TBuf<30> printAddr;
    RemAddr.Output(printAddr);
	
    INFO_PRINTF1(printAddr);
	
    // Connect a socket
    sock.Connect(RemAddr,sta);
	
    // Wait for Connect to complete
    User::WaitForRequest(sta);
    TEST(sta.Int() == 0);
    
    TInt iterEnd;
	GetIntFromConfig(_L("MMUInfo"), _L("TestPPPmaxMMU"), iterEnd);
    if (iterEnd > KMaxMMU)
		iterEnd = KMaxMMU;
	
    TInt iterStart;
	GetIntFromConfig(_L("MMUInfo"), _L("TestPPPminMMU"), iterStart);
    if (iterStart < KMinMMU)
		iterStart = KMinMMU;
	
    TInt i,j;
    TSockXfrLength recvLen;
    INFO_PRINTF1(_L("Send/Recv frames"));
    for(j=iterStart;j<=iterEnd;j++)
		{
		sendBuf->Zero();
		
		for (i=0;i<j;i++)
			sendBuf->Append(Math::Random() & 0x7f);
		
		INFO_PRINTF2(_L("Sending Packet of Size: %d"),j);
		// Send data to echo port
		sock.Write(*sendBuf,sta);
		User::WaitForRequest(sta);
		TEST(sta.Int() == 0);
		i=0;
		recvBuf->Zero();
		
		while(i<j)
			{
			// Receive data from echo port
			sock.RecvOneOrMore(*recvBuf2,0,sta,recvLen); 
			User::WaitForRequest(sta);
			TEST(sta.Int() == 0);
			i += recvBuf2->Length();
			recvBuf->Append(*recvBuf2);
			}
		
		TEST(KErrNone == recvBuf->Compare(*sendBuf));
		INFO_PRINTF1(_L("   Received echoed Packet"));
		}
    
    sock.Shutdown(RSocket::EStopOutput,sta);
    User::WaitForRequest(sta);
    TEST(sta.Int() == 0);
    sock.Close();
    ss.Close();

	CleanupStack::PopAndDestroy(3);

	return TestStepResult();
	}