summaryrefslogtreecommitdiff
path: root/drivers/unix
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-01-15 00:26:46 +0100
committerGitHub <noreply@github.com>2017-01-15 00:26:46 +0100
commita992d3f74f73ce4975abf9273aeaaa8909b78de1 (patch)
tree3d2db13f34e29e3287bcdd46dcbe18793cee325b /drivers/unix
parentd4eb8ec884c0519dc02de4451e249f6f5cca962a (diff)
parent55b4f3686d8f51958132a1a1745cc4e128fd118d (diff)
Merge pull request #7510 from Faless/tcp_connect
TCP connect always opens the correct socket type
Diffstat (limited to 'drivers/unix')
-rw-r--r--drivers/unix/stream_peer_tcp_posix.cpp11
-rw-r--r--drivers/unix/stream_peer_tcp_posix.h3
2 files changed, 9 insertions, 5 deletions
diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp
index 82f3115f4b..ae4bf77c36 100644
--- a/drivers/unix/stream_peer_tcp_posix.cpp
+++ b/drivers/unix/stream_peer_tcp_posix.cpp
@@ -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_to_host(const IP_Address& p_host, uint16_t p_p
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_from_host();
@@ -159,7 +161,7 @@ Error StreamPeerTCPPosix::connect_to_host(const IP_Address& p_host, uint16_t p_p
#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) {
@@ -340,6 +342,8 @@ void StreamPeerTCPPosix::disconnect_from_host() {
if (sockfd != -1)
close(sockfd);
+
+ sock_type = IP::TYPE_NONE;
sockfd=-1;
status = STATUS_NONE;
@@ -390,6 +394,7 @@ uint16_t StreamPeerTCPPosix::get_connected_port() const {
StreamPeerTCPPosix::StreamPeerTCPPosix() {
+ sock_type = IP::TYPE_NONE;
sockfd = -1;
status = STATUS_NONE;
peer_port = 0;
diff --git a/drivers/unix/stream_peer_tcp_posix.h b/drivers/unix/stream_peer_tcp_posix.h
index e0091d55b7..d33883b159 100644
--- a/drivers/unix/stream_peer_tcp_posix.h
+++ b/drivers/unix/stream_peer_tcp_posix.h
@@ -35,14 +35,13 @@
#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;