TCP connect always opens correct socket type
TCP client connections does not need to rely on ipv6 dual stack sockets
(cherry picked from commit 55b4f3686d
)
This commit is contained in:
parent
a14ad02d15
commit
ccf37c4ca2
4 changed files with 17 additions and 8 deletions
|
@ -98,7 +98,7 @@ Error StreamPeerTCPPosix::_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) == -1) {
|
||||
|
||||
|
@ -125,6 +125,7 @@ Error StreamPeerTCPPosix::_poll_connection(bool p_block) const {
|
|||
void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_ip_type) {
|
||||
|
||||
ip_type = p_ip_type;
|
||||
sock_type = p_ip_type;
|
||||
sockfd = p_sockfd;
|
||||
#ifndef NO_FCNTL
|
||||
fcntl(sockfd, F_SETFL, O_NONBLOCK);
|
||||
|
@ -143,7 +144,8 @@ Error StreamPeerTCPPosix::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 == -1) {
|
||||
ERR_PRINT("Socket creation failed!");
|
||||
disconnect();
|
||||
|
@ -159,7 +161,7 @@ Error StreamPeerTCPPosix::connect(const IP_Address &p_host, uint16_t p_port) {
|
|||
#endif
|
||||
|
||||
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);
|
||||
|
||||
errno = 0;
|
||||
if (::connect(sockfd, (struct sockaddr *)&their_addr, addr_size) == -1 && errno != EINPROGRESS) {
|
||||
|
@ -339,6 +341,8 @@ void StreamPeerTCPPosix::disconnect() {
|
|||
|
||||
if (sockfd != -1)
|
||||
close(sockfd);
|
||||
|
||||
sock_type = IP::TYPE_NONE;
|
||||
sockfd = -1;
|
||||
|
||||
status = STATUS_NONE;
|
||||
|
@ -387,6 +391,7 @@ uint16_t StreamPeerTCPPosix::get_connected_port() const {
|
|||
|
||||
StreamPeerTCPPosix::StreamPeerTCPPosix() {
|
||||
|
||||
sock_type = IP::TYPE_NONE;
|
||||
sockfd = -1;
|
||||
status = STATUS_NONE;
|
||||
peer_port = 0;
|
||||
|
|
|
@ -35,13 +35,12 @@
|
|||
#include "core/io/stream_peer_tcp.h"
|
||||
#include "error_list.h"
|
||||
|
||||
#include "core/io/ip_address.h"
|
||||
|
||||
class StreamPeerTCPPosix : public StreamPeerTCP {
|
||||
|
||||
protected:
|
||||
mutable Status status;
|
||||
|
||||
IP::Type sock_type;
|
||||
int sockfd;
|
||||
|
||||
Error _block(int p_sockfd, bool p_read, bool p_write) const;
|
||||
|
|
|
@ -87,7 +87,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) {
|
||||
|
||||
|
@ -277,6 +277,7 @@ void StreamPeerWinsock::disconnect() {
|
|||
if (sockfd != INVALID_SOCKET)
|
||||
closesocket(sockfd);
|
||||
sockfd = INVALID_SOCKET;
|
||||
sock_type = IP::TYPE_NONE;
|
||||
|
||||
status = STATUS_NONE;
|
||||
|
||||
|
@ -288,6 +289,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;
|
||||
|
@ -297,7 +299,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();
|
||||
|
@ -313,7 +316,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) {
|
||||
|
||||
|
@ -359,6 +362,7 @@ uint16_t StreamPeerWinsock::get_connected_port() const {
|
|||
|
||||
StreamPeerWinsock::StreamPeerWinsock() {
|
||||
|
||||
sock_type = IP::TYPE_NONE;
|
||||
sockfd = INVALID_SOCKET;
|
||||
status = STATUS_NONE;
|
||||
peer_port = 0;
|
||||
|
|
|
@ -40,6 +40,7 @@ class StreamPeerWinsock : public StreamPeerTCP {
|
|||
|
||||
protected:
|
||||
mutable Status status;
|
||||
IP::Type sock_type;
|
||||
|
||||
int sockfd;
|
||||
|
||||
|
|
Loading…
Reference in a new issue