コード例 #1
0
// -----------------------------------------------------------------------------
// CMceLocalAddrResolver::ConstructL
// -----------------------------------------------------------------------------
//
void CMceLocalAddrResolver::ConstructL( TUint32 aIapId )
    {
	// The actual IAP ID is fetched dynamically 
	// to make local IP address lookup work in a case
	// where there are several IAPs used which have different IDs 
	// but all point to the same physical AP.
    
    RConnection connection;
    User::LeaveIfError( connection.Open( iSocketServ ) );
    CleanupClosePushL( connection );
    
    // The connection has to be started to get the actual IAP ID from it
    // At this point the physical connection should be already up
    // as the related SIP profile has been registered using it and
    // the synchronous RConnection::Start should return quickly and
    // should not hang the whole MCE server process for too long
    TConnPrefList prefList;
    TExtendedConnPref preferences;
    preferences.SetIapId( aIapId );
    prefList.AppendL( &preferences ); 
    connection.Start( prefList );    
    
    // Fetch the actual IAP ID from the started connection
	_LIT( KIapIdSetting, "IAP\\Id" );
	User::LeaveIfError( connection.GetIntSetting( KIapIdSetting, iIapId ) );
	
	CleanupStack::PopAndDestroy(); // connection
    }
コード例 #2
0
enum TVerdict CTestIdna08::doTestStepL()
	{

	INFO_PRINTF1(_L(" Testing the Loading of the new Library "));
	INFO_PRINTF1(_L("****************************************"));
	
	SetTestStepResult(EFail); // By default start the test case with failure.	
	
	RLibrary testLibrary;
	TInt err = testLibrary.Load(_L("punycodeconverter.dll"));
	
	if(err == KErrNone)
		{
		INFO_PRINTF1(_L(" Loading the punycodeconverter library is successful"));
		SetTestStepResult(EPass);
		}
	else 
		{	
		INFO_PRINTF1(_L(" Loading the punycodeconverter library is NOT successful"));
		User::LeaveIfError(KErrNone);  // just to suppress the LeaveScan warning
		}
	
	INFO_PRINTF1(_L("Negative Testing of SetOpt		 "));
	INFO_PRINTF1(_L("****************************************"));		

	RSocketServ pSocketServ;
	User::LeaveIfError(pSocketServ.Connect());
	RConnection myConnection;
	myConnection.Open(pSocketServ, KAfInet);

	TRequestStatus myStatus=KErrNone;
	myConnection.Start(myStatus);
	User::WaitForRequest(myStatus);

	RHostResolver hr;
	hr.Open(pSocketServ,KAfInet,KProtocolInetUdp);
	
	TBool enableIdn = ETrue;//enabling the option of IDN support
	TPckgC<TBool> pckgEnable(enableIdn);
	TInt setOptErr = hr.SetOpt(KSoInetConfigInterface , KSolInetDns , pckgEnable);
	if(setOptErr != KErrNone)
		{
		INFO_PRINTF1(_L(" Negative Testing of the Setopt successful "));
		SetTestStepResult(EPass);
		}
	
	setOptErr = hr.SetOpt(KSoDnsEnableIdn , KSolInetDns , pckgEnable);
	User::LeaveIfError(setOptErr);

	enableIdn = EFalse;
	TPckgC<TBool> pckgDisable(enableIdn);
	setOptErr = hr.SetOpt(KSoDnsEnableIdn , KSolInetDns , pckgDisable);
	User::LeaveIfError(setOptErr);
	
	hr.Close();
	myConnection.Close();
	pSocketServ.Close();
	return TestStepResult();

	}
