summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-10-28 20:35:31 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-10-30 17:46:05 +0100
commit2f1c8592721eca1e6a71f419208f99977ceab2d9 (patch)
tree1433c51da9158410c303c16473be08ebd24ba93a /core/io
parent812908e236e83db368dfef49b8badb9a6182e1de (diff)
Add optional IP type param in TCP/UDP connect/set_send_address
Diffstat (limited to 'core/io')
-rw-r--r--core/io/packet_peer_udp.cpp6
-rw-r--r--core/io/packet_peer_udp.h2
-rw-r--r--core/io/stream_peer_tcp.cpp19
-rw-r--r--core/io/stream_peer_tcp.h2
4 files changed, 24 insertions, 5 deletions
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp
index 018dc77d91..3eff128d25 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;
}
@@ -62,7 +62,7 @@ void PacketPeerUDP::_bind_methods() {
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 6c79104e43..37e700cebd 100644
--- a/core/io/packet_peer_udp.h
+++ b/core/io/packet_peer_udp.h
@@ -42,7 +42,7 @@ 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:
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();