Skip to content

Commit

Permalink
Use WSAConnect instead of connect on Windows.
Browse files Browse the repository at this point in the history
The misterious windows networking stack...
Using connect instead of WSAConnect causes socket error 10022 under
certain conditions.
See: https://github.com/godotengine/webrtc-native/ (issue 6)
Having to guess, code path for connect is different then WSAConnect with
NULL extra parameters.
The only reference about weird error with this code mentions something
called "Windows Filtering Platform" but windows internals are, as
always, obscure.

This might be something to try and report to Microsoft if anyone has the
time to spare with the likely outcome of being ignored.
  • Loading branch information
Faless committed Oct 25, 2019
1 parent 6ce35e1 commit d780570
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/unix/net_socket_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#define SOCK_CBUF(x) x
#define SOCK_IOCTL ioctl
#define SOCK_CLOSE ::close
#define SOCK_CONNECT(p_sock, p_addr, p_addr_len) ::connect(p_sock, p_addr, p_addr_len)

/* Windows */
#elif defined(WINDOWS_ENABLED)
Expand All @@ -83,6 +84,9 @@
#define SOCK_CBUF(x) (const char *)(x)
#define SOCK_IOCTL ioctlsocket
#define SOCK_CLOSE closesocket
// connect is broken on windows under certain conditions, reasons unknown:
// See https://github.com/godotengine/webrtc-native/issues/6
#define SOCK_CONNECT(p_sock, p_addr, p_addr_len) ::WSAConnect(p_sock, p_addr, p_addr_len, NULL, NULL, NULL, NULL)

// Workaround missing flag in MinGW
#if defined(__MINGW32__) && !defined(SIO_UDP_NETRESET)
Expand Down Expand Up @@ -409,7 +413,7 @@ Error NetSocketPosix::connect_to_host(IP_Address p_host, uint16_t p_port) {
struct sockaddr_storage addr;
size_t addr_size = _set_addr_storage(&addr, p_host, p_port, _ip_type);

if (::connect(_sock, (struct sockaddr *)&addr, addr_size) != 0) {
if (SOCK_CONNECT(_sock, (struct sockaddr *)&addr, addr_size) != 0) {

NetError err = _get_socket_error();

Expand Down

0 comments on commit d780570

Please sign in to comment.