コード例 #3
0
int ILibSocketWrapper_socket(int socketType)
{
	int RetVal;

  // create a new connection for the socket
  RConnection* pConnection = new RConnection;

  // open a connection
  pConnection->Open(socketServer);

  TCommDbConnPref prefs;
  // set the preference for the requested interface
  prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
  pConnection->Start(prefs);	

	if ( (socketType == SOCK_DGRAM) ||
       (socketType == SOCK_STREAM) )
	{
    RSocket *pSocket = new RSocket();

    if ( socketType == SOCK_DGRAM )
    {
      pSocket->Open(socketServer,
                    KAfInet,
                    KSockDatagram,
                    KProtocolInetUdp,
                    *pConnection);
    }
    else
    {
      pSocket->Open(socketServer,
                    KAfInet,
                    KSockStream,
                    KProtocolInetTcp,
                    *pConnection);
    }

    RetVal = ILibSocketWrapper_GetNextAvailableHandle();

    if( RetVal >= 0 )
    {
      SocketArray[RetVal] = (int)pSocket;
      ConnectionArray[RetVal] = pConnection;
    }
    else
    {
      pSocket->Close();
      delete pSocket;
      pConnection->Close();
      delete pConnection;
      RetVal = -1;
    }
  }

  return RetVal;
}
コード例 #4
0
enum TVerdict CTestIdna04::doTestStepL()
	{

	INFO_PRINTF1(_L(" Testing GetByAddress(for an IDN) 	with IDN Enabled     "));
	INFO_PRINTF1(_L("*********************************************************"));
	
	SetTestStepResult(EFail); // By default start the test case with failure.	
	
	RSocketServ pSocketServ;
	User::LeaveIfError(pSocketServ.Connect());
	RConnection myConnection;
	myConnection.Open(pSocketServ, KAfInet);

	TRequestStatus myStatus=KErrNone;
	myConnection.Start(myStatus);
	User::WaitForRequest(myStatus);
	
	RHostResolver hr;
	hr.Open(pSocketServ,KAfInet,KProtocolInetUdp);

	TBool enableIdn = ETrue;//enabling the option of IDN support
	TPckgC<TBool> pckgEnable(enableIdn);
	TInt setOptErr = hr.SetOpt(KSoDnsEnableIdn , KSolInetDns , pckgEnable);
	User::LeaveIfError(setOptErr);
	
	TInetAddr inetAddr;
	//inetAddr.Input(_L("83.241.177.38")); // this is the IPAddress of the domain räksmörgås.josefsson.org
										 // as of 06 Feb 2009. If this IP changes, this test case might fail
										 // but no harm on this.
		
	//TNameEntry resultEntry;
	
	inetAddr.Input(_L("64.233.169.103")); 
	
	TNameRecord asdf;
	TPckgBuf<TNameRecord> resultEntry(asdf);
	
	hr.GetByAddress(inetAddr,resultEntry,myStatus);
	User::WaitForRequest(myStatus);
	TInt err = myStatus.Int();
					
	if(err == KErrNone)
		{
		INFO_PRINTF2(_L(" GetByAddress 	with IDN disabled returned %d"),err);
		SetTestStepResult(EPass);
		}
	
	hr.Close();
	myConnection.Close();
	pSocketServ.Close();

	return TestStepResult();

	}
コード例 #5
0
void CRconn::ConstructL()
{
	TInt err;

	User::LeaveIfError(iServ.Connect());

	err = iConn.Open(iServ);
	if (KErrNone != err) {
		DEBUG_WARNING("iConn.Open err=%d\n", err);
		User::Leave(err);
	}
}
コード例 #6
0
/* 
 * Open an Explicit UDP Socket
 */
void CMultipleArray::OpenExplicitUdpSocketL(TInt aExtraSocksToJoin, RSocketServ iSocketServer)
	{
   /* Get number of sockets from script
	* Open a UDP socket
	* Store socket handle
	* Return the EFail or EPass
	*/
	RSocket* sock;
	RConnection* conn;
	TCommDbConnPref prefs;
	TInt err = 0;
		
	sock = new (ELeave) RSocket;
	conn = new (ELeave) RConnection;
	CleanupStack::PushL(sock);
	CleanupStack::PushL(conn);

	// Start an outgoing connection
	err = conn->Open(iSocketServer);
	if (err!=KErrNone)
		{
		iQoSStep->iQoSSuite->Log(_L("Failed to open Connection: return value = <%d>"), err);
		User::Leave(err);
		}
		
	// Setup SetBearerSet
	prefs.SetBearerSet(iSetBearerSet[aExtraSocksToJoin]);	
	// Setup IAP
	prefs.SetIapId(iIAP[aExtraSocksToJoin]);

	err = conn->Start(prefs);
	if (err!=KErrNone)
		{
		iQoSStep->iQoSSuite->Log(_L("Failed to open socket: return value = <%d>"), err);
		User::Leave(err);
		}

	err = sock->Open(iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp, *conn);
	if (err!=KErrNone)
		{
		iQoSStep->iQoSSuite->Log(_L("Failed to open socket: return value = <%d>"), err);
		User::Leave(err);
		}
		
	AddSocketToListL(sock);
	AddConnectionToListL(conn);

	CleanupStack::Pop(2);	//sock and conn
	}
コード例 #7
0
// Util function
void GetIpFromDHCPServer(void)
    {
    RSocketServ rSockServer;
    if(KErrNone==rSockServer.Connect())
        {
        RConnection rConnect;
        if(KErrNone==rConnect.Open(rSockServer))
            {
            TRequestStatus status; 
            rConnect.Start(status);
                
            User::WaitForRequest(status); 
            }
        } 
    }
