コード例 #1
0
enum TVerdict CEsockTest11_1::easyTestStepL()
	{
	// get ip address to connect to
	TInetAddr addr;
	TESTL(GetIpAddressFromConfig(_L("Test_Common"), _L("ipAddress"), addr));
	
	// get port number to connect to
	TInt port;
	TESTL(GetIntFromConfig(_L("Test_11.1"), _L("port"), port));
	
	// set remote address port
	addr.SetPort(port);
	
	// open a TCP socket
	RSocket sock;
	CleanupClosePushL(sock);
	TInt nRet = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp);
	TESTEL(KErrNone == nRet, nRet);
	
	// connect to the remote address
	TRequestStatus stat;
	sock.Connect(addr, stat);
	User::WaitForRequest(stat);
	TESTEL(stat==KErrNone, stat.Int());
	
	// get the remote name of the connected socket
	TInetAddr addr1;
	sock.RemoteName(addr1);
	
	// check this matches the address we connected to
	TESTL(addr.CmpAddr(addr1));
	
	CleanupStack::PopAndDestroy(1, &sock);
	return EPass;
	}
コード例 #2
0
ファイル: ioqueue_symbian.cpp プロジェクト: max3903/SFLphone
//
// Handle asynchronous Accept() completion.
//
CPjSocket *CIoqueueCallback::HandleAcceptCompletion()
{
    CPjSocket *pjNewSock = new CPjSocket (get_pj_socket()->GetAf(),
                                          get_pj_socket()->GetSockType(),
                                          blank_sock_);
    int addrlen = 0;

    if (pending_data_.accept_.new_sock_) {
        *pending_data_.accept_.new_sock_ = (pj_sock_t) pjNewSock;
        pending_data_.accept_.new_sock_ = NULL;
    }

    if (pending_data_.accept_.local_) {
        TInetAddr aAddr;
        pj_sockaddr *ptr_sockaddr;

        blank_sock_.LocalName (aAddr);
        ptr_sockaddr = (pj_sockaddr*) pending_data_.accept_.local_;
        addrlen = *pending_data_.accept_.addrlen_;
        PjSymbianOS::Addr2pj (aAddr, *ptr_sockaddr, &addrlen);
        pending_data_.accept_.local_ = NULL;
    }

    if (pending_data_.accept_.remote_) {
        TInetAddr aAddr;
        pj_sockaddr *ptr_sockaddr;

        blank_sock_.RemoteName (aAddr);
        ptr_sockaddr = (pj_sockaddr*) pending_data_.accept_.remote_;
        addrlen = *pending_data_.accept_.addrlen_;
        PjSymbianOS::Addr2pj (aAddr, *ptr_sockaddr, &addrlen);
        pending_data_.accept_.remote_ = NULL;
    }

    if (pending_data_.accept_.addrlen_) {
        if (addrlen == 0) {
            if (pjNewSock->GetAf() == PJ_AF_INET)
                addrlen = sizeof (pj_sockaddr_in);
            else if (pjNewSock->GetAf() == PJ_AF_INET6)
                addrlen = sizeof (pj_sockaddr_in6);
            else {
                pj_assert (!"Unsupported address family");
            }
        }

        *pending_data_.accept_.addrlen_ = addrlen;
        pending_data_.accept_.addrlen_ = NULL;
    }

    return pjNewSock;
}
コード例 #3
0
int ILibSocketWrapper_recvfrom(int socketObject, char *buffer, int bufferLength, struct sockaddr *src)
{
	RSocket *s = (RSocket*)SocketArray[socketObject];
	TRequestStatus status;
	TInetAddr addr;
	int RetVal=0;
	RBuf8 *buf = new RBuf8();
	
	if(buf->Create(bufferLength)==KErrNone)
	{
		TProtocolDesc aProtocol;
		
		s->Info(aProtocol);
		if(aProtocol.iSockType==KSockStream)
		{
			s->RemoteName(addr);
			((struct in_addr*)src->sa_data)->s_addr = ntohl(addr.Address());
			src->sa_port = htons(addr.Port());
			RetVal = ILibSocketWrapper_recv(socketObject, buffer, bufferLength);
		}
		else
		{
			s->RecvFrom(*buf,addr,(unsigned int)0,status);
			User::WaitForRequest(status);
			if(status!=KErrNone)
			{
				RetVal = 0;
			}
			else
			{
				((struct in_addr*)src->sa_data)->s_addr = ntohl(addr.Address());
				src->sa_port = htons(addr.Port());
				Mem::Copy(buffer,buf->Ptr(),buf->Length());
				RetVal = buf->Length();
			}
		}
	}
	buf->Close();
	delete buf;
	return(RetVal);
}