mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-30 21:18:25 +00:00
Refactor mg_open_listener()
This commit is contained in:
1 parent
5ac5c93c90
commit
5c66d32bc0
2 files changed
+8
-8
No files matched your search
+4
-4
@@ -3335,7 +3335,7 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
(void) on;
|
(void) on;
|
||||||
|
|
||||||
if ((fd = socket(af, type, proto)) == INVALID_SOCKET) {
|
if ((fd = socket(af, type, proto)) == INVALID_SOCKET) {
|
||||||
MG_ERROR(("socket: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("socket: %d", MG_SOCK_ERRNO));
|
||||||
#if (MG_ARCH != MG_ARCH_WIN32 || !defined(SO_EXCLUSIVEADDRUSE)) && \
|
#if (MG_ARCH != MG_ARCH_WIN32 || !defined(SO_EXCLUSIVEADDRUSE)) && \
|
||||||
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
||||||
} else if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
|
} else if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
|
||||||
@@ -3351,7 +3351,7 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
// defining
|
// defining
|
||||||
// SO_REUSE (in lwipopts.h), otherwise the code below will compile
|
// SO_REUSE (in lwipopts.h), otherwise the code below will compile
|
||||||
// but won't work! (setsockopt will return EINVAL)
|
// but won't work! (setsockopt will return EINVAL)
|
||||||
MG_ERROR(("reuseaddr: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("reuseaddr: %d", MG_SOCK_ERRNO));
|
||||||
#endif
|
#endif
|
||||||
#if MG_ARCH == MG_ARCH_WIN32 && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
#if MG_ARCH == MG_ARCH_WIN32 && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
||||||
} else if (setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on,
|
} else if (setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on,
|
||||||
@@ -3360,12 +3360,12 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
MG_ERROR(("exclusiveaddruse: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("exclusiveaddruse: %s", MG_SOCK_ERRNO));
|
||||||
#endif
|
#endif
|
||||||
} else if (bind(fd, &usa.sa, slen) != 0) {
|
} else if (bind(fd, &usa.sa, slen) != 0) {
|
||||||
MG_ERROR(("bind: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("bind: %d", MG_SOCK_ERRNO));
|
||||||
} else if ((type == SOCK_STREAM &&
|
} else if ((type == SOCK_STREAM &&
|
||||||
listen(fd, MG_SOCK_LISTEN_BACKLOG_SIZE) != 0)) {
|
listen(fd, MG_SOCK_LISTEN_BACKLOG_SIZE) != 0)) {
|
||||||
// NOTE(lsm): FreeRTOS uses backlog value as a connection limit
|
// NOTE(lsm): FreeRTOS uses backlog value as a connection limit
|
||||||
// In case port was set to 0, get the real port number
|
// In case port was set to 0, get the real port number
|
||||||
MG_ERROR(("listen: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("listen: %d", MG_SOCK_ERRNO));
|
||||||
} else {
|
} else {
|
||||||
setlocaddr(fd, &c->loc);
|
setlocaddr(fd, &c->loc);
|
||||||
mg_set_non_blocking_mode(fd);
|
mg_set_non_blocking_mode(fd);
|
||||||
|
|||||||
+4
-4
@@ -198,7 +198,7 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
(void) on;
|
(void) on;
|
||||||
|
|
||||||
if ((fd = socket(af, type, proto)) == INVALID_SOCKET) {
|
if ((fd = socket(af, type, proto)) == INVALID_SOCKET) {
|
||||||
MG_ERROR(("socket: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("socket: %d", MG_SOCK_ERRNO));
|
||||||
#if (MG_ARCH != MG_ARCH_WIN32 || !defined(SO_EXCLUSIVEADDRUSE)) && \
|
#if (MG_ARCH != MG_ARCH_WIN32 || !defined(SO_EXCLUSIVEADDRUSE)) && \
|
||||||
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
||||||
} else if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
|
} else if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
|
||||||
@@ -214,7 +214,7 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
// defining
|
// defining
|
||||||
// SO_REUSE (in lwipopts.h), otherwise the code below will compile
|
// SO_REUSE (in lwipopts.h), otherwise the code below will compile
|
||||||
// but won't work! (setsockopt will return EINVAL)
|
// but won't work! (setsockopt will return EINVAL)
|
||||||
MG_ERROR(("reuseaddr: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("reuseaddr: %d", MG_SOCK_ERRNO));
|
||||||
#endif
|
#endif
|
||||||
#if MG_ARCH == MG_ARCH_WIN32 && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
#if MG_ARCH == MG_ARCH_WIN32 && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
||||||
} else if (setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on,
|
} else if (setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on,
|
||||||
@@ -223,12 +223,12 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
|||||||
MG_ERROR(("exclusiveaddruse: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("exclusiveaddruse: %s", MG_SOCK_ERRNO));
|
||||||
#endif
|
#endif
|
||||||
} else if (bind(fd, &usa.sa, slen) != 0) {
|
} else if (bind(fd, &usa.sa, slen) != 0) {
|
||||||
MG_ERROR(("bind: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("bind: %d", MG_SOCK_ERRNO));
|
||||||
} else if ((type == SOCK_STREAM &&
|
} else if ((type == SOCK_STREAM &&
|
||||||
listen(fd, MG_SOCK_LISTEN_BACKLOG_SIZE) != 0)) {
|
listen(fd, MG_SOCK_LISTEN_BACKLOG_SIZE) != 0)) {
|
||||||
// NOTE(lsm): FreeRTOS uses backlog value as a connection limit
|
// NOTE(lsm): FreeRTOS uses backlog value as a connection limit
|
||||||
// In case port was set to 0, get the real port number
|
// In case port was set to 0, get the real port number
|
||||||
MG_ERROR(("listen: %s", MG_SOCK_ERRNO));
|
MG_ERROR(("listen: %d", MG_SOCK_ERRNO));
|
||||||
} else {
|
} else {
|
||||||
setlocaddr(fd, &c->loc);
|
setlocaddr(fd, &c->loc);
|
||||||
mg_set_non_blocking_mode(fd);
|
mg_set_non_blocking_mode(fd);
|
||||||
|
|||||||
Reference in new issue
Block a user