summaryrefslogtreecommitdiffstats
path: root/drivers/unix/tcp_server_posix.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-11-30 20:45:19 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-12-09 18:24:59 +0100
commit95bdd977686005d3d813eb09aca625384f1774c1 (patch)
tree6d80a57751e2b9af75824e5b0e5bd1a53819b226 /drivers/unix/tcp_server_posix.cpp
parent311f1f165be12ea290799e42f9951011d997ab40 (diff)
downloadredot-engine-95bdd977686005d3d813eb09aca625384f1774c1.tar.gz
Use an instance variable for ip_type in raw sockets
PacketPeerUDP/StreamPeerTCP/TCP_Server now uses an instance variable to store the selected ip_type (IPv4/IPv6/ANY, where ANY = dual stack). All calls to resolve addresses, sending/receving data, connecting/listening will use that socket type.
Diffstat (limited to 'drivers/unix/tcp_server_posix.cpp')
-rw-r--r--drivers/unix/tcp_server_posix.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp
index 7028c1a107..e6f3614cb5 100644
--- a/drivers/unix/tcp_server_posix.cpp
+++ b/drivers/unix/tcp_server_posix.cpp
@@ -68,14 +68,14 @@ void TCPServerPosix::make_default() {
TCP_Server::_create = TCPServerPosix::_create;
};
-Error TCPServerPosix::listen(uint16_t p_port, IP_Address::AddrType p_type, const List<String> *p_accepted_hosts) {
+Error TCPServerPosix::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 == -1, 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) {
@@ -95,7 +95,7 @@ Error TCPServerPosix::listen(uint16_t p_port, IP_Address::AddrType p_type, const
}
struct sockaddr_storage addr;
- size_t addr_size = _set_listen_sockaddr(&addr, p_port, p_type, p_accepted_hosts);
+ size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, p_accepted_hosts);
// automatically fill with my IP TODO: use p_accepted_hosts
@@ -164,7 +164,7 @@ Ref<StreamPeerTCP> TCPServerPosix::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;
};
@@ -183,6 +183,7 @@ void TCPServerPosix::stop() {
TCPServerPosix::TCPServerPosix() {
listen_sockfd = -1;
+ ip_type = IP_Address::TYPE_ANY;
};
TCPServerPosix::~TCPServerPosix() {