diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2016-11-30 20:45:19 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2016-12-09 18:24:59 +0100 |
commit | 95bdd977686005d3d813eb09aca625384f1774c1 (patch) | |
tree | 6d80a57751e2b9af75824e5b0e5bd1a53819b226 /core | |
parent | 311f1f165be12ea290799e42f9951011d997ab40 (diff) |
Use an instance variable for ip_type in raw sockets
PacketPeerUDP/StreamPeerTCP/TCP_Server now uses an instance variable
to store the selected ip_type (IPv4/IPv6/ANY, where ANY = dual stack).
All calls to resolve addresses, sending/receving data, connecting/listening
will use that socket type.
Diffstat (limited to 'core')
-rw-r--r-- | core/io/packet_peer_udp.cpp | 9 | ||||
-rw-r--r-- | core/io/packet_peer_udp.h | 6 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.cpp | 7 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.h | 4 | ||||
-rw-r--r-- | core/io/tcp_server.cpp | 7 | ||||
-rw-r--r-- | core/io/tcp_server.h | 6 |
6 files changed, 24 insertions, 15 deletions
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 925d00a84a..8106647910 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,IP_Address::AddrType p_type) { +Error PacketPeerUDP::_set_send_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, p_type); + ip=IP::get_singleton()->resolve_hostname(p_address, ip_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,IP_Add void PacketPeerUDP::_bind_methods() { - 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("listen:Error","port", "recv_buf_size"),&PacketPeerUDP::listen,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","ip_type"),&PacketPeerUDP::_set_send_address,DEFVAL(IP_Address::TYPE_ANY)); + ObjectTypeDB::bind_method(_MD("set_send_address","host","port"),&PacketPeerUDP::_set_send_address); } @@ -83,4 +83,5 @@ PacketPeerUDP* PacketPeerUDP::create() { PacketPeerUDP::PacketPeerUDP() { + ip_type = IP_Address::TYPE_ANY; } diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index 37e700cebd..011e8dd9aa 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -37,16 +37,18 @@ class PacketPeerUDP : public PacketPeer { protected: + IP_Address::AddrType ip_type; + static PacketPeerUDP* (*_create)(); static void _bind_methods(); String _get_packet_ip() const; - virtual Error _set_send_address(const String& p_address,int p_port, IP_Address::AddrType p_address_type = IP_Address::TYPE_ANY); + virtual Error _set_send_address(const String& p_address,int p_port); public: - virtual Error listen(int p_port, IP_Address::AddrType p_address_type = IP_Address::TYPE_ANY, int p_recv_buffer_size=65536)=0; + virtual Error listen(int p_port, 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 528f2e8cab..b18bba4d2e 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -32,13 +32,13 @@ 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) { +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, p_type); + ip=IP::get_singleton()->resolve_hostname(p_address, ip_type); if (ip==IP_Address()) return ERR_CANT_RESOLVE; } @@ -49,7 +49,7 @@ Error StreamPeerTCP::_connect(const String& p_address,int p_port,IP_Address::Add void StreamPeerTCP::_bind_methods() { - ObjectTypeDB::bind_method(_MD("connect","host","port","ip_type"),&StreamPeerTCP::_connect,DEFVAL(IP_Address::TYPE_ANY)); + ObjectTypeDB::bind_method(_MD("connect","host","port"),&StreamPeerTCP::_connect); 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); @@ -79,6 +79,7 @@ StreamPeerTCP* StreamPeerTCP::create() { StreamPeerTCP::StreamPeerTCP() { + ip_type = IP_Address::TYPE_ANY; } StreamPeerTCP::~StreamPeerTCP() { diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index a151fffad8..10e061972b 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -51,7 +51,9 @@ public: protected: - virtual Error _connect(const String& p_address, int p_port, IP_Address::AddrType p_type = IP_Address::TYPE_ANY); + IP_Address::AddrType ip_type; + + virtual Error _connect(const String& p_address, int p_port); static StreamPeerTCP* (*_create)(); static void _bind_methods(); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 894cccf691..29e8bd0c02 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -46,19 +46,19 @@ TCP_Server* TCP_Server::create() { return _create(); } -Error TCP_Server::_listen(uint16_t p_port, IP_Address::AddrType p_type, DVector<String> p_accepted_hosts) { +Error TCP_Server::_listen(uint16_t p_port, DVector<String> p_accepted_hosts) { List<String> hosts; for(int i=0;i<p_accepted_hosts.size();i++) hosts.push_back(p_accepted_hosts.get(i)); - return listen(p_port,p_type, hosts.size()?&hosts:NULL); + return listen(p_port, hosts.size()?&hosts:NULL); } void TCP_Server::_bind_methods() { - 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("listen","port","accepted_hosts"),&TCP_Server::_listen,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); @@ -68,4 +68,5 @@ void TCP_Server::_bind_methods() { TCP_Server::TCP_Server() { + ip_type = IP_Address::TYPE_ANY; } diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index 0267895008..c380db52d0 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -38,14 +38,16 @@ class TCP_Server : public Reference { OBJ_TYPE( TCP_Server, Reference ); protected: + IP_Address::AddrType ip_type; + static TCP_Server* (*_create)(); //bind helper - Error _listen(uint16_t p_port, IP_Address::AddrType p_type = IP_Address::TYPE_ANY ,DVector<String> p_accepted_hosts=DVector<String>()); + Error _listen(uint16_t p_port, 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_ANY, const List<String> *p_accepted_hosts=NULL)=0; + virtual Error listen(uint16_t p_port, const List<String> *p_accepted_hosts=NULL)=0; virtual bool is_connection_available() const=0; virtual Ref<StreamPeerTCP> take_connection()=0; |