コード例 #8
0
enum TVerdict CTestIdna02::doTestStepL()
	{

	INFO_PRINTF1(_L(" Testing GetByName(IDN) 	with IDN Enabled     "));
	INFO_PRINTF1(_L("****************************************************"));
	
	SetTestStepResult(EFail); // By default start the test case with failure.	
	
	RSocketServ pSocketServ;
	User::LeaveIfError(pSocketServ.Connect());
	RConnection myConnection;
	myConnection.Open(pSocketServ, KAfInet);

	TRequestStatus myStatus=KErrNone;
	myConnection.Start(myStatus);
	User::WaitForRequest(myStatus);

	_LIT(KTestName1,"räksmörgås.josefsson.org");
		
	TName myHostName = KTestName1();
	TNameEntry myResolvedName;
	RHostResolver hr;
	hr.Open(pSocketServ,KAfInet,KProtocolInetUdp);
	
	TBool enableIdn = ETrue;//enabling the option of IDN support
	TPckgC<TBool> pckgEnable(enableIdn);
	TInt setOptErr = hr.SetOpt(KSoDnsEnableIdn , KSolInetDns , pckgEnable);
	User::LeaveIfError(setOptErr);
	
	hr.GetByName(myHostName,myResolvedName,myStatus);
		
	User::WaitForRequest(myStatus);
	TInt err = myStatus.Int();
	
	if(err == KErrNone)
		{
		INFO_PRINTF2(_L(" GetByName(%S) with IDN Enabled   returned KErrNone "),&myHostName);
		SetTestStepResult(EPass);
		}
	
	hr.Close();
	myConnection.Close();
	pSocketServ.Close();

	return TestStepResult();

	}
コード例 #9
0
void CTe_rtpSuite::ConfigureReflectorModeL(TBool aMode, TInetAddr& aAddr)
	{
    /* Configures the reflector to change the SSRC or not
     */	
	RSocketServ sockServer;
	//Open a connection
	RConnection conn;
	User::LeaveIfError(sockServer.Connect());
	CleanupClosePushL(sockServer);
	
	User::LeaveIfError(conn.Open(sockServer));
	CleanupClosePushL(conn);
	
	//Start the connection
	User::LeaveIfError(conn.Start());
	
	RSocket ctrlSock;
	User::LeaveIfError(ctrlSock.Open(sockServer,KAfInet, KSockDatagram, KProtocolInetUdp, conn));
	CleanupClosePushL(ctrlSock);
	
    TBuf8<64> lCmdBuff;
    TUint8* lPtr = const_cast<TUint8*>(lCmdBuff.Ptr());
    TUint32* lIntData = (TUint32*)lPtr;
    *lIntData = ByteOrder::Swap32(0xFF00BABE);
    if (aMode)
    	{
    	*(lIntData + 1) = ByteOrder::Swap32(0xCD000100);
    	}
    else
    	{
    	*(lIntData + 1) = ByteOrder::Swap32(0xCD000101);
    	}
    lCmdBuff.SetLength(64);
    
    TRequestStatus lMyReqStat;
    ctrlSock.SendTo(lCmdBuff,aAddr,0,lMyReqStat);
    User::WaitForRequest(lMyReqStat);
    
    ctrlSock.Close();
    conn.Close();
    sockServer.Close();
    
    CleanupStack::Pop(3);
	}
コード例 #10
0
enum TVerdict CTestIdna05::doTestStepL()
	{
	INFO_PRINTF1(_L(" Testing GetByName(IDN in UTF-16) 	without IDN Enabled     "));
	INFO_PRINTF1(_L("***********************************************************"));

	SetTestStepResult(EFail); // By default start the test case with failure.
	
	RSocketServ pSocketServ;
	User::LeaveIfError(pSocketServ.Connect());
	RConnection myConnection;
	myConnection.Open(pSocketServ, KAfInet);

	TRequestStatus myStatus=KErrNone;
	myConnection.Start(myStatus);
	User::WaitForRequest(myStatus);

	RHostResolver hr;
	hr.Open(pSocketServ,KAfInet,KProtocolInetUdp);

	THostName utf16HostName;
	TInt surrogateInt = 55301 ; //0xD805
	utf16HostName.Copy((const unsigned short*)&surrogateInt);
	surrogateInt = 57173; // 0xDF55
	utf16HostName.Append((const unsigned short*)&surrogateInt, sizeof(TInt));
		
	TNameEntry myResolvedName;
	hr.GetByName(utf16HostName,myResolvedName,myStatus);
	User::WaitForRequest(myStatus);
	TInt err = myStatus.Int();

	if(err == KErrDndBadName)
		{
		INFO_PRINTF1(_L(" GetByName (IDN in UTF16) 	without IDN enabled returned KErrDndBadName"));
		SetTestStepResult(EPass);
		}

	hr.Close();
	myConnection.Close();
	pSocketServ.Close();

	return TestStepResult();

	}
