mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-27 20:59:00 +08:00
On Windows, prefer EXCLADDRINUSE, then REUSEADDR
This commit is contained in:
parent
fd86eb7aa7
commit
717c9dbe89
13
mongoose.c
13
mongoose.c
@ -4547,7 +4547,12 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
||||
|
||||
if ((fd = socket(af, type, proto)) == MG_INVALID_SOCKET) {
|
||||
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,
|
||||
sizeof(on))) != 0) {
|
||||
// 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)
|
||||
MG_ERROR(("setsockopt(SO_REUSEADDR): %d", MG_SOCK_ERR(rc)));
|
||||
#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)
|
||||
} else if (c->loc.is_ip6 &&
|
||||
(rc = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on,
|
||||
|
13
src/sock.c
13
src/sock.c
@ -193,7 +193,12 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
||||
|
||||
if ((fd = socket(af, type, proto)) == MG_INVALID_SOCKET) {
|
||||
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,
|
||||
sizeof(on))) != 0) {
|
||||
// 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)
|
||||
MG_ERROR(("setsockopt(SO_REUSEADDR): %d", MG_SOCK_ERR(rc)));
|
||||
#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)
|
||||
} else if (c->loc.is_ip6 &&
|
||||
(rc = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on,
|
||||
|
Loading…
Reference in New Issue
Block a user