diff options
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/ip.cpp | 4 | ||||
-rw-r--r-- | core/io/packet_peer_udp.cpp | 8 | ||||
-rw-r--r-- | core/io/packet_peer_udp.h | 4 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.cpp | 19 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.h | 2 | ||||
-rw-r--r-- | core/io/tcp_server.cpp | 2 | ||||
-rw-r--r-- | core/io/tcp_server.h | 4 |
7 files changed, 31 insertions, 12 deletions
diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 4ee1b281c4..f0f273af1a 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -212,8 +212,8 @@ Array IP::_get_local_addresses() const { void IP::_bind_methods() { - ObjectTypeDB::bind_method(_MD("resolve_hostname","host"),&IP::resolve_hostname); - ObjectTypeDB::bind_method(_MD("resolve_hostname_queue_item","host"),&IP::resolve_hostname_queue_item); + ObjectTypeDB::bind_method(_MD("resolve_hostname","host","ip_type"),&IP::resolve_hostname,DEFVAL(IP_Address::TYPE_ANY)); + ObjectTypeDB::bind_method(_MD("resolve_hostname_queue_item","host","ip_type"),&IP::resolve_hostname_queue_item,DEFVAL(IP_Address::TYPE_ANY)); ObjectTypeDB::bind_method(_MD("get_resolve_item_status","id"),&IP::get_resolve_item_status); 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); diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 018dc77d91..925d00a84a 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -38,13 +38,13 @@ String PacketPeerUDP::_get_packet_ip() const { return get_packet_address(); } -Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port) { +Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port,IP_Address::AddrType p_type) { IP_Address ip; if (p_address.is_valid_ip_address()) { ip=p_address; } else { - ip=IP::get_singleton()->resolve_hostname(p_address); + ip=IP::get_singleton()->resolve_hostname(p_address, p_type); if (ip==IP_Address()) return ERR_CANT_RESOLVE; } @@ -55,14 +55,14 @@ Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port) { void PacketPeerUDP::_bind_methods() { - ObjectTypeDB::bind_method(_MD("listen:Error","port","recv_buf_size"),&PacketPeerUDP::listen,DEFVAL(65536)); + ObjectTypeDB::bind_method(_MD("listen:Error","port","ip_type", "recv_buf_size"),&PacketPeerUDP::listen,DEFVAL(IP_Address::TYPE_ANY),DEFVAL(65536)); ObjectTypeDB::bind_method(_MD("close"),&PacketPeerUDP::close); ObjectTypeDB::bind_method(_MD("wait:Error"),&PacketPeerUDP::wait); ObjectTypeDB::bind_method(_MD("is_listening"),&PacketPeerUDP::is_listening); ObjectTypeDB::bind_method(_MD("get_packet_ip"),&PacketPeerUDP::_get_packet_ip); //ObjectTypeDB::bind_method(_MD("get_packet_address"),&PacketPeerUDP::_get_packet_address); ObjectTypeDB::bind_method(_MD("get_packet_port"),&PacketPeerUDP::get_packet_port); - ObjectTypeDB::bind_method(_MD("set_send_address","host","port"),&PacketPeerUDP::_set_send_address); + ObjectTypeDB::bind_method(_MD("set_send_address","host","port","ip_type"),&PacketPeerUDP::_set_send_address,DEFVAL(IP_Address::TYPE_ANY)); } diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index c0806a9e6a..37e700cebd 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -42,11 +42,11 @@ protected: String _get_packet_ip() const; - virtual Error _set_send_address(const String& p_address,int p_port); + virtual Error _set_send_address(const String& p_address,int p_port, IP_Address::AddrType p_address_type = IP_Address::TYPE_ANY); public: - virtual Error listen(int p_port, IP_Address::AddrType p_address_type = IP_Address::TYPE_IPV4, int p_recv_buffer_size=65536)=0; + virtual Error listen(int p_port, IP_Address::AddrType p_address_type = IP_Address::TYPE_ANY, int p_recv_buffer_size=65536)=0; virtual void close()=0; virtual Error wait()=0; virtual bool is_listening() const=0; diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index fbb0c69cb7..528f2e8cab 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -30,9 +30,26 @@ StreamPeerTCP* (*StreamPeerTCP::_create)()=NULL; +VARIANT_ENUM_CAST(IP_Address::AddrType); + +Error StreamPeerTCP::_connect(const String& p_address,int p_port,IP_Address::AddrType p_type) { + + IP_Address ip; + if (p_address.is_valid_ip_address()) { + ip=p_address; + } else { + ip=IP::get_singleton()->resolve_hostname(p_address, p_type); + if (ip==IP_Address()) + return ERR_CANT_RESOLVE; + } + + connect(ip,p_port); + return OK; +} + void StreamPeerTCP::_bind_methods() { - ObjectTypeDB::bind_method(_MD("connect","host","port"),&StreamPeerTCP::connect); + ObjectTypeDB::bind_method(_MD("connect","host","port","ip_type"),&StreamPeerTCP::_connect,DEFVAL(IP_Address::TYPE_ANY)); ObjectTypeDB::bind_method(_MD("is_connected"),&StreamPeerTCP::is_connected); ObjectTypeDB::bind_method(_MD("get_status"),&StreamPeerTCP::get_status); ObjectTypeDB::bind_method(_MD("get_connected_host"),&StreamPeerTCP::get_connected_host); diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index 4c58e7e149..a151fffad8 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -32,6 +32,7 @@ #include "stream_peer.h" #include "ip_address.h" +#include "io/ip.h" class StreamPeerTCP : public StreamPeer { @@ -50,6 +51,7 @@ public: protected: + virtual Error _connect(const String& p_address, int p_port, IP_Address::AddrType p_type = IP_Address::TYPE_ANY); static StreamPeerTCP* (*_create)(); static void _bind_methods(); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 53d6e900f3..894cccf691 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -58,7 +58,7 @@ Error TCP_Server::_listen(uint16_t p_port, IP_Address::AddrType p_type, DVector< void TCP_Server::_bind_methods() { - ObjectTypeDB::bind_method(_MD("listen","port","accepted_hosts"),&TCP_Server::_listen,DEFVAL(IP_Address::TYPE_IPV4), DEFVAL(DVector<String>())); + ObjectTypeDB::bind_method(_MD("listen","port","ip_type", "accepted_hosts"),&TCP_Server::_listen,DEFVAL(IP_Address::TYPE_ANY),DEFVAL(DVector<String>())); ObjectTypeDB::bind_method(_MD("is_connection_available"),&TCP_Server::is_connection_available); ObjectTypeDB::bind_method(_MD("take_connection"),&TCP_Server::take_connection); ObjectTypeDB::bind_method(_MD("stop"),&TCP_Server::stop); diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index 883a3ef2f6..0267895008 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -41,11 +41,11 @@ protected: static TCP_Server* (*_create)(); //bind helper - Error _listen(uint16_t p_port, IP_Address::AddrType p_type = IP_Address::TYPE_IPV4 ,DVector<String> p_accepted_hosts=DVector<String>()); + Error _listen(uint16_t p_port, IP_Address::AddrType p_type = IP_Address::TYPE_ANY ,DVector<String> p_accepted_hosts=DVector<String>()); static void _bind_methods(); public: - virtual Error listen(uint16_t p_port, IP_Address::AddrType p_type = IP_Address::TYPE_IPV4, const List<String> *p_accepted_hosts=NULL)=0; + virtual Error listen(uint16_t p_port, IP_Address::AddrType p_type = IP_Address::TYPE_ANY, const List<String> *p_accepted_hosts=NULL)=0; virtual bool is_connection_available() const=0; virtual Ref<StreamPeerTCP> take_connection()=0; |