Better reuseaddr handling on Win32

This commit is contained in:
cpq committed 2021-01-13 03:08:11 +00:00
1 parent 83c106a857
commit 6c93446a1f
3 files changed
+9 -1

No files matched your search

+4
View File
@@ -11,6 +11,9 @@
#if MG_ENABLE_SOCKET
#if defined(_WIN32)
#ifndef SO_EXCLUSIVEADDRUSE
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
#endif
#define MG_SOCK_ERRNO WSAGetLastError()
#define FD(C_) ((SOCKET)(C_)->fd)
#elif MG_ARCH == MG_ARCH_FREERTOS
@@ -207,6 +210,7 @@ SOCKET mg_open_listener(const char *url) {
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
!setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on,
sizeof(on)) &&
!setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof(on)) &&
#endif
bind(fd, &usa.sa, slen) == 0 &&
// NOTE(lsm): FreeRTOS uses backlog value as a connection limit