From 84e24017b03ab2e4675281610e22f549e9991f79 Mon Sep 17 00:00:00 2001 From: Pablo Andres Fuente Date: Mon, 16 Sep 2024 23:38:32 -0300 Subject: [PATCH] Adding a macro on NetSocketPosix to pick the right type for FIONREAD len On Windows, `ioctlsocket` returns `len` as an unsigned long. On Posix, `ioctl` returns `len` as an int. This aims to fix #41287 bug, which was seen on Linux. The implementation is just a new macro that is set with the proper type for each platform. --- drivers/unix/net_socket_posix.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp index 1e52b39be15..5caa33100ee 100644 --- a/drivers/unix/net_socket_posix.cpp +++ b/drivers/unix/net_socket_posix.cpp @@ -67,6 +67,7 @@ #define SOCK_BUF(x) x #define SOCK_CBUF(x) x #define SOCK_IOCTL ioctl +#define SOCK_FIONREAD_LEN_TYPE int #define SOCK_CLOSE ::close #define SOCK_CONNECT(p_sock, p_addr, p_addr_len) ::connect(p_sock, p_addr, p_addr_len) @@ -81,6 +82,7 @@ #define SOCK_BUF(x) (char *)(x) #define SOCK_CBUF(x) (const char *)(x) #define SOCK_IOCTL ioctlsocket +#define SOCK_FIONREAD_LEN_TYPE unsigned long #define SOCK_CLOSE closesocket // connect is broken on windows under certain conditions, reasons unknown: // See https://github.com/godotengine/webrtc-native/issues/6 @@ -742,7 +744,7 @@ bool NetSocketPosix::is_open() const { int NetSocketPosix::get_available_bytes() const { ERR_FAIL_COND_V(!is_open(), -1); - unsigned long len; + SOCK_FIONREAD_LEN_TYPE len; int ret = SOCK_IOCTL(_sock, FIONREAD, &len); if (ret == -1) { _get_socket_error();