コード例 #11
0
enum TVerdict CTestIdna03::doTestStepL()
	{

	INFO_PRINTF1(_L(" Testing GetByAddress(for an IDN) 	without IDN Enabled     "));
	INFO_PRINTF1(_L("*********************************************************"));
	
	SetTestStepResult(EFail); // By default start the test case with failure.	
	
	RSocketServ pSocketServ;
	User::LeaveIfError(pSocketServ.Connect());
	RConnection myConnection;
	myConnection.Open(pSocketServ, KAfInet);

	TRequestStatus myStatus=KErrNone;
	myConnection.Start(myStatus);
	User::WaitForRequest(myStatus);
	
	RHostResolver hr;
	hr.Open(pSocketServ,KAfInet,KProtocolInetUdp);
	
	TInetAddr inetAddr;
	inetAddr.Input(_L("83.241.177.38")); // this is the IPAddress of the domain räksmörgås.josefsson.org
										 // as of 06 Feb 2009. If this IP changes, this test case might fail
										 // but no harm on this.
		
	TNameEntry resultEntry;
	hr.GetByAddress(inetAddr,resultEntry,myStatus);
	User::WaitForRequest(myStatus);
	TInt err = myStatus.Int();
					
	if(err == KErrNone)
		{
		INFO_PRINTF2(_L(" GetByAddress 	with IDN disabled returned %d"),err);
		SetTestStepResult(EPass);
		}
	
	hr.Close();
	myConnection.Close();
	pSocketServ.Close();

	return TestStepResult();

	}
コード例 #12
0
enum TVerdict CTestIdna01::doTestStepL()
	{

	INFO_PRINTF1(_L(" Testing GetByName(IDN) 	without IDN Enabled     "));
	INFO_PRINTF1(_L("****************************************************"));
	
	SetTestStepResult(EFail); // By default start the test case with failure.	
	
	RSocketServ pSocketServ;
	User::LeaveIfError(pSocketServ.Connect());
	RConnection myConnection;
	myConnection.Open(pSocketServ, KAfInet);

	TRequestStatus myStatus=KErrNone;
	myConnection.Start(myStatus);
	User::WaitForRequest(myStatus);

	_LIT(KTestName1,"räksmörgås.josefsson.org");
		
	TName myHostName = KTestName1();
	TNameEntry myResolvedName;
	RHostResolver hr;
	hr.Open(pSocketServ,KAfInet,KProtocolInetUdp);

	hr.GetByName(myHostName,myResolvedName,myStatus);
		
	User::WaitForRequest(myStatus);
	TInt err = myStatus.Int();
	
	if(err == KErrDndNameNotFound)
		{
		INFO_PRINTF2(_L(" GetByName(%S) 	without IDN Enabled   returned KErrDndNameNotFound "),&myHostName);
		SetTestStepResult(EPass);
		}
	
	hr.Close();
	myConnection.Close();
	pSocketServ.Close();

	return TestStepResult();

	}
XQAccessPoint XQAccessPointManagerPrivate::systemAccessPointL() const
{
    XQAccessPoint iap;

    RSocketServ serv;
    TInt retVal = serv.Connect();
    if (retVal != KErrNone) {
        return iap;
    }
    CleanupClosePushL(serv);
    RConnection conn;
    retVal = conn.Open(serv);
    if (retVal != KErrNone) {
        CleanupStack::PopAndDestroy(&serv);
        return iap;
    }
    CleanupClosePushL(conn);
    retVal = conn.Start();
    if (retVal != KErrNone) {
        CleanupStack::PopAndDestroy(&conn);
        CleanupStack::PopAndDestroy(&serv);
        return iap;
    }
    
    _LIT(KSetting, "IAP\\Id");
    unsigned long int iapId = 0;
    conn.GetIntSetting(KSetting, iapId);

    CleanupStack::PopAndDestroy(&conn);
    CleanupStack::PopAndDestroy(&serv);

    QList<XQAccessPoint> iaps = accessPoints();
    for (int i=0; i < iaps.count(); i++) {
        if (iaps[i].id() == iapId) {
            iap = iaps[i];
            break;
        }
    }
    
    return iap;
}
コード例 #14
0
// ---------------------------------------------------------
// RHssInterface::StopConnectionL
// ---------------------------------------------------------
//
TInt RHssInterface::StopConnectionL( const TUint aIapId, const TUint aNetworkId )
    {
    DEBUG( "RHssInterface::StopConnectionL()" );

    TInt ret( KErrNone );
    RSocketServ socketServ;
    RConnection conn;

    User::LeaveIfError( socketServ.Connect() );
    CleanupClosePushL( socketServ );
    
    // Open connection
    User::LeaveIfError( conn.Open(socketServ) );
    CleanupClosePushL( conn );

    TConnectionInfo info;
    info.iIapId = aIapId;
    info.iNetId = aNetworkId;

    TInt err = conn.Attach(
            TPckg< TConnectionInfo >( info ),
            RConnection::EAttachTypeNormal );
    DEBUG1( "RHssInterface::conn.Attach: %d", err );

    if ( err == KErrNone )
        {
        ret = conn.Stop( RConnection::EStopAuthoritative );
        DEBUG1( "RHssInterface::connection.Stop: %d", ret );
        }

    /* Note: In previous version, tried to PopAndDestroy conn (RConnection)
     * from cleanup stack...
     * => Somehow this broke Sniffer connection opening, no idea why.
     */
    CleanupStack::Pop( &conn );
    conn.Close();
    CleanupStack::PopAndDestroy( &socketServ );
    
    return ret;
    }
