mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-05 22:08:23 +00:00
On Windows, prefer EXCLADDRINUSE, then REUSEADDR
This commit is contained in:
1 parent
fd86eb7aa7
commit
717c9dbe89
2 files changed
+12
-14
No files matched your search
+6
-7
@@ -4547,7 +4547,12 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
|
|
||||||
if ((fd = socket(af, type, proto)) == MG_INVALID_SOCKET) {
|
if ((fd = socket(af, type, proto)) == MG_INVALID_SOCKET) {
|
||||||
MG_ERROR(("socket: %d", MG_SOCK_ERR(-1)));
|
MG_ERROR(("socket: %d", MG_SOCK_ERR(-1)));
|
||||||
#if defined(SO_REUSEADDR) && (!defined(LWIP_SOCKET) || SO_REUSE)
|
#if defined(SO_EXCLUSIVEADDRUSE)
|
||||||
|
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
|
||||||
|
(char *) &on, sizeof(on))) != 0) {
|
||||||
|
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
|
||||||
|
MG_ERROR(("setsockopt(SO_EXCLUSIVEADDRUSE): %d %d", on, MG_SOCK_ERR(rc)));
|
||||||
|
#elif defined(SO_REUSEADDR) && (!defined(LWIP_SOCKET) || SO_REUSE)
|
||||||
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
|
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
|
||||||
sizeof(on))) != 0) {
|
sizeof(on))) != 0) {
|
||||||
// 1. SO_REUSEADDR semantics on UNIX and Windows is different. On
|
// 1. SO_REUSEADDR semantics on UNIX and Windows is different. On
|
||||||
@@ -4561,12 +4566,6 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
// won't work! (setsockopt will return EINVAL)
|
// won't work! (setsockopt will return EINVAL)
|
||||||
MG_ERROR(("setsockopt(SO_REUSEADDR): %d", MG_SOCK_ERR(rc)));
|
MG_ERROR(("setsockopt(SO_REUSEADDR): %d", MG_SOCK_ERR(rc)));
|
||||||
#endif
|
#endif
|
||||||
#if defined(SO_EXCLUSIVEADDRUSE)
|
|
||||||
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
|
|
||||||
(char *) &on, sizeof(on))) != 0) {
|
|
||||||
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
|
|
||||||
MG_ERROR(("setsockopt(SO_EXCLUSIVEADDRUSE): %d", MG_SOCK_ERR(rc)));
|
|
||||||
#endif
|
|
||||||
#if defined(IPV6_V6ONLY)
|
#if defined(IPV6_V6ONLY)
|
||||||
} else if (c->loc.is_ip6 &&
|
} else if (c->loc.is_ip6 &&
|
||||||
(rc = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on,
|
(rc = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on,
|
||||||
|
|||||||
+6
-7
@@ -193,7 +193,12 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
|
|
||||||
if ((fd = socket(af, type, proto)) == MG_INVALID_SOCKET) {
|
if ((fd = socket(af, type, proto)) == MG_INVALID_SOCKET) {
|
||||||
MG_ERROR(("socket: %d", MG_SOCK_ERR(-1)));
|
MG_ERROR(("socket: %d", MG_SOCK_ERR(-1)));
|
||||||
#if defined(SO_REUSEADDR) && (!defined(LWIP_SOCKET) || SO_REUSE)
|
#if defined(SO_EXCLUSIVEADDRUSE)
|
||||||
|
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
|
||||||
|
(char *) &on, sizeof(on))) != 0) {
|
||||||
|
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
|
||||||
|
MG_ERROR(("setsockopt(SO_EXCLUSIVEADDRUSE): %d %d", on, MG_SOCK_ERR(rc)));
|
||||||
|
#elif defined(SO_REUSEADDR) && (!defined(LWIP_SOCKET) || SO_REUSE)
|
||||||
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
|
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
|
||||||
sizeof(on))) != 0) {
|
sizeof(on))) != 0) {
|
||||||
// 1. SO_REUSEADDR semantics on UNIX and Windows is different. On
|
// 1. SO_REUSEADDR semantics on UNIX and Windows is different. On
|
||||||
@@ -207,12 +212,6 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
// won't work! (setsockopt will return EINVAL)
|
// won't work! (setsockopt will return EINVAL)
|
||||||
MG_ERROR(("setsockopt(SO_REUSEADDR): %d", MG_SOCK_ERR(rc)));
|
MG_ERROR(("setsockopt(SO_REUSEADDR): %d", MG_SOCK_ERR(rc)));
|
||||||
#endif
|
#endif
|
||||||
#if defined(SO_EXCLUSIVEADDRUSE)
|
|
||||||
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
|
|
||||||
(char *) &on, sizeof(on))) != 0) {
|
|
||||||
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
|
|
||||||
MG_ERROR(("setsockopt(SO_EXCLUSIVEADDRUSE): %d", MG_SOCK_ERR(rc)));
|
|
||||||
#endif
|
|
||||||
#if defined(IPV6_V6ONLY)
|
#if defined(IPV6_V6ONLY)
|
||||||
} else if (c->loc.is_ip6 &&
|
} else if (c->loc.is_ip6 &&
|
||||||
(rc = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on,
|
(rc = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on,
|
||||||
|
|||||||
Reference in new issue
Block a user