Beispiel #1
0
int UDT_transport_connect(UDT_transport *udt)
{
	char * remote_ip = NULL;
	char * remote_port = NULL;

	remote_ip = ortp_strdup_printf("%s",inet_ntoa(((struct sockaddr_in *)&udt->rtp_session->rtp.rem_addr)->sin_addr));
	remote_port = ortp_strdup_printf("%d",ntohs(((struct sockaddr_in *)&udt->rtp_session->rtp.rem_addr)->sin_port));

	if (0 != getaddrinfo(remote_ip, remote_port, &udt->hints, &udt->peer)){
		return -1;
	}

	if (UDT::ERROR == UDT::connect(udt->udt_socket,udt-> peer->ai_addr,udt->peer->ai_addrlen)){
		ms_error("connect: %s",UDT::getlasterror().getErrorMessage());
		return -2;
	}

	//using CC method
	CUDPBlast* cchandle = NULL;
	int temp;
	UDT::getsockopt(udt->udt_socket, 0, UDT_CC, &cchandle, &temp);
	if (NULL != cchandle)
		cchandle->setRate(1);

	ms_free(remote_ip);
	ms_free(remote_port);
	return 0;
}
Beispiel #2
0
// caller: application
bool UDTConnection::connect( )
{
    struct sockaddr address;
    CCC *cc = NULL;
    int len;

    ConstConnectionDescriptionPtr description = getDescription();
    LBASSERT( CONNECTIONTYPE_UDT == description->type );
    if( !isClosed( ))
        return false;

    _setState( STATE_CONNECTING );

    if( !_parseAddress( description, address, false ))
        goto err;

    LBASSERT( UDT::INVALID_SOCK == _udt );
    _udt = UDT::socket( AF_INET, SOCK_STREAM, 0 );
    if( UDT::INVALID_SOCK == _udt )
    {
        LBERROR << UDTLASTERROR( "UDT::socket" ) << std::endl;
        goto err;
    }

    if( !tuneSocket( ))
        goto err;

    if( UDT::ERROR == UDT::connect( _udt, &address, sizeof( address )))
    {
        LBERROR << UDTLASTERROR( "UDT::connect" ) << std::endl;
        goto err;
    }

    // Do this after connect, otherwise connect itself becomes non-blocking
    static const bool OFF = false;
    if( !setSockOpt( UDT_RCVSYN,
        static_cast<const void *>( &OFF ), sizeof(OFF) ))
        goto err;

    if( UDT::ERROR != UDT::getsockopt( _udt, 0, UDT_CC, &cc, &len ))
    {
        if( NULL != cc )
        {
            CUDPBlast *ccblast = dynamic_cast<CUDPBlast *>( cc );
            if( NULL != ccblast )
                ccblast->setRate( description->bandwidth / 1000. );
        }
    }

    if( initialize( ))
    {
        _setState( STATE_CONNECTED );
        return true;
    }
err:
    return false;
}