コード例 #15
0
ファイル: tcptest.cpp プロジェクト: cdaffara/symbiandump-os2
void CTcpProcess::ConstructL()
	{
	//Create the data buffer
	User::LeaveIfError(iSendBuf.Create(iSize));
	User::LeaveIfError(iRecvBuf.Create(iSize));
	iRecvSize = iSize;
	
	iProcessState = ECreateConnection;
	
	User::LeaveIfError(iSockServ.Connect());
	if(iMode)
		{
		//Listen at specified port
		TBuf<5>		 protocol = _L("tcp");
		User::LeaveIfError(iListenSocket.Open(iSockServ, protocol));
		User::LeaveIfError(iListenSocket.SetOpt(KSoReuseAddr, KProtocolInetIp, 1));
		User::LeaveIfError(iListenSocket.SetLocalPort(iPort));
		User::LeaveIfError(iListenSocket.Listen(5));
		User::LeaveIfError(iSocket.Open(iSockServ));
		iListenSocket.Accept(iSocket, iStatus);
		iConsole.Printf(_L("\nWait for a connection at port[%d].\n"), iPort);
		}
	else
		{
        RConnection conn;  
        User::LeaveIfError(conn.Open(iSockServ));
        TCommDbConnPref pref;
        pref.SetIapId(13);
        pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
        User::LeaveIfError(conn.Start(pref));
        
		//Connect to specified server
		User::LeaveIfError(iSocket.Open(iSockServ, KAfInet, KSockStream, KProtocolInetTcp, conn));
		iSocket.Connect(iAddr, iStatus);

		iConsole.Printf(_L("\nConnecting....\n"));
		}
	SetActive();
	}
コード例 #16
0
ファイル: tcptest.cpp プロジェクト: cdaffara/symbiandump-os2
void CUdpProcess::ConstructL()
    {
    //Create the data buffer
    User::LeaveIfError(iSendBuf.Create(iSize));
    User::LeaveIfError(iRecvBuf.Create(iSize));
    iRecvSize = iSize;

    User::LeaveIfError(iSockServ.Connect());

    // Start NCM IAP
    RConnection conn;
    User::LeaveIfError(conn.Open(iSockServ));
    TCommDbConnPref pref;
    pref.SetIapId(13);
    pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    User::LeaveIfError(conn.Start(pref));
    
    User::LeaveIfError(iSocket.Open(iSockServ, KAfInet, KSockDatagram,
            KProtocolInetUdp, conn));
    
    iConsole.Printf(_L("In constructL, port=%d"), iAddr.Port());
    
    if (iMode)
        {
        iProcessState = EDataTransfer;
       
        User::LeaveIfError(iSocket.SetLocalPort(iPort));
        iSocket.RecvFrom(iRecvBuf, iPeerAddr, 0, iStatus);
        iConsole.Printf(_L("\nWait for UDP incoming data at port[%d]...\n"),iPort);
        SetActive();
        }
    else 
        {
        iProcessState = EDataSending;
        SetActive();
        TRequestStatus* status = &iStatus;
        User::RequestComplete(status, KErrNone);
        }
    }
コード例 #17
0
// ---------------------------------------------------------------------------
// CRoHandlerDMgrWrapper::PostResponseUrlL
// ---------------------------------------------------------------------------
//
void CRoHandlerDMgrWrapper::PostResponseUrlL( const TDesC8& aPostResponseUrl )
    {
    UpdateBufferL< HBufC8, TDesC8 >( iTriggerUrl, aPostResponseUrl );

    if ( !iIapId )
        {
        // Take AP from open conenction
        RSocketServ socketServer;

        TInt err( KErrNone );

        err = socketServer.Connect();

        RConnection myConnection;

        err = myConnection.Open( socketServer );

        TUint connectionCount( 0 );

        err = myConnection.EnumerateConnections( connectionCount );

        if ( err != KErrNone || connectionCount < 1 )
            {
            return;
            }

        TPckgBuf<TConnectionInfoV2> connectionInfo;

        err = myConnection.GetConnectionInfo( connectionCount,
                connectionInfo );

        iIapId = connectionInfo().iIapId;

        myConnection.Close();
        socketServer.Close();
        }
    }
