From 887a897c02144f2d01896d3112bdae5ce7d6df5c Mon Sep 17 00:00:00 2001 From: Ariel Manzur Date: Tue, 18 Oct 2016 18:53:18 -0300 Subject: adding ipv6 --- core/io/ip.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'core/io/ip.cpp') diff --git a/core/io/ip.cpp b/core/io/ip.cpp index a77aace07f..aba55687a5 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -32,6 +32,7 @@ #include "hash_map.h" VARIANT_ENUM_CAST(IP::ResolverStatus); +VARIANT_ENUM_CAST(IP_Address::AddrType); /************* RESOLVER ******************/ @@ -43,10 +44,12 @@ struct _IP_ResolverPrivate { volatile IP::ResolverStatus status; IP_Address response; String hostname; + IP_Address::AddrType type; void clear() { status = IP::RESOLVER_STATUS_NONE; response = IP_Address(); + type = IP_Address::TYPE_NONE; hostname=""; }; @@ -78,9 +81,9 @@ struct _IP_ResolverPrivate { if (queue[i].status!=IP::RESOLVER_STATUS_WAITING) continue; - queue[i].response=IP::get_singleton()->resolve_hostname(queue[i].hostname); + queue[i].response=IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type); - if (queue[i].response.host==0) + if (queue[i].response.type==IP_Address::TYPE_NONE) queue[i].status=IP::RESOLVER_STATUS_ERROR; else queue[i].status=IP::RESOLVER_STATUS_DONE; @@ -109,21 +112,21 @@ struct _IP_ResolverPrivate { -IP_Address IP::resolve_hostname(const String& p_hostname) { +IP_Address IP::resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type) { - GLOBAL_LOCK_FUNCTION + GLOBAL_LOCK_FUNCTION; if (resolver->cache.has(p_hostname)) return resolver->cache[p_hostname]; - IP_Address res = _resolve_hostname(p_hostname); + IP_Address res = _resolve_hostname(p_hostname, p_type); resolver->cache[p_hostname]=res; return res; } -IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname) { +IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP_Address::AddrType p_type) { - GLOBAL_LOCK_FUNCTION + GLOBAL_LOCK_FUNCTION; ResolverID id = resolver->find_empty_id(); @@ -133,6 +136,7 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname) { } resolver->queue[id].hostname=p_hostname; + resolver->queue[id].type = p_type; if (resolver->cache.has(p_hostname)) { resolver->queue[id].response=resolver->cache[p_hostname]; resolver->queue[id].status=IP::RESOLVER_STATUS_DONE; @@ -145,10 +149,6 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname) { resolver->resolve_queues(); } - - - - return id; } -- cgit v1.2.3 From 672225b710815865449e7930255468d1c085b137 Mon Sep 17 00:00:00 2001 From: Ariel Manzur Date: Thu, 20 Oct 2016 07:04:10 -0300 Subject: added windows support for ipv6, cleaned up unix code --- core/io/ip.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'core/io/ip.cpp') diff --git a/core/io/ip.cpp b/core/io/ip.cpp index aba55687a5..4ee1b281c4 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -117,7 +117,9 @@ IP_Address IP::resolve_hostname(const String& p_hostname, IP_Address::AddrType p GLOBAL_LOCK_FUNCTION; if (resolver->cache.has(p_hostname)) - return resolver->cache[p_hostname]; + if (resolver->cache[p_hostname].type & p_type != 0) + return resolver->cache[p_hostname]; + // requested type is different from type in cache. continue resolution, if successful it'll overwrite cache IP_Address res = _resolve_hostname(p_hostname, p_type); resolver->cache[p_hostname]=res; @@ -137,7 +139,7 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP_Addr resolver->queue[id].hostname=p_hostname; resolver->queue[id].type = p_type; - if (resolver->cache.has(p_hostname)) { + if (resolver->cache.has(p_hostname) && (resolver->cache[p_hostname].type & p_type) != 0) { resolver->queue[id].response=resolver->cache[p_hostname]; resolver->queue[id].status=IP::RESOLVER_STATUS_DONE; } else { @@ -187,6 +189,14 @@ void IP::erase_resolve_item(ResolverID p_id) { } +void IP::clear_cache(const String &p_hostname) { + + if (p_hostname.empty()) { + resolver->cache.clear(); + } else { + resolver->cache.erase(p_hostname); + } +}; Array IP::_get_local_addresses() const { @@ -208,6 +218,7 @@ void IP::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_resolve_item_address","id"),&IP::get_resolve_item_address); ObjectTypeDB::bind_method(_MD("erase_resolve_item","id"),&IP::erase_resolve_item); ObjectTypeDB::bind_method(_MD("get_local_addresses"),&IP::_get_local_addresses); + ObjectTypeDB::bind_method(_MD("clear_cache"),&IP::clear_cache, DEFVAL("")); BIND_CONSTANT( RESOLVER_STATUS_NONE ); BIND_CONSTANT( RESOLVER_STATUS_WAITING ); -- cgit v1.2.3