summaryrefslogtreecommitdiff
path: root/drivers/unix
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/unix')
-rw-r--r--drivers/unix/dir_access_unix.cpp7
-rw-r--r--drivers/unix/ip_unix.cpp2
-rw-r--r--drivers/unix/net_socket_posix.cpp30
-rw-r--r--drivers/unix/net_socket_posix.h2
4 files changed, 18 insertions, 23 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index e011176806..251bab5783 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -100,10 +100,7 @@ bool DirAccessUnix::dir_exists(String p_dir) {
struct stat flags;
bool success = (stat(p_dir.utf8().get_data(), &flags) == 0);
- if (success && S_ISDIR(flags.st_mode))
- return true;
-
- return false;
+ return (success && S_ISDIR(flags.st_mode));
}
uint64_t DirAccessUnix::get_modified_time(String p_file) {
@@ -316,7 +313,7 @@ Error DirAccessUnix::change_dir(String p_dir) {
// try_dir is the directory we are trying to change into
String try_dir = "";
if (p_dir.is_rel_path()) {
- String next_dir = current_dir + "/" + p_dir;
+ String next_dir = current_dir.plus_file(p_dir);
next_dir = next_dir.simplify_path();
try_dir = next_dir;
} else {
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index 39ca9a823e..ce66f07a19 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -56,7 +56,6 @@
#endif // MINGW hack
#endif
#else // UNIX
-#include <net/if.h>
#include <netdb.h>
#ifdef ANDROID_ENABLED
// We could drop this file once we up our API level to 24,
@@ -73,6 +72,7 @@
#ifdef __FreeBSD__
#include <netinet/in.h>
#endif
+#include <net/if.h> // Order is important on OpenBSD, leave as last
#endif
static IP_Address _sockaddr2ip(struct sockaddr *p_addr) {
diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp
index 4bde7789e2..f8e771aea0 100644
--- a/drivers/unix/net_socket_posix.cpp
+++ b/drivers/unix/net_socket_posix.cpp
@@ -55,10 +55,6 @@
#include <netinet/tcp.h>
-#if defined(__APPLE__)
-#define MSG_NOSIGNAL SO_NOSIGPIPE
-#endif
-
// BSD calls this flag IPV6_JOIN_GROUP
#if !defined(IPV6_ADD_MEMBERSHIP) && defined(IPV6_JOIN_GROUP)
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
@@ -87,10 +83,6 @@
#define SOCK_IOCTL ioctlsocket
#define SOCK_CLOSE closesocket
-// Windows doesn't have this flag
-#ifndef MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
-#endif
// Workaround missing flag in MinGW
#if defined(__MINGW32__) && !defined(SIO_UDP_NETRESET)
#define SIO_UDP_NETRESET _WSAIOW(IOC_VENDOR, 15)
@@ -229,10 +221,7 @@ bool NetSocketPosix::_can_use_ip(const IP_Address p_ip, const bool p_for_bind) c
}
// Check if socket support this IP type.
IP::Type type = p_ip.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
- if (_ip_type != IP::TYPE_ANY && !p_ip.is_wildcard() && _ip_type != type) {
- return false;
- }
- return true;
+ return !(_ip_type != IP::TYPE_ANY && !p_ip.is_wildcard() && _ip_type != type);
}
_FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IP_Address p_ip, String p_if_name, bool p_add) {
@@ -345,6 +334,13 @@ Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) {
}
}
#endif
+#if defined(SO_NOSIGPIPE)
+ // Disable SIGPIPE (should only be relevant to stream sockets, but seems to affect UDP too on iOS)
+ int par = 1;
+ if (setsockopt(_sock, SOL_SOCKET, SO_NOSIGPIPE, SOCK_CBUF(&par), sizeof(int)) != 0) {
+ print_verbose("Unable to turn off SIGPIPE on socket");
+ }
+#endif
return OK;
}
@@ -549,8 +545,10 @@ Error NetSocketPosix::send(const uint8_t *p_buffer, int p_len, int &r_sent) {
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
int flags = 0;
+#ifdef MSG_NOSIGNAL
if (_is_stream)
flags = MSG_NOSIGNAL;
+#endif
r_sent = ::send(_sock, SOCK_CBUF(p_buffer), p_len, flags);
if (r_sent < 0) {
@@ -686,10 +684,10 @@ Ref<NetSocket> NetSocketPosix::accept(IP_Address &r_ip, uint16_t &r_port) {
return Ref<NetSocket>(ns);
}
-Error NetSocketPosix::join_multicast_group(const IP_Address &p_ip, String p_if_name) {
- return _change_multicast_group(p_ip, p_if_name, true);
+Error NetSocketPosix::join_multicast_group(const IP_Address &p_multi_address, String p_if_name) {
+ return _change_multicast_group(p_multi_address, p_if_name, true);
}
-Error NetSocketPosix::leave_multicast_group(const IP_Address &p_ip, String p_if_name) {
- return _change_multicast_group(p_ip, p_if_name, false);
+Error NetSocketPosix::leave_multicast_group(const IP_Address &p_multi_address, String p_if_name) {
+ return _change_multicast_group(p_multi_address, p_if_name, false);
}
diff --git a/drivers/unix/net_socket_posix.h b/drivers/unix/net_socket_posix.h
index cf0412311d..ce6dc00d42 100644
--- a/drivers/unix/net_socket_posix.h
+++ b/drivers/unix/net_socket_posix.h
@@ -77,7 +77,7 @@ public:
virtual void close();
virtual Error bind(IP_Address p_addr, uint16_t p_port);
virtual Error listen(int p_max_pending);
- virtual Error connect_to_host(IP_Address p_addr, uint16_t p_port);
+ virtual Error connect_to_host(IP_Address p_host, uint16_t p_port);
virtual Error poll(PollType p_type, int timeout) const;
virtual Error recv(uint8_t *p_buffer, int p_len, int &r_read);
virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port);