예제 #1
0
파일: variant.cpp 프로젝트: kyoconan/godot
Variant::operator IP_Address() const {

	if (type==REAL_ARRAY || type==INT_ARRAY || type==RAW_ARRAY) {

		DVector<int> addr=operator DVector<int>();
		if (addr.size()==4) {
			return IP_Address(addr.get(0),addr.get(1),addr.get(2),addr.get(3));
		}
	}

	return IP_Address( operator String() );
}
예제 #2
0
파일: ip.cpp 프로젝트: MattUV/godot
IP_Address IP::get_resolve_item_address(ResolverID p_id) const {

	ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP_Address());

	GLOBAL_LOCK_FUNCTION;

	if (resolver->queue[p_id].status != IP::RESOLVER_STATUS_DONE) {
		ERR_EXPLAIN("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet.");
		ERR_FAIL_COND_V(resolver->queue[p_id].status != IP::RESOLVER_STATUS_DONE, IP_Address());
	}

	return resolver->queue[p_id].response;
}
예제 #3
0
Error PacketPeerUDPWinsock::listen(int p_port, IP_Address p_bind_address, int p_recv_buffer_size) {

	ERR_FAIL_COND_V(sockfd != -1, ERR_ALREADY_IN_USE);
	ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);

	sock_type = IP::TYPE_ANY;

	if (p_bind_address.is_valid())
		sock_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;

	int sock = _get_socket();
	if (sock == -1)
		return ERR_CANT_CREATE;

	struct sockaddr_storage addr = { 0 };
	size_t addr_size = _set_listen_sockaddr(&addr, p_port, sock_type, IP_Address());

	if (bind(sock, (struct sockaddr *)&addr, addr_size) == -1) {
		close();
		return ERR_UNAVAILABLE;
	}

	blocking = true;

	printf("UDP Connection listening on port %i\n", p_port);
	rb.resize(nearest_shift(p_recv_buffer_size));
	return OK;
}
예제 #4
0
파일: ip.cpp 프로젝트: Bonfi96/godot
IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Type p_type) {

	resolver->mutex->lock();

	ResolverID id = resolver->find_empty_id();

	if (id == RESOLVER_INVALID_ID) {
		WARN_PRINT("Out of resolver queries");
		resolver->mutex->unlock();
		return id;
	}

	String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type);
	resolver->queue[id].hostname = p_hostname;
	resolver->queue[id].type = p_type;
	if (resolver->cache.has(key)) {
		resolver->queue[id].response = resolver->cache[key];
		resolver->queue[id].status = IP::RESOLVER_STATUS_DONE;
	} else {
		resolver->queue[id].response = IP_Address();
		resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING;
		if (resolver->thread)
			resolver->sem->post();
		else
			resolver->resolve_queues();
	}

	resolver->mutex->unlock();
	return id;
}
예제 #5
0
Error HTTPClient::connect(const String &p_host,int p_port){

	close();
	conn_port=p_port;
	conn_host=p_host;

	if (conn_host.begins_with("http://")) {

		conn_host=conn_host.replace_first("http://","");
	} else if (conn_host.begins_with("https://")) {
		//use https
		conn_host=conn_host.replace_first("https://","");
	}


	connection=tcp_connection;
	if (conn_host.is_valid_ip_address()) {
		//is ip
		Error err = tcp_connection->connect(IP_Address(conn_host),p_port);
		if (err) {
			status=STATUS_CANT_CONNECT;
			return err;
		}

		status=STATUS_CONNECTING;
	} else {
		//is hostname
		resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host);
		status=STATUS_RESOLVING;

	}

	return OK;
}
예제 #6
0
파일: ip.cpp 프로젝트: Bonfi96/godot
IP_Address IP::get_resolve_item_address(ResolverID p_id) const {

	ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP_Address());

	resolver->mutex->lock();

	if (resolver->queue[p_id].status != IP::RESOLVER_STATUS_DONE) {
		ERR_PRINTS("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet.");
		resolver->mutex->unlock();
		return IP_Address();
	}

	IP_Address res = resolver->queue[p_id].response;

	resolver->mutex->unlock();
	return res;
}
예제 #7
0
void StreamPeerWinsock::disconnect() {

	if (sockfd != INVALID_SOCKET)
		closesocket(sockfd);
	sockfd=INVALID_SOCKET;

	status = STATUS_NONE;

	peer_host = IP_Address();
	peer_port = 0;
};
예제 #8
0
파일: ip_unix.cpp 프로젝트: 03050903/godot
IP_Address IP_Unix::_resolve_hostname(const String& p_hostname) {

	struct hostent *he;
	if ((he=gethostbyname(p_hostname.utf8().get_data())) == NULL) {  // get the host info
		ERR_PRINT("gethostbyname failed!");
		return IP_Address();
	}
	IP_Address ip;

	ip.host= *((unsigned long*)he->h_addr);

	return ip;

}
예제 #9
0
Error StreamPeerTCP::_connect(const String& p_address,int p_port) {

	IP_Address ip;
	if (p_address.is_valid_ip_address()) {
		ip=p_address;
	} else {
		ip=IP::get_singleton()->resolve_hostname(p_address, ip_type);
		if (ip==IP_Address())
			return ERR_CANT_RESOLVE;
	}

	connect(ip,p_port);
	return OK;
}
예제 #10
0
Error PacketPeerUDP::_set_dest_address(const String& p_address, int p_port) {

	IP_Address ip;
	if (p_address.is_valid_ip_address()) {
		ip=p_address;
	} else {
		ip=IP::get_singleton()->resolve_hostname(p_address, ip_type);
		if (ip==IP_Address())
			return ERR_CANT_RESOLVE;
	}

	set_dest_address(ip,p_port);
	return OK;
}
예제 #11
0
파일: http_client.cpp 프로젝트: ippan/godot
Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) {

	close();

	conn_port = p_port;
	conn_host = p_host;

	ssl = p_ssl;
	ssl_verify_host = p_verify_host;

	String host_lower = conn_host.to_lower();
	if (host_lower.begins_with("http://")) {

		conn_host = conn_host.substr(7, conn_host.length() - 7);
	} else if (host_lower.begins_with("https://")) {

		ssl = true;
		conn_host = conn_host.substr(8, conn_host.length() - 8);
	}

	ERR_FAIL_COND_V(conn_host.length() < HOST_MIN_LEN, ERR_INVALID_PARAMETER);

	if (conn_port < 0) {
		if (ssl) {
			conn_port = PORT_HTTPS;
		} else {
			conn_port = PORT_HTTP;
		}
	}

	connection = tcp_connection;

	if (conn_host.is_valid_ip_address()) {
		// Host contains valid IP
		Error err = tcp_connection->connect_to_host(IP_Address(conn_host), p_port);
		if (err) {
			status = STATUS_CANT_CONNECT;
			return err;
		}

		status = STATUS_CONNECTING;
	} else {
		// Host contains hostname and needs to be resolved to IP
		resolving = IP::get_singleton()->resolve_hostname_queue_item(conn_host);
		status = STATUS_RESOLVING;
	}

	return OK;
}
예제 #12
0
파일: ip.cpp 프로젝트: Bonfi96/godot
		void clear() {
			status = IP::RESOLVER_STATUS_NONE;
			response = IP_Address();
			type = IP::TYPE_NONE;
			hostname = "";
		};
예제 #13
0
IP_Address LWSClient::get_connected_host() const {

	return IP_Address();
};