diff options
-rw-r--r-- | drivers/unix/ip_unix.cpp | 4 | ||||
-rw-r--r-- | drivers/unix/stream_peer_tcp_posix.cpp | 21 | ||||
-rw-r--r-- | drivers/unix/tcp_server_posix.cpp | 17 | ||||
-rw-r--r-- | drivers/windows/stream_peer_tcp_winsock.cpp | 4 | ||||
-rw-r--r-- | drivers/windows/tcp_server_winsock.cpp | 1 | ||||
-rw-r--r-- | modules/websocket/lws_peer.cpp | 9 |
6 files changed, 42 insertions, 14 deletions
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index a7fb0c3887..949609bb9a 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -101,7 +101,7 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) { hints.ai_family = AF_UNSPEC; hints.ai_flags = AI_ADDRCONFIG; }; - hints.ai_flags &= !AI_NUMERICHOST; + hints.ai_flags &= ~AI_NUMERICHOST; int s = getaddrinfo(p_hostname.utf8().get_data(), NULL, &hints, &result); if (s != 0) { @@ -111,6 +111,8 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) { if (result == NULL || result->ai_addr == NULL) { ERR_PRINT("Invalid response from getaddrinfo"); + if (result) + freeaddrinfo(result); return IP_Address(); }; diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp index 17112e5ab5..6d798f32f9 100644 --- a/drivers/unix/stream_peer_tcp_posix.cpp +++ b/drivers/unix/stream_peer_tcp_posix.cpp @@ -124,11 +124,14 @@ void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port, sock_type = p_sock_type; sockfd = p_sockfd; #ifndef NO_FCNTL - fcntl(sockfd, F_SETFL, O_NONBLOCK); + if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) { + WARN_PRINT("Error setting socket as non blocking"); + } #else int bval = 1; - ioctl(sockfd, FIONBIO, &bval); - + if (ioctl(sockfd, FIONBIO, &bval) < 0) { + WARN_PRINT("Error setting socket as non blocking"); + } #endif status = STATUS_CONNECTING; @@ -150,10 +153,14 @@ Error StreamPeerTCPPosix::connect_to_host(const IP_Address &p_host, uint16_t p_p }; #ifndef NO_FCNTL - fcntl(sockfd, F_SETFL, O_NONBLOCK); + if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) { + WARN_PRINT("Error setting socket as non blocking"); + } #else int bval = 1; - ioctl(sockfd, FIONBIO, &bval); + if (ioctl(sockfd, FIONBIO, &bval) < 0) { + WARN_PRINT("Error setting socket as non blocking"); + } #endif struct sockaddr_storage their_addr; @@ -308,7 +315,9 @@ void StreamPeerTCPPosix::set_no_delay(bool p_enabled) { ERR_FAIL_COND(!is_connected_to_host()); int flag = p_enabled ? 1 : 0; - setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)); + if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0) { + ERR_PRINT("Unable to set TCP no delay option"); + } } bool StreamPeerTCPPosix::is_connected_to_host() const { diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp index 07ffe3b00a..67ab981f46 100644 --- a/drivers/unix/tcp_server_posix.cpp +++ b/drivers/unix/tcp_server_posix.cpp @@ -91,10 +91,14 @@ Error TCPServerPosix::listen(uint16_t p_port, const IP_Address &p_bind_address) ERR_FAIL_COND_V(sockfd == -1, FAILED); #ifndef NO_FCNTL - fcntl(sockfd, F_SETFL, O_NONBLOCK); + if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) { + WARN_PRINT("Error setting socket as non blocking"); + } #else int bval = 1; - ioctl(sockfd, FIONBIO, &bval); + if (ioctl(sockfd, FIONBIO, &bval) < 0) { + WARN_PRINT("Error setting socket as non blocking"); + } #endif int reuse = 1; @@ -113,6 +117,7 @@ Error TCPServerPosix::listen(uint16_t p_port, const IP_Address &p_bind_address) ERR_FAIL_V(FAILED); }; } else { + close(sockfd); return ERR_ALREADY_IN_USE; }; @@ -157,10 +162,14 @@ Ref<StreamPeerTCP> TCPServerPosix::take_connection() { int fd = accept(listen_sockfd, (struct sockaddr *)&their_addr, &size); ERR_FAIL_COND_V(fd == -1, Ref<StreamPeerTCP>()); #ifndef NO_FCNTL - fcntl(fd, F_SETFL, O_NONBLOCK); + if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { + WARN_PRINT("Error setting socket as non blocking"); + } #else int bval = 1; - ioctl(fd, FIONBIO, &bval); + if (ioctl(fd, FIONBIO, &bval) < 0) { + WARN_PRINT("Error setting socket as non blocking"); + } #endif Ref<StreamPeerTCPPosix> conn = memnew(StreamPeerTCPPosix); diff --git a/drivers/windows/stream_peer_tcp_winsock.cpp b/drivers/windows/stream_peer_tcp_winsock.cpp index 55775fc231..cb501ce35d 100644 --- a/drivers/windows/stream_peer_tcp_winsock.cpp +++ b/drivers/windows/stream_peer_tcp_winsock.cpp @@ -335,7 +335,9 @@ Error StreamPeerTCPWinsock::connect_to_host(const IP_Address &p_host, uint16_t p void StreamPeerTCPWinsock::set_no_delay(bool p_enabled) { ERR_FAIL_COND(!is_connected_to_host()); int flag = p_enabled ? 1 : 0; - setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)); + if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) != 0) { + ERR_PRINT("Unable to set TCP no delay option"); + } } int StreamPeerTCPWinsock::get_available_bytes() const { diff --git a/drivers/windows/tcp_server_winsock.cpp b/drivers/windows/tcp_server_winsock.cpp index 413a0d19b5..ddb955549f 100644 --- a/drivers/windows/tcp_server_winsock.cpp +++ b/drivers/windows/tcp_server_winsock.cpp @@ -105,6 +105,7 @@ Error TCPServerWinsock::listen(uint16_t p_port, const IP_Address &p_bind_address ERR_FAIL_V(FAILED); }; } else { + closesocket(sockfd); return ERR_ALREADY_IN_USE; }; diff --git a/modules/websocket/lws_peer.cpp b/modules/websocket/lws_peer.cpp index 8a064fb5a4..3855a39aef 100644 --- a/modules/websocket/lws_peer.cpp +++ b/modules/websocket/lws_peer.cpp @@ -35,6 +35,7 @@ // Needed for socket_helpers on Android at least. UNIXes has it, just include if not windows #if !defined(WINDOWS_ENABLED) #include <netinet/in.h> +#include <sys/socket.h> #endif #include "drivers/unix/socket_helpers.h" @@ -190,9 +191,11 @@ IP_Address LWSPeer::get_connected_host() const { IP_Address ip; int port = 0; - socklen_t len; + socklen_t len = 0; struct sockaddr_storage addr; + int fd = lws_get_socket_fd(wsi); + ERR_FAIL_COND_V(fd == -1, IP_Address()); int ret = getpeername(fd, (struct sockaddr *)&addr, &len); ERR_FAIL_COND_V(ret != 0, IP_Address()); @@ -209,9 +212,11 @@ uint16_t LWSPeer::get_connected_port() const { IP_Address ip; int port = 0; - socklen_t len; + socklen_t len = 0; struct sockaddr_storage addr; + int fd = lws_get_socket_fd(wsi); + ERR_FAIL_COND_V(fd == -1, 0); int ret = getpeername(fd, (struct sockaddr *)&addr, &len); ERR_FAIL_COND_V(ret != 0, 0); |