コード例 #18
0
// -----------------------------------------------------------------------------
// CSIPApnConfigurationHandler::IsInUseL
// -----------------------------------------------------------------------------
//
TBool CSIPApnConfigurationHandler::IsInUseL( TConnectionInfo& aConnectionInfo )
    {
    PROFILE_DEBUG1( 
            "CSIPApnConfigurationHandler::IsInUseL()" )
    
    TBool inUse( EFalse );
    RConnection rcon;
    User::LeaveIfError( rcon.Open( iSocketSrv ) );
    CleanupClosePushL( rcon );
    
    TUint activeCount( 0 );
    User::LeaveIfError( rcon.EnumerateConnections( activeCount ) );
    
    if ( activeCount > 0  )
        {
        // Indexing is unordinary
        for( TUint i = 1; i <= activeCount && !inUse; i++ )
            {
            TPckgBuf<TConnectionInfoV2> connectionInfo;
            User::LeaveIfError( rcon.GetConnectionInfo( i, connectionInfo ) );
            
            if ( connectionInfo().iIapId == iIapId )
                {
                inUse = ETrue;
                aConnectionInfo = connectionInfo();
                }
            }
        }
        
    CleanupStack::PopAndDestroy( &rcon );
    
    PROFILE_DEBUG3( 
            "CSIPApnConfigurationHandler::IsInUseL() inuse", inUse )
    
    return inUse;
    }
コード例 #19
0
enum TVerdict CTestStepNullAgtLoopbackTest::doTestStepL(void)
{
    __UHEAP_MARK;

    TInt r;                // the result of various operations
    TRequestStatus status; // status of asynchronous ops

    RSocketServ server;    // connection paraphanelia
    RConnection connection;
    RSocket socket;

    TInetAddr dest;
    dest.SetAddress(KDummyNifLocalAddressBase + 4);
    dest.SetPort(KPortNo);

    TBuf8<KBufferLength> buffer;

    // connect to the socket server
    r = server.Connect();
    TESTEL(r == KErrNone, r);
    CleanupClosePushL(server);

    // this is why we needed a socket server...
    r = connection.Open(server, KAfInet);
    TESTEL(r == KErrNone, r);
    CleanupClosePushL(connection);

    // start the connection up (outgoing)
    connection.Start(status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());

    // open a udp socket
    r = socket.Open(server, KAfInet, KSockDatagram, KProtocolInetUdp);
    TESTEL(r == KErrNone, r);
    CleanupClosePushL(socket);
    TESTL(socket.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone);
    // set the source port number - otherwise will panic cos it's zero
    r = socket.SetLocalPort(KPortNo);
    TESTEL(r == KErrNone, r);

    // build some data to send on the socket
    // this is an ICMP ping request apparently
    buffer.SetMax();
    buffer.FillZ();
    buffer[0] = (TUint8) 0x8;		// ICMP type = 8
    buffer[1] = (TUint8) 0x0;		// ICMP code = 0
    buffer[2] = (TUint8) 0xF7;		// ICMP checksum high byte
    buffer[3] = (TUint8) 0xFF;		// ICMP checksum low byte
    // NB the rest of the buffer is zero
    // hence the checksum (0xFFFF - 0x800) since 0x8
    // is the only non-zero element of the buffer

    // send the data out over the socket
    socket.SendTo(buffer, dest, 0, status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());

    buffer.Zero();
    // I expect to get the data looped back from the dummy NIF
    socket.RecvFrom(buffer, dest, 0, status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());

    // check that what we sent is what we got back
    if (status.Int() == KErrNone)
    {
        // if the receive times out and we access buffer we get a panic
        TEST(buffer[0] == 0x08);
        TEST(buffer[1] == 0x00);
        TEST(buffer[2] == 0xF7);
        TEST(buffer[3] == 0xFF);
    }

    // close the socket
    socket.Shutdown(RSocket::ENormal, status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());
    CleanupStack::Pop();

    // force the destruction of the connection
    r = connection.Stop();
    TESTEL(r == KErrNone, r);
    CleanupStack::Pop();

    // close the socket server
    server.Close();
    CleanupStack::Pop();

    __UHEAP_MARKEND;

