Skip to content

Commit 397b01d

Browse files
authored
Merge pull request #22332 from Faless/udp_win_reset
Fix Winsock UDP ECONNRESET/ENETRESET bug
2 parents d878c82 + c37442e commit 397b01d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

drivers/unix/net_socket_posix.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
#elif defined(WINDOWS_ENABLED)
7575
#include <winsock2.h>
7676
#include <ws2tcpip.h>
77+
78+
#include <mswsock.h>
7779
// Some custom defines to minimize ifdefs
7880
#define SOCK_EMPTY INVALID_SOCKET
7981
#define SOCK_BUF(x) (char *)(x)
@@ -85,6 +87,10 @@
8587
#ifndef MSG_NOSIGNAL
8688
#define MSG_NOSIGNAL 0
8789
#endif
90+
// Workaround missing flag in MinGW
91+
#if defined(__MINGW32__) && !defined(SIO_UDP_NETRESET)
92+
#define SIO_UDP_NETRESET _WSAIOW(IOC_VENDOR, 15)
93+
#endif
8894

8995
#endif
9096

@@ -258,6 +264,21 @@ Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) {
258264
}
259265

260266
_is_stream = p_sock_type == TYPE_TCP;
267+
268+
#if defined(WINDOWS_ENABLED)
269+
if (!_is_stream) {
270+
// Disable windows feature/bug reporting WSAECONNRESET/WSAENETRESET when
271+
// recv/recvfrom and an ICMP reply was received from a previous send/sendto.
272+
unsigned long disable = 0;
273+
if (ioctlsocket(_sock, SIO_UDP_CONNRESET, &disable) == SOCKET_ERROR) {
274+
print_verbose("Unable to turn off UDP WSAECONNRESET behaviour on Windows");
275+
}
276+
if (ioctlsocket(_sock, SIO_UDP_NETRESET, &disable) == SOCKET_ERROR) {
277+
// This feature seems not to be supported on wine.
278+
print_verbose("Unable to turn off UDP WSAENETRESET behaviour on Windows");
279+
}
280+
}
281+
#endif
261282
return OK;
262283
}
263284

0 commit comments

Comments
 (0)