Esempio n. 1
0
udt_socket udt_socket::accept()
{
	struct sockaddr_in remote;
	int remote_sz = sizeof(remote);
	memset((char*)&remote, 0, remote_sz);

	UDTSOCKET conn = UDT::accept(_sock, (sockaddr*)&remote, &remote_sz);
	if (conn != UDT::INVALID_SOCK)
		setAsyncWrites(conn, true);
	return udt_socket(conn);
}
Esempio n. 2
0
OnelabNetworkClient::OnelabNetworkClient(std::string name, bool UDT)
  : VirtualClient(name)
{
  _fds = 0;
  _fdu = 0;
  _ip.address = 0;
  _ip.port = 0;
  _connected = false;

  IPv4 local;
  local.address = 0;// FIXME ip4_default_iface();
  local.port = 0;
  UDT::startup();
  if(UDT) _fdu = udt_socket(local, SOCK_STREAM);
  else _fds = ip4_socket(local, SOCK_STREAM);
}
Esempio n. 3
0
PRFileDesc* PR_OpenUDPTransportSocket(PRIntn af, const char* host,
        PRInt32 port) {
    _check_init();
    PRFileDesc* socks[2] = {0};
    UDTSOCKET u_socket = UDT_UDT_SNDBUF;
    PRUdtSocketDesc* p_desc = NULL;

    u_socket = udt_socket(af, SOCK_STREAM, 0);
    PRStatus status_pr = PR_NewTCPSocketPair(socks);

    PRFileDesc* udpt_fd = PR_CreateIOLayerStub(_udpt_desc_identity,
            &udptMethods);

    p_desc = (PRUdtSocketDesc*)PR_Malloc(sizeof(PRUdtSocketDesc));
    int status_udt = udt_bind_events(u_socket, UDT_UDT_EPOLL_IN, (void*)_udp_event_cb, p_desc);

    if ((NULL != udpt_fd) && (NULL != p_desc) && (status_udt >= 0)
    		&& (status_pr == PR_SUCCESS))
    {
        PRFileDesc * sockpair_fd = socks[0];
        memset(p_desc, 0, sizeof(PRUdtSocketDesc));
    	p_desc->sock_pair0 = socks[0];
    	p_desc->sock_pair1 = socks[1];
    	p_desc->dtor       = udpt_fd->dtor;
    	p_desc->udtfd      = u_socket;
        udpt_fd->secret = (PRFilePrivate*)p_desc;
        udpt_fd->lower = sockpair_fd;
        sockpair_fd->higher = udpt_fd;
        udpt_fd->dtor = _udtp_detor;
        return udpt_fd;
    }

    if (NULL != socks[0])
        PR_Close(socks[0]);
    if (NULL != socks[1])
        PR_Close(socks[1]);
    if (UDT_INVALID_SOCK != u_socket)
        udt_close(u_socket);
    if (NULL != p_desc)
        PR_Free(p_desc);
    if (NULL != udpt_fd)
        PR_Close(udpt_fd);

    return NULL;
}
Esempio n. 4
0
File: client.c Progetto: iwanbk/udt
int main(int argc, char* argv[])
{
    if ((3 != argc) || (0 == atoi(argv[2])))
    {
        printf("usage: client server_ip server_port\n");
        return -1;
    }
   
   
    if (udt_startup() != 0)
    {
        printf("udt : startup failed:%s\n", udt_getlasterror_desc());
        return -1;
    }
   
   
    struct addrinfo hints, *local, *peer;

   
    memset(&hints, 0, sizeof(struct addrinfo));

   
    hints.ai_flags = AI_PASSIVE;
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    //hints.ai_socktype = SOCK_DGRAM;
   
    if (0 != getaddrinfo(NULL, argv[2], &hints, &local))
    {
        printf("incorrect network address.\n");
        return -1;
    }

    
    UDTSOCKET client = udt_socket(local->ai_family, local->ai_socktype, local->ai_protocol);

   // UDT Options
   //UDT::setsockopt(client, 0, UDT_CC, new CCCFactory<CUDPBlast>, sizeof(CCCFactory<CUDPBlast>));
   //UDT::setsockopt(client, 0, UDT_MSS, new int(9000), sizeof(int));
   //UDT::setsockopt(client, 0, UDT_SNDBUF, new int(10000000), sizeof(int));
   //UDT::setsockopt(client, 0, UDP_SNDBUF, new int(10000000), sizeof(int));
   //UDT::setsockopt(client, 0, UDT_MAXBW, new int64_t(12500000), sizeof(int));

   // for rendezvous connection, enable the code below
   /*
   UDT::setsockopt(client, 0, UDT_RENDEZVOUS, new bool(true), sizeof(bool));
   if (UDT::ERROR == UDT::bind(client, local->ai_addr, local->ai_addrlen))
   {
      cout << "bind: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }
   */


    freeaddrinfo(local);
   
    if (0 != getaddrinfo(argv[1], argv[2], &hints, &peer))
    {
        printf("incorrect server/peer address. %s:%s\n", argv[1], argv[2]);
        return -1;
   
    }

   
    // connect to the server, implict bind
    if (UDT_ERROR == udt_connect(client, peer->ai_addr, peer->ai_addrlen))
    {
        printf("connect: %s\n", udt_getlasterror_desc());
        return 0;
    }

 
    freeaddrinfo(peer);
   
    // using CC method
    //CUDPBlast* cchandle = NULL;
    //int temp;
   
    //UDT::getsockopt(client, 0, UDT_CC, &cchandle, &temp);
   
    //if (NULL != cchandle)
    //   cchandle->setRate(500);
    
    char* data = malloc(sizeof(char) * DATA_LEN);
    memset(data, 'a', DATA_LEN);

    struct timeval t1, t2;
    gettimeofday(&t1, NULL);
    for (int i = 0; i < N_SEND; i ++)
    {
        //printf("i = %d\n", i);
        if (UDT_ERROR == udt_send(client, data, DATA_LEN, 0))
        {
            printf("send:%s\n", udt_getlasterror_desc());
            break;
        }
    }

    gettimeofday(&t2, NULL);
    int elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;      // sec to ms
    elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;   // us to ms
    printf("finished to write data in %d milliseconds\n", elapsedTime);
    
    udt_close(client);
    free(data);

    if (udt_cleanup() != 0) {
        printf("cleanup:%s", udt_getlasterror_desc());
    }
    return 0;
}