    return iTestStepResult;
}
コード例 #20
0
// Main 
void MainL()
	{
	/* Inetd Setup 
	Create a inetd process 
	*/
	RProcess inetd;
	CleanupClosePushL(inetd);
	User::LeaveIfError(inetd.Create(_L("inetd"), _L("")));
	
	// Resume inetd
	inetd.Resume();
	
	// Wait for inetd to be ready
	console->Printf(_L("[ press any key ]"));
	console->Getch();	// Get and ignore character

	
	/* IPEcho Part 
	Connect to socket server 
	*/
	console->Printf(_L("Connect to socket server ... \n"));
	RSocketServ socketServ;
	CleanupClosePushL(socketServ);
	User::LeaveIfError(socketServ.Connect());
	
	// Open RConnection
	console->Printf(_L("Open RConnection ... \n"));
	RConnection connect;
	CleanupClosePushL(connect);
	User::LeaveIfError(connect.Open(socketServ, KConnectionTypeDefault));

	// Start RConnection
	console->Printf(_L("Start RConnection ... \n"));
	TCommDbConnPref prefs;
	prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
	User::LeaveIfError(connect.Start(prefs));	// Handle options here like (ie: No Prompt)

	// Open RSocket
	console->Printf(_L("Open Socket ... \n"));
	RSocket sock;
	CleanupClosePushL(sock);
	User::LeaveIfError(sock.Open(socketServ, KAfInet, KSockStream, KProtocolInetTcp, connect));

	// Connect
	console->Printf(_L("Connect Socket ... \n"));
	TRequestStatus status;
	TInetAddr echoServAddr(KInetAddrLoop, 7);	// 7: TCP port 
	sock.Connect(echoServAddr, status);
	User::WaitForRequest(status);
	User::LeaveIfError(status.Int());

	// Wait for the socket transfer to be over 
	console->Printf(_L("[ press any key ]"));
	console->Getch();	// Get and ignore character
	
	// Send a packet
	console->Printf(_L("Send a packet ... \n"));
	HBufC8* packet = HBufC8::NewL(KSocketDefaultBufferSize);
	CleanupStack::PushL(packet);

	packet->Des().SetMax();
	packet->Des().FillZ();
	sock.Send(packet->Des(), 0, status);
	User::WaitForRequest(status);
	User::LeaveIfError(status.Int());
	
	// Receive it back
	console->Printf(_L("Received it back ... \n"));
	packet->Des().Zero();
	TPtr8 buff = packet->Des();
	sock.Recv(buff, 0, status);
	User::WaitForRequest(status);
	User::LeaveIfError(status.Int());

	
	// Terminates 
	console->Printf(_L("Terminates ... \n"));
	CleanupStack::PopAndDestroy(packet);
	CleanupStack::PopAndDestroy(&sock);
	CleanupStack::PopAndDestroy(&connect);
	CleanupStack::PopAndDestroy(&socketServ);
	CleanupStack::PopAndDestroy(&inetd);
	}
コード例 #21
0
TVerdict CmoveConnectedSocketToSubconnectionStep::doSingleTestStep()
	{
	
	RSocket			socket;
	TInetAddr		dstAddr;
	RSocketServ		socketServer;
	RConnection		conn;
	RSubConnection	subconn;
	TRequestStatus	status;
	TRequestStatus 	eventStatus;
	TNotificationEventBuf	subconnNotifBuf;
	TInt				ret;
	
	CleanupClosePushL(socketServer);
   	CleanupClosePushL(conn);
    	CleanupClosePushL(socket);
    	CleanupClosePushL(subconn);

    	// Connect to ESOCK
    	ret = socketServer.Connect();
    	if (ret != KErrNone)
    		{
    		INFO_PRINTF2(_L("Failed to connect toEsock due to Error: %d."),ret);
    		return EFail;
    		}
  
        	// Open a connection
    	ret = conn.Open(socketServer);
	if (ret != KErrNone)
    		{
    		INFO_PRINTF2(_L("Failed to open connection due to Error: %d."),ret);
    		return EFail;
    		}

	// Start the connection
	conn.Start(status);
	User::WaitForRequest(status);
	
	if (status != KErrNone)
    		{
    		INFO_PRINTF2(_L("Failed to start connection due to Error: %d."),status.Int());
    		return EFail;
    		}


	// Open UDP socket
	ret = socket.Open(socketServer,
			KAfInet,
	                      KSockDatagram,
	                      KProtocolInetUdp,
	                      conn);
	if (ret != KErrNone)
    		{
    		INFO_PRINTF2(_L("Failure to open socket due to Error: %d."),ret);
    		return EFail;
    		}
	
	
	dstAddr.SetPort(3441);
	_LIT(KText50, "127.0.0.1");
	dstAddr.Input( KText50 );

	ret = socket.SetLocalPort(3442);
	if (ret != KErrNone)
    		{
    		INFO_PRINTF2(_L("Failed to set port on socket due to Error: %d."),ret);
    		return EFail;
    		}
    		
	socket.Connect(dstAddr, status);
	User::WaitForRequest(status);

	if (status != KErrNone)
    		{
    		INFO_PRINTF2(_L("Socket failed to connect to dst addr due to Error: %d."),status.Int());
    		return EFail;
    		}

	// Create a new sub-connection
	ret = subconn.Open(socketServer,
	                   RSubConnection::ECreateNew,
	                   conn);
	if (ret != KErrNone)
    		{
    		INFO_PRINTF2(_L("Failed to create new sub-connection due to Error: %d."),ret);
    		return EFail;
    		}
    		
	 // Move the connected socket onto the new sub-connection
	subconn.Add(socket, status);
	User::WaitForRequest(status);

	if (status != KErrNotReady)
    		{
    		INFO_PRINTF2(_L("Socket could not be added to subconn due to  Error: %d."),status.Int());
    		return EFail;
    		}

	 // close and destroy
	CleanupStack::PopAndDestroy(&subconn);
	CleanupStack::PopAndDestroy(&socket);
	CleanupStack::PopAndDestroy(&conn);
	CleanupStack::PopAndDestroy(&socketServer);
	
 	return EPass;
	}
