diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2016-12-20 15:13:16 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2017-01-13 19:02:39 +0100 |
commit | 55b4f3686d8f51958132a1a1745cc4e128fd118d (patch) | |
tree | 166970b41aa83726525a395303ca3a0ec0949533 /platform/windows | |
parent | d2aae675e92cbe99706564e2cffbc34ed7cea639 (diff) |
TCP connect always opens correct socket type
TCP client connections does not need to rely on ipv6 dual stack sockets
Diffstat (limited to 'platform/windows')
-rw-r--r-- | platform/windows/stream_peer_winsock.cpp | 10 | ||||
-rw-r--r-- | platform/windows/stream_peer_winsock.h | 1 |
2 files changed, 8 insertions, 3 deletions
diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp index a48a02c7a7..e0f77782a1 100644 --- a/platform/windows/stream_peer_winsock.cpp +++ b/platform/windows/stream_peer_winsock.cpp @@ -88,7 +88,7 @@ Error StreamPeerWinsock::_poll_connection(bool p_block) const { }; struct sockaddr_storage their_addr; - size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, ip_type); + size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type); if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == SOCKET_ERROR) { @@ -282,6 +282,7 @@ void StreamPeerWinsock::disconnect() { if (sockfd != INVALID_SOCKET) closesocket(sockfd); sockfd=INVALID_SOCKET; + sock_type = IP::TYPE_NONE; status = STATUS_NONE; @@ -293,6 +294,7 @@ void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port, ip_type = p_ip_type; sockfd = p_sockfd; + sock_type = p_ip_type; status = STATUS_CONNECTING; peer_host = p_host; peer_port = p_port; @@ -302,7 +304,8 @@ Error StreamPeerWinsock::connect(const IP_Address& p_host, uint16_t p_port) { ERR_FAIL_COND_V( p_host == IP_Address(), ERR_INVALID_PARAMETER); - sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP); + sock_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + sockfd = _socket_create(sock_type, SOCK_STREAM, IPPROTO_TCP); if (sockfd == INVALID_SOCKET) { ERR_PRINT("Socket creation failed!"); disconnect(); @@ -318,7 +321,7 @@ Error StreamPeerWinsock::connect(const IP_Address& p_host, uint16_t p_port) { }; struct sockaddr_storage their_addr; - size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, ip_type); + size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, sock_type); if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == SOCKET_ERROR) { @@ -365,6 +368,7 @@ uint16_t StreamPeerWinsock::get_connected_port() const { StreamPeerWinsock::StreamPeerWinsock() { + sock_type = IP::TYPE_NONE; sockfd = INVALID_SOCKET; status = STATUS_NONE; peer_port = 0; diff --git a/platform/windows/stream_peer_winsock.h b/platform/windows/stream_peer_winsock.h index e17a7167e1..66e7736e04 100644 --- a/platform/windows/stream_peer_winsock.h +++ b/platform/windows/stream_peer_winsock.h @@ -41,6 +41,7 @@ class StreamPeerWinsock : public StreamPeerTCP { protected: mutable Status status; + IP::Type sock_type; int sockfd; |