static PRStatus _udt_connect(PRFileDesc *fd, const PRNetAddr *addr,
		PRIntervalTime timeout){
	///fprintf(stdout, "%s:%d\n", __func__, __LINE__);
	UDTSOCKET s = get_socket_from_fd(fd);
	struct sockaddr_in peer_addr;
	peer_addr.sin_family      = AF_INET;///(addr->raw.family == PR_AF_INET6)? AF_INET6:AF_INET;
	peer_addr.sin_port        = addr->inet.port;
	peer_addr.sin_addr.s_addr = addr->inet.ip;
	bool sync = true, old;
	int optlen;

	if (udt_getsockopt(s, SOL_SOCKET, UDT_UDT_RCVSYN, &old, &optlen) < 0)
		return PR_FAILURE;
	if (udt_setsockopt(s, SOL_SOCKET, UDT_UDT_RCVSYN, &sync, sizeof(sync)) < 0)
		return PR_FAILURE;

	if (udt_connect(s, (sockaddr*)&peer_addr, sizeof(peer_addr)) == 0) {
		// check for sync connect
		if (udt_getsockstate(s) == UDT_CONNECTED) {
			if (udt_setsockopt(s, SOL_SOCKET, UDT_UDT_RCVSYN, &old, sizeof(old)) < 0)
				return PR_FAILURE;
			return PR_SUCCESS;
		} else {
			return PR_FAILURE;
		}
	} else {
		return PR_FAILURE;
	}
}
Exemple #2
0
int udt_close(UDTSOCKET u)
{
    int rc;
    int st = udt_getsockstate(u);

    if ((st == UDT_NONEXIST) ||
        (st == UDT_CLOSED)   ||
        (st == UDT_CLOSING)  ||
        (st == UDT_BROKEN)) {
        // nothing to do on closed or not existed socket
        return 0;
    } else {
        rc = UDT::close(u);
        if (rc == UDT::ERROR) {
            // error happen
            return -1;
        } else {
            return 0;
        }
    }
}