summaryrefslogtreecommitdiff
path: root/platform/windows
diff options
context:
space:
mode:
Diffstat (limited to 'platform/windows')
-rw-r--r--platform/windows/packet_peer_udp_winsock.cpp15
-rw-r--r--platform/windows/packet_peer_udp_winsock.h4
-rw-r--r--platform/windows/stream_peer_winsock.cpp6
-rw-r--r--platform/windows/stream_peer_winsock.h2
-rw-r--r--platform/windows/tcp_server_winsock.cpp11
-rw-r--r--platform/windows/tcp_server_winsock.h2
6 files changed, 22 insertions, 18 deletions
diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/platform/windows/packet_peer_udp_winsock.cpp
index 73c6116aa3..595f1edd8b 100644
--- a/platform/windows/packet_peer_udp_winsock.cpp
+++ b/platform/windows/packet_peer_udp_winsock.cpp
@@ -71,7 +71,7 @@ Error PacketPeerUDPWinsock::get_packet(const uint8_t **r_buffer,int &r_buffer_si
}
Error PacketPeerUDPWinsock::put_packet(const uint8_t *p_buffer,int p_buffer_size){
- int sock = _get_socket(peer_addr.type);
+ int sock = _get_socket();
ERR_FAIL_COND_V( sock == -1, FAILED );
struct sockaddr_storage addr;
size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port);
@@ -112,14 +112,14 @@ void PacketPeerUDPWinsock::_set_blocking(bool p_blocking) {
};
}
-Error PacketPeerUDPWinsock::listen(int p_port, IP_Address::AddrType p_type, int p_recv_buffer_size) {
+Error PacketPeerUDPWinsock::listen(int p_port, int p_recv_buffer_size) {
close();
- int sock = _get_socket(p_type);
+ int sock = _get_socket();
if (sock == -1 )
return ERR_CANT_CREATE;
- if(p_type == IP_Address::TYPE_IPV6) {
+ if(ip_type == IP_Address::TYPE_IPV6) {
// Use IPv6 only socket
int yes = 1;
if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) {
@@ -128,7 +128,7 @@ Error PacketPeerUDPWinsock::listen(int p_port, IP_Address::AddrType p_type, int
}
struct sockaddr_storage addr = {0};
- size_t addr_size = _set_listen_sockaddr(&addr, p_port, p_type, NULL);
+ size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL);
if (bind(sock, (struct sockaddr*)&addr, addr_size) == -1 ) {
close();
@@ -242,12 +242,12 @@ int PacketPeerUDPWinsock::get_packet_port() const{
return packet_port;
}
-int PacketPeerUDPWinsock::_get_socket(IP_Address::AddrType p_type) {
+int PacketPeerUDPWinsock::_get_socket() {
if (sockfd != -1)
return sockfd;
- sockfd = _socket_create(p_type, SOCK_DGRAM, IPPROTO_UDP);
+ sockfd = _socket_create(ip_type, SOCK_DGRAM, IPPROTO_UDP);
return sockfd;
}
@@ -277,6 +277,7 @@ PacketPeerUDPWinsock::PacketPeerUDPWinsock() {
packet_port=0;
queue_count=0;
peer_port=0;
+ ip_type = IP_Address::TYPE_ANY;
}
PacketPeerUDPWinsock::~PacketPeerUDPWinsock() {
diff --git a/platform/windows/packet_peer_udp_winsock.h b/platform/windows/packet_peer_udp_winsock.h
index 9837ef6621..1ffdc81685 100644
--- a/platform/windows/packet_peer_udp_winsock.h
+++ b/platform/windows/packet_peer_udp_winsock.h
@@ -50,7 +50,7 @@ class PacketPeerUDPWinsock : public PacketPeerUDP {
IP_Address peer_addr;
int peer_port;
- _FORCE_INLINE_ int _get_socket(IP_Address::AddrType p_type);
+ _FORCE_INLINE_ int _get_socket();
static PacketPeerUDP* _create();
@@ -67,7 +67,7 @@ public:
virtual int get_max_packet_size() const;
- virtual Error listen(int p_port, IP_Address::AddrType p_address_type, int p_recv_buffer_size=65536);
+ virtual Error listen(int p_port, int p_recv_buffer_size=65536);
virtual void close();
virtual Error wait();
virtual bool is_listening() const;
diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp
index 48dd37e9c4..d11724eb8e 100644
--- a/platform/windows/stream_peer_winsock.cpp
+++ b/platform/windows/stream_peer_winsock.cpp
@@ -289,8 +289,9 @@ void StreamPeerWinsock::disconnect() {
peer_port = 0;
};
-void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port) {
+void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP_Address::AddrType p_ip_type) {
+ ip_type = p_ip_type;
sockfd = p_sockfd;
status = STATUS_CONNECTING;
peer_host = p_host;
@@ -301,7 +302,7 @@ Error StreamPeerWinsock::connect(const IP_Address& p_host, uint16_t p_port) {
ERR_FAIL_COND_V( p_host.type == IP_Address::TYPE_NONE, ERR_INVALID_PARAMETER);
- sockfd = _socket_create(p_host.type, SOCK_STREAM, IPPROTO_TCP);
+ sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP);
if (sockfd == INVALID_SOCKET) {
ERR_PRINT("Socket creation failed!");
disconnect();
@@ -367,6 +368,7 @@ StreamPeerWinsock::StreamPeerWinsock() {
sockfd = INVALID_SOCKET;
status = STATUS_NONE;
peer_port = 0;
+ ip_type = IP_Address::TYPE_ANY;
};
StreamPeerWinsock::~StreamPeerWinsock() {
diff --git a/platform/windows/stream_peer_winsock.h b/platform/windows/stream_peer_winsock.h
index bbff661490..7a7ceab8a6 100644
--- a/platform/windows/stream_peer_winsock.h
+++ b/platform/windows/stream_peer_winsock.h
@@ -68,7 +68,7 @@ public:
virtual int get_available_bytes() const;
- void set_socket(int p_sockfd, IP_Address p_host, int p_port);
+ void set_socket(int p_sockfd, IP_Address p_host, int p_port, IP_Address::AddrType p_ip_type);
virtual IP_Address get_connected_host() const;
virtual uint16_t get_connected_port() const;
diff --git a/platform/windows/tcp_server_winsock.cpp b/platform/windows/tcp_server_winsock.cpp
index 38a6b04100..eed03c9b8d 100644
--- a/platform/windows/tcp_server_winsock.cpp
+++ b/platform/windows/tcp_server_winsock.cpp
@@ -63,13 +63,13 @@ void TCPServerWinsock::cleanup() {
};
-Error TCPServerWinsock::listen(uint16_t p_port, IP_Address::AddrType p_type,const List<String> *p_accepted_hosts) {
+Error TCPServerWinsock::listen(uint16_t p_port,const List<String> *p_accepted_hosts) {
int sockfd;
- sockfd = _socket_create(p_type, SOCK_STREAM, IPPROTO_TCP);
+ sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP);
ERR_FAIL_COND_V(sockfd == INVALID_SOCKET, FAILED);
- if(p_type == IP_Address::TYPE_IPV6) {
+ if(ip_type == IP_Address::TYPE_IPV6) {
// Use IPv6 only socket
int yes = 1;
if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) {
@@ -85,7 +85,7 @@ Error TCPServerWinsock::listen(uint16_t p_port, IP_Address::AddrType p_type,cons
};
struct sockaddr_storage my_addr;
- size_t addr_size = _set_listen_sockaddr(&my_addr, p_port, p_type, p_accepted_hosts);
+ size_t addr_size = _set_listen_sockaddr(&my_addr, p_port, ip_type, p_accepted_hosts);
int reuse=1;
if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) {
@@ -158,7 +158,7 @@ Ref<StreamPeerTCP> TCPServerWinsock::take_connection() {
int port;
_set_ip_addr_port(ip, port, &their_addr);
- conn->set_socket(fd, ip, port);
+ conn->set_socket(fd, ip, port, ip_type);
return conn;
};
@@ -176,6 +176,7 @@ void TCPServerWinsock::stop() {
TCPServerWinsock::TCPServerWinsock() {
listen_sockfd = INVALID_SOCKET;
+ ip_type = IP_Address::TYPE_ANY;
};
TCPServerWinsock::~TCPServerWinsock() {
diff --git a/platform/windows/tcp_server_winsock.h b/platform/windows/tcp_server_winsock.h
index 115fdb4234..bd6a05c74d 100644
--- a/platform/windows/tcp_server_winsock.h
+++ b/platform/windows/tcp_server_winsock.h
@@ -39,7 +39,7 @@ class TCPServerWinsock : public TCP_Server {
public:
- virtual Error listen(uint16_t p_port, IP_Address::AddrType p_type,const List<String> *p_accepted_hosts=NULL);
+ virtual Error listen(uint16_t p_port,const List<String> *p_accepted_hosts=NULL);
virtual bool is_connection_available() const;
virtual Ref<StreamPeerTCP> take_connection();