コード例 #22
0
ファイル: INETD.CPP プロジェクト: kuailexs/symbiandump-os2
// Main
void MainL()
{
    /* Arguments:
    Not implemented in this test case.
    Note: Implement if necessary
     */


    /* Connection part:
    Here we want to open all requirements:
    	- RSocketServer connection
    	- RSocket
    We also want to start RConnection
     */

    // Connect to socket server
    console->Printf(_L("Connect RSocketServ ... "));
    RSocketServ socketServ;
    CleanupClosePushL(socketServ);
    User::LeaveIfError(socketServ.Connect());
    console->Printf(_L("OK\n"));

    // Open RConnection
    console->Printf(_L("Open RConnection ... "));
    RConnection connect;
    CleanupClosePushL(connect);
    User::LeaveIfError(connect.Open(socketServ, KConnectionTypeDefault));
    console->Printf(_L("OK\n"));

    // Start RConnection
    console->Printf(_L("Start RConnection ... "));

    /* In a real inetd you would probably want to avoid the IAP prompting.
    You could do it this way:

    TCommDbConnPref prefs;
    prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    User::LeaveIfError(connect.Start(prefs));	// Handle options here (ie: No Prompt)

    */
    User::LeaveIfError(connect.Start());
    console->Printf(_L("OK\n"));


    /* Configuration file:
    We read configuration file.
    We will create a listener for each line.
    It will listen and accept connection for the
    specified protocol, then it will launch
    the appropriate program and continue
    to listen.

    Our basic inetd.conf file is:
    	==> ServiceName: Contains the name of an Internet service.
    	==> SocketType: Specifies which socket to use.
    	==> ProtocolName: Contains the name of an Internet protocol.
    	==> ProtocolPort: Specifies which port to use.
    	==> ServerName: Contains the name of program to launch.
    	==> ServerArgs: Contains program arguments.
     */

    // Connect to file server
    console->Printf(_L("Connect to file server ... "));
    TListeners listeners;
    CleanupStack::PushL(TCleanupItem(TCleanupOperation(DestroyPointerArray), &listeners));
    RFs fileServ;
    CleanupClosePushL(fileServ);
    User::LeaveIfError(fileServ.Connect());
    console->Printf(_L("OK\n"));

    // Search file
    TFindFile ff(fileServ);
    TInt ret = ff.FindByDir(KConfigFileName, KConfigFileDir);
    if(ret != KErrNone)
    {
        if(ret == KErrNotFound)
        {
            console->Printf(_L("Can't find file '%S'\n"), &KConfigFileName);
        }
        else
        {
            User::LeaveIfError(ret);
        }
    }
    else
    {
        // File Open
        console->Printf(_L("Open file ... "));
        RFile configFile;
        CleanupClosePushL(configFile);
        ret = configFile.Open(fileServ, ff.File(), EFileRead);
        if(ret != KErrNone)
        {
            if(ret == KErrNotFound)
            {
                console->Printf(_L("Can't open file '%S'\n"), &KConfigFileName);
            }
            else
            {
                User::LeaveIfError(ret);
            }
        }
        else
        {
            console->Printf(_L("OK\n"));

            // Read File (Here, we read the whole file as we know it's small. Not optimal)
            ReadConfigFileL(configFile, listeners, socketServ, connect);
        }

        // We have Finished with file
        CleanupStack::PopAndDestroy(&configFile);
    }

    // We have finished with file server
    CleanupStack::PopAndDestroy(&fileServ);

    // Test here for the number of listeners or any config file error.
    // If 0, then we've got no configuration in file
    console->Printf(_L("NbListeners: %d\n"), listeners.Count());

    if(listeners.Count() != 0)
    {
        /* Launch listeners
        Start the active scheduler
         */
        console->Printf(_L("Start ... \n"));
        // Set up timer to stop inetd (Test case implementation)
        CInetdExitTimer* timeToRun = CInetdExitTimer::NewL();
        CleanupStack::PushL(timeToRun);
        timeToRun->After(KRunTime);

        // Start active scheduler for listeners to accept
        CActiveScheduler::Start();

        // End of Inetd, triggered by CInetdExitTimer::RunL()
        console->Printf(_L("Stop\n"));

        CleanupStack::PopAndDestroy(timeToRun);	// Delete timeToRun
    }

    /* Destroy listeners
    Cancel all pending listeners
    Delete them
     */
    console->Printf(_L("Delete listeners ... "));
    CleanupStack::PopAndDestroy(&listeners);
    console->Printf(_L("OK\n"));

    // Close all opened stuff
    console->Printf(_L("Closing ... "));
    CleanupStack::PopAndDestroy(&connect);
    CleanupStack::PopAndDestroy(&socketServ);
    console->Printf(_L("End\n"));
}
コード例 #23
0
ファイル: test.cpp プロジェクト: cdaffara/symbiandump-os1
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();
	};