summaryrefslogtreecommitdiff
path: root/drivers/unix
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/unix')
-rw-r--r--drivers/unix/SCsub14
-rw-r--r--drivers/unix/dir_access_unix.cpp2
-rw-r--r--drivers/unix/dir_access_unix.h2
-rw-r--r--drivers/unix/file_access_unix.cpp2
-rw-r--r--drivers/unix/file_access_unix.h2
-rw-r--r--drivers/unix/ip_unix.cpp34
-rw-r--r--drivers/unix/ip_unix.h4
-rw-r--r--drivers/unix/memory_pool_static_malloc.cpp2
-rw-r--r--drivers/unix/memory_pool_static_malloc.h2
-rw-r--r--drivers/unix/mutex_posix.cpp2
-rw-r--r--drivers/unix/mutex_posix.h2
-rw-r--r--drivers/unix/os_unix.cpp9
-rw-r--r--drivers/unix/os_unix.h2
-rw-r--r--drivers/unix/packet_peer_udp_posix.cpp44
-rw-r--r--drivers/unix/packet_peer_udp_posix.h6
-rw-r--r--drivers/unix/semaphore_posix.cpp2
-rw-r--r--drivers/unix/semaphore_posix.h2
-rw-r--r--drivers/unix/socket_helpers.h66
-rw-r--r--drivers/unix/stream_peer_tcp_posix.cpp23
-rw-r--r--drivers/unix/stream_peer_tcp_posix.h4
-rw-r--r--drivers/unix/tcp_server_posix.cpp14
-rw-r--r--drivers/unix/tcp_server_posix.h4
-rw-r--r--drivers/unix/thread_posix.cpp2
-rw-r--r--drivers/unix/thread_posix.h2
24 files changed, 148 insertions, 100 deletions
diff --git a/drivers/unix/SCsub b/drivers/unix/SCsub
index fe427e747f..3766e782e4 100644
--- a/drivers/unix/SCsub
+++ b/drivers/unix/SCsub
@@ -2,13 +2,13 @@
Import('env')
-g_set_p='#ifdef UNIX_ENABLED\n'
-g_set_p+='#include "os_unix.h"\n'
-g_set_p+='String OS_Unix::get_global_settings_path() const {\n'
-g_set_p+='\treturn "' + env["unix_global_settings_path"]+'";\n'
-g_set_p+='}\n'
-g_set_p+='#endif'
-f = open("os_unix_global_settings_path.cpp","wb")
+g_set_p = '#ifdef UNIX_ENABLED\n'
+g_set_p += '#include "os_unix.h"\n'
+g_set_p += 'String OS_Unix::get_global_settings_path() const {\n'
+g_set_p += '\treturn "' + env["unix_global_settings_path"] + '";\n'
+g_set_p += '}\n'
+g_set_p += '#endif'
+f = open("os_unix_global_settings_path.cpp", "wb")
f.write(g_set_p)
f.close()
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index b3bea8ac27..3bb30700db 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h
index b2f1aed10f..324d2a379c 100644
--- a/drivers/unix/dir_access_unix.h
+++ b/drivers/unix/dir_access_unix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp
index 2838e7d913..ee51db6694 100644
--- a/drivers/unix/file_access_unix.cpp
+++ b/drivers/unix/file_access_unix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/file_access_unix.h b/drivers/unix/file_access_unix.h
index d6a172bf47..57b643dc26 100644
--- a/drivers/unix/file_access_unix.h
+++ b/drivers/unix/file_access_unix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index d6d1be3395..0ebd593953 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,7 +33,11 @@
#include <string.h>
#ifdef WINDOWS_ENABLED
- #ifdef WINRT_ENABLED
+ // Workaround mingw missing flags!
+ #ifndef AI_ADDRCONFIG
+ #define AI_ADDRCONFIG 0x00000400
+ #endif
+ #ifdef UWP_ENABLED
#include <ws2tcpip.h>
#include <winsock2.h>
#include <windows.h>
@@ -68,30 +72,29 @@ static IP_Address _sockaddr2ip(struct sockaddr* p_addr) {
IP_Address ip;
if (p_addr->sa_family == AF_INET) {
struct sockaddr_in* addr = (struct sockaddr_in*)p_addr;
- ip.field32[0] = *((unsigned long*)&addr->sin_addr);
- ip.type = IP_Address::TYPE_IPV4;
+ ip.set_ipv4((uint8_t *)&(addr->sin_addr));
} else {
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)p_addr;
- for (int i=0; i<16; i++)
- ip.field8[i] = addr6->sin6_addr.s6_addr[i];
- ip.type = IP_Address::TYPE_IPV6;
+ ip.set_ipv6(addr6->sin6_addr.s6_addr);
};
return ip;
};
-IP_Address IP_Unix::_resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type) {
+IP_Address IP_Unix::_resolve_hostname(const String& p_hostname, Type p_type) {
struct addrinfo hints;
struct addrinfo* result;
memset(&hints, 0, sizeof(struct addrinfo));
- if (p_type == IP_Address::TYPE_IPV4) {
+ if (p_type == TYPE_IPV4) {
hints.ai_family = AF_INET;
- } else if (p_type == IP_Address::TYPE_IPV6) {
+ } else if (p_type == TYPE_IPV6) {
hints.ai_family = AF_INET6;
+ hints.ai_flags = 0;
} else {
hints.ai_family = AF_UNSPEC;
+ hints.ai_flags = AI_ADDRCONFIG;
};
int s = getaddrinfo(p_hostname.utf8().get_data(), NULL, &hints, &result);
@@ -115,7 +118,7 @@ IP_Address IP_Unix::_resolve_hostname(const String& p_hostname, IP_Address::Addr
#if defined(WINDOWS_ENABLED)
-#if defined(WINRT_ENABLED)
+#if defined(UWP_ENABLED)
void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
@@ -175,15 +178,12 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
SOCKADDR_IN* ipv4 = reinterpret_cast<SOCKADDR_IN*>(address->Address.lpSockaddr);
- ip.field32[0] = *((unsigned long*)&ipv4->sin_addr);
- ip.type = IP_Address::TYPE_IPV4;
+ ip.set_ipv4((uint8_t *)&(ipv4->sin_addr));
} else { // ipv6
SOCKADDR_IN6* ipv6 = reinterpret_cast<SOCKADDR_IN6*>(address->Address.lpSockaddr);
- for (int i=0; i<16; i++) {
- ip.field8[i] = ipv6->sin6_addr.s6_addr[i];
- };
- ip.type = IP_Address::TYPE_IPV6;
+
+ ip.set_ipv6(ipv6->sin6_addr.s6_addr);
};
diff --git a/drivers/unix/ip_unix.h b/drivers/unix/ip_unix.h
index d198a330e7..00870d5492 100644
--- a/drivers/unix/ip_unix.h
+++ b/drivers/unix/ip_unix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,7 +36,7 @@
class IP_Unix : public IP {
OBJ_TYPE(IP_Unix, IP);
- virtual IP_Address _resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type);
+ virtual IP_Address _resolve_hostname(const String& p_hostname, IP::Type p_type);
static IP* _create_unix();
public:
diff --git a/drivers/unix/memory_pool_static_malloc.cpp b/drivers/unix/memory_pool_static_malloc.cpp
index f89b55de12..a7720cd44a 100644
--- a/drivers/unix/memory_pool_static_malloc.cpp
+++ b/drivers/unix/memory_pool_static_malloc.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/memory_pool_static_malloc.h b/drivers/unix/memory_pool_static_malloc.h
index 78ad82ee22..0d34bac78b 100644
--- a/drivers/unix/memory_pool_static_malloc.h
+++ b/drivers/unix/memory_pool_static_malloc.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/mutex_posix.cpp b/drivers/unix/mutex_posix.cpp
index fb4fa4a891..c9b5bdce75 100644
--- a/drivers/unix/mutex_posix.cpp
+++ b/drivers/unix/mutex_posix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/mutex_posix.h b/drivers/unix/mutex_posix.h
index a1993be221..a71400924a 100644
--- a/drivers/unix/mutex_posix.h
+++ b/drivers/unix/mutex_posix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 271cf302ef..89fd108476 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -88,6 +88,10 @@ void OS_Unix::print_error(const char* p_function,const char* p_file,int p_line,c
print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n",p_function,err_details);
print("\E[0;35m At: %s:%i.\E[0m\n",p_file,p_line);
break;
+ case ERR_SHADER:
+ print("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n",p_function,err_details);
+ print("\E[0;36m At: %s:%i.\E[0m\n",p_file,p_line);
+ break;
}
}
@@ -522,9 +526,6 @@ String OS_Unix::get_executable_path() const {
delete[] resolved_path;
return path;
-#elif defined(EMSCRIPTEN)
- // We return nothing
- return String();
#else
ERR_PRINT("Warning, don't know how to obtain executable path on this OS! Please override this function properly.");
return OS::get_executable_path();
diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h
index a889bba0ff..b28adc2ee0 100644
--- a/drivers/unix/os_unix.h
+++ b/drivers/unix/os_unix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp
index 0b172b6a51..4d9ef6cdae 100644
--- a/drivers/unix/packet_peer_udp_posix.cpp
+++ b/drivers/unix/packet_peer_udp_posix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -76,12 +76,14 @@ Error PacketPeerUDPPosix::get_packet(const uint8_t **r_buffer,int &r_buffer_size
uint32_t size;
uint8_t type;
rb.read(&type, 1, true);
- if (type == IP_Address::TYPE_IPV4) {
- rb.read((uint8_t*)&packet_ip.field8,4,true);
- packet_ip.type = IP_Address::TYPE_IPV4;
+ if (type == IP::TYPE_IPV4) {
+ uint8_t ip[4];
+ rb.read(ip,4,true);
+ packet_ip.set_ipv4(ip);
} else {
- rb.read((uint8_t*)&packet_ip.field8,16,true);
- packet_ip.type = IP_Address::TYPE_IPV6;
+ uint8_t ipv6[16];
+ rb.read(ipv6,16,true);
+ packet_ip.set_ipv6(ipv6);
};
rb.read((uint8_t*)&packet_port,4,true);
rb.read((uint8_t*)&size,4,true);
@@ -94,12 +96,12 @@ Error PacketPeerUDPPosix::get_packet(const uint8_t **r_buffer,int &r_buffer_size
}
Error PacketPeerUDPPosix::put_packet(const uint8_t *p_buffer,int p_buffer_size){
- ERR_FAIL_COND_V(peer_addr.type == IP_Address::TYPE_NONE, ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(peer_addr == IP_Address(), ERR_UNCONFIGURED);
- 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);
+ size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port, ip_type);
errno = 0;
int err;
@@ -119,17 +121,16 @@ int PacketPeerUDPPosix::get_max_packet_size() const{
return 512; // uhm maybe not
}
-Error PacketPeerUDPPosix::listen(int p_port, IP_Address::AddrType p_address_type, int p_recv_buffer_size) {
-
- ERR_FAIL_COND_V(p_address_type != IP_Address::TYPE_IPV4 && p_address_type != IP_Address::TYPE_IPV6, ERR_INVALID_PARAMETER);
+Error PacketPeerUDPPosix::listen(int p_port, int p_recv_buffer_size) {
close();
- int sock = _get_socket(p_address_type);
+ int sock = _get_socket();
+
if (sock == -1 )
return ERR_CANT_CREATE;
sockaddr_storage addr = {0};
- size_t addr_size = _set_listen_sockaddr(&addr, p_port, p_address_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();
@@ -164,7 +165,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
uint32_t port = 0;
if (from.ss_family == AF_INET) {
- uint8_t type = (uint8_t)IP_Address::TYPE_IPV4;
+ uint8_t type = (uint8_t)IP::TYPE_IPV4;
rb.write(&type, 1);
struct sockaddr_in* sin_from = (struct sockaddr_in*)&from;
rb.write((uint8_t*)&sin_from->sin_addr, 4);
@@ -172,7 +173,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
} else if (from.ss_family == AF_INET6) {
- uint8_t type = (uint8_t)IP_Address::TYPE_IPV6;
+ uint8_t type = (uint8_t)IP::TYPE_IPV6;
rb.write(&type, 1);
struct sockaddr_in6* s6_from = (struct sockaddr_in6*)&from;
@@ -182,7 +183,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
} else {
// WARN_PRINT("Ignoring packet with unknown address family");
- uint8_t type = (uint8_t)IP_Address::TYPE_NONE;
+ uint8_t type = (uint8_t)IP::TYPE_NONE;
rb.write(&type, 1);
};
@@ -218,16 +219,12 @@ int PacketPeerUDPPosix::get_packet_port() const{
return packet_port;
}
-int PacketPeerUDPPosix::_get_socket(IP_Address::AddrType p_type) {
+int PacketPeerUDPPosix::_get_socket() {
if (sockfd != -1)
return sockfd;
- int family = p_type == IP_Address::TYPE_IPV6 ? AF_INET6 : AF_INET;
-
- sockfd = socket(family, SOCK_DGRAM, IPPROTO_UDP);
- ERR_FAIL_COND_V( sockfd == -1, -1 );
- //fcntl(sockfd, F_SETFL, O_NONBLOCK);
+ sockfd = _socket_create(ip_type, SOCK_DGRAM, IPPROTO_UDP);
return sockfd;
}
@@ -256,6 +253,7 @@ PacketPeerUDPPosix::PacketPeerUDPPosix() {
packet_port=0;
queue_count=0;
peer_port=0;
+ ip_type = IP::TYPE_ANY;
}
PacketPeerUDPPosix::~PacketPeerUDPPosix() {
diff --git a/drivers/unix/packet_peer_udp_posix.h b/drivers/unix/packet_peer_udp_posix.h
index 13b6969e53..89b8886cf5 100644
--- a/drivers/unix/packet_peer_udp_posix.h
+++ b/drivers/unix/packet_peer_udp_posix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -52,7 +52,7 @@ class PacketPeerUDPPosix : 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();
virtual Error _poll(bool p_block);
@@ -65,7 +65,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/drivers/unix/semaphore_posix.cpp b/drivers/unix/semaphore_posix.cpp
index 3ae94ae5d9..83b34a42dd 100644
--- a/drivers/unix/semaphore_posix.cpp
+++ b/drivers/unix/semaphore_posix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/semaphore_posix.h b/drivers/unix/semaphore_posix.h
index 0a3cf36749..96d1ff5c06 100644
--- a/drivers/unix/semaphore_posix.h
+++ b/drivers/unix/semaphore_posix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/socket_helpers.h b/drivers/unix/socket_helpers.h
index 4ee40e3d3d..962f228c3c 100644
--- a/drivers/unix/socket_helpers.h
+++ b/drivers/unix/socket_helpers.h
@@ -3,33 +3,55 @@
#include <string.h>
+#ifdef WINDOWS_ENABLED
+ // Workaround mingw missing flags!
+ #ifndef IPV6_V6ONLY
+ #define IPV6_V6ONLY 27
+ #endif
+#endif
+
+#ifdef UWP_ENABLED
+#define in6addr_any IN6ADDR_ANY_INIT
+#endif
+
// helpers for sockaddr -> IP_Address and back, should work for posix and winsock. All implementations should use this
-static size_t _set_sockaddr(struct sockaddr_storage* p_addr, const IP_Address& p_ip, int p_port) {
+static size_t _set_sockaddr(struct sockaddr_storage* p_addr, const IP_Address& p_ip, int p_port, IP::Type p_sock_type = IP::TYPE_ANY) {
memset(p_addr, 0, sizeof(struct sockaddr_storage));
- if (p_ip.type == IP_Address::TYPE_IPV6) {
+
+ ERR_FAIL_COND_V(p_ip==IP_Address(),0);
+
+ // IPv6 socket
+ if (p_sock_type == IP::TYPE_IPV6 || p_sock_type == IP::TYPE_ANY) {
+
+ // IPv6 only socket with IPv4 address
+ ERR_FAIL_COND_V(p_sock_type == IP::TYPE_IPV6 && p_ip.is_ipv4(),0);
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)p_addr;
addr6->sin6_family = AF_INET6;
addr6->sin6_port = htons(p_port);
- copymem(&addr6->sin6_addr.s6_addr, p_ip.field8, 16);
+ copymem(&addr6->sin6_addr.s6_addr, p_ip.get_ipv6(), 16);
return sizeof(sockaddr_in6);
- } else {
+ } else { // IPv4 socket
+
+ // IPv4 socket with IPv6 address
+ ERR_FAIL_COND_V(!p_ip.is_ipv4(),0);
+ uint32_t ipv4 = *((uint32_t *)p_ip.get_ipv4());
struct sockaddr_in* addr4 = (struct sockaddr_in*)p_addr;
- addr4->sin_family = AF_INET; // host byte order
+ addr4->sin_family = AF_INET;
addr4->sin_port = htons(p_port); // short, network byte order
- addr4->sin_addr = *((struct in_addr*)&p_ip.field32[0]);
+ copymem(&addr4->sin_addr.s_addr, p_ip.get_ipv4(), 16);
return sizeof(sockaddr_in);
};
};
-static size_t _set_listen_sockaddr(struct sockaddr_storage* p_addr, int p_port, IP_Address::AddrType p_address_type, const List<String> *p_accepted_hosts) {
+static size_t _set_listen_sockaddr(struct sockaddr_storage* p_addr, int p_port, IP::Type p_sock_type, const List<String> *p_accepted_hosts) {
memset(p_addr, 0, sizeof(struct sockaddr_storage));
- if (p_address_type == IP_Address::TYPE_IPV4) {
+ if (p_sock_type == IP::TYPE_IPV4) {
struct sockaddr_in* addr4 = (struct sockaddr_in*)p_addr;
addr4->sin_family = AF_INET;
addr4->sin_port = htons(p_port);
@@ -45,22 +67,40 @@ static size_t _set_listen_sockaddr(struct sockaddr_storage* p_addr, int p_port,
};
};
+static int _socket_create(IP::Type p_type, int type, int protocol) {
+
+ ERR_FAIL_COND_V(p_type > IP::TYPE_ANY || p_type < IP::TYPE_NONE, ERR_INVALID_PARAMETER);
+
+ int family = p_type == IP::TYPE_IPV4 ? AF_INET : AF_INET6;
+ int sockfd = socket(family, type, protocol);
+
+ ERR_FAIL_COND_V( sockfd == -1, -1 );
+
+ if(family == AF_INET6) {
+ // Select IPv4 over IPv6 mapping
+ int opt = p_type != IP::TYPE_ANY;
+ if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&opt, sizeof(opt)) != 0) {
+ WARN_PRINT("Unable to set/unset IPv4 address mapping over IPv6");
+ }
+ }
+
+ return sockfd;
+}
+
+
static void _set_ip_addr_port(IP_Address& r_ip, int& r_port, struct sockaddr_storage* p_addr) {
if (p_addr->ss_family == AF_INET) {
- r_ip.type = IP_Address::TYPE_IPV4;
struct sockaddr_in* addr4 = (struct sockaddr_in*)p_addr;
- r_ip.field32[0] = (uint32_t)addr4->sin_addr.s_addr;
+ r_ip.set_ipv4((uint8_t *)&(addr4->sin_addr.s_addr));
r_port = ntohs(addr4->sin_port);
} else if (p_addr->ss_family == AF_INET6) {
- r_ip.type = IP_Address::TYPE_IPV6;
-
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)p_addr;
- copymem(&addr6->sin6_addr.s6_addr, r_ip.field8, 16);
+ r_ip.set_ipv6(addr6->sin6_addr.s6_addr);
r_port = ntohs(addr6->sin6_port);
};
diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp
index f2915b0a16..f2a1417920 100644
--- a/drivers/unix/stream_peer_tcp_posix.cpp
+++ b/drivers/unix/stream_peer_tcp_posix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -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);
+ size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, ip_type);
if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == -1) {
@@ -107,7 +107,12 @@ Error StreamPeerTCPPosix::_poll_connection(bool p_block) const {
return OK;
};
- return OK;
+ if (errno == EINPROGRESS || errno == EALREADY) {
+ return OK;
+ }
+
+ status = STATUS_ERROR;
+ return ERR_CONNECTION_ERROR;
} else {
status = STATUS_CONNECTED;
@@ -117,8 +122,9 @@ Error StreamPeerTCPPosix::_poll_connection(bool p_block) const {
return OK;
};
-void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port) {
+void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_ip_type) {
+ ip_type = p_ip_type;
sockfd = p_sockfd;
#ifndef NO_FCNTL
fcntl(sockfd, F_SETFL, O_NONBLOCK);
@@ -135,10 +141,10 @@ void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port)
Error StreamPeerTCPPosix::connect(const IP_Address& p_host, uint16_t p_port) {
- ERR_FAIL_COND_V( p_host.type == IP_Address::TYPE_NONE, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V( p_host == IP_Address(), ERR_INVALID_PARAMETER);
- int family = p_host.type == IP_Address::TYPE_IPV6 ? AF_INET6 : AF_INET;
- if ((sockfd = socket(family, SOCK_STREAM, 0)) == -1) {
+ sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP);
+ if (sockfd == -1) {
ERR_PRINT("Socket creation failed!");
disconnect();
//perror("socket");
@@ -153,7 +159,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);
+ size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, ip_type);
errno = 0;
if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == -1 && errno != EINPROGRESS) {
@@ -387,6 +393,7 @@ StreamPeerTCPPosix::StreamPeerTCPPosix() {
sockfd = -1;
status = STATUS_NONE;
peer_port = 0;
+ ip_type = IP::TYPE_ANY;
};
StreamPeerTCPPosix::~StreamPeerTCPPosix() {
diff --git a/drivers/unix/stream_peer_tcp_posix.h b/drivers/unix/stream_peer_tcp_posix.h
index a379efe3ca..1df509cac4 100644
--- a/drivers/unix/stream_peer_tcp_posix.h
+++ b/drivers/unix/stream_peer_tcp_posix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -69,7 +69,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::Type p_ip_type);
virtual IP_Address get_connected_host() const;
virtual uint16_t get_connected_port() const;
diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp
index 05b739804c..0178f08b8c 100644
--- a/drivers/unix/tcp_server_posix.cpp
+++ b/drivers/unix/tcp_server_posix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -68,12 +68,13 @@ 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;
- int family = p_type == IP_Address::TYPE_IPV6 ? AF_INET6 : AF_INET;
- sockfd = socket(family, SOCK_STREAM, 0);
+ sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP);
+
ERR_FAIL_COND_V(sockfd == -1, FAILED);
+
#ifndef NO_FCNTL
fcntl(sockfd, F_SETFL, O_NONBLOCK);
#else
@@ -87,7 +88,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
@@ -156,7 +157,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;
};
@@ -175,6 +176,7 @@ void TCPServerPosix::stop() {
TCPServerPosix::TCPServerPosix() {
listen_sockfd = -1;
+ ip_type = IP::TYPE_ANY;
};
TCPServerPosix::~TCPServerPosix() {
diff --git a/drivers/unix/tcp_server_posix.h b/drivers/unix/tcp_server_posix.h
index 134ec494cb..6f9fa8cb5b 100644
--- a/drivers/unix/tcp_server_posix.h
+++ b/drivers/unix/tcp_server_posix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -40,7 +40,7 @@ class TCPServerPosix : public TCP_Server {
public:
- virtual Error listen(uint16_t p_port, IP_Address::AddrType p_type = IP_Address::TYPE_IPV4, 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();
diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp
index c71e09685b..ecea67c37b 100644
--- a/drivers/unix/thread_posix.cpp
+++ b/drivers/unix/thread_posix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/unix/thread_posix.h b/drivers/unix/thread_posix.h
index 06a17c2ae6..cf360e164a 100644
--- a/drivers/unix/thread_posix.h
+++ b/drivers/unix/thread_posix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */