mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-28 21:59:02 +08:00
Refactor mg_open_listener()
This commit is contained in:
parent
5ac5c93c90
commit
5c66d32bc0
@ -3335,7 +3335,7 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
||||
(void) on;
|
||||
|
||||
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)) && \
|
||||
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
||||
} 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
|
||||
// SO_REUSE (in lwipopts.h), otherwise the code below will compile
|
||||
// but won't work! (setsockopt will return EINVAL)
|
||||
MG_ERROR(("reuseaddr: %s", MG_SOCK_ERRNO));
|
||||
MG_ERROR(("reuseaddr: %d", MG_SOCK_ERRNO));
|
||||
#endif
|
||||
#if MG_ARCH == MG_ARCH_WIN32 && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
||||
} 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));
|
||||
#endif
|
||||
} 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 &&
|
||||
listen(fd, MG_SOCK_LISTEN_BACKLOG_SIZE) != 0)) {
|
||||
// NOTE(lsm): FreeRTOS uses backlog value as a connection limit
|
||||
// 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 {
|
||||
setlocaddr(fd, &c->loc);
|
||||
mg_set_non_blocking_mode(fd);
|
||||
|
@ -198,7 +198,7 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
|
||||
(void) on;
|
||||
|
||||
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)) && \
|
||||
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
||||
} 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
|
||||
// SO_REUSE (in lwipopts.h), otherwise the code below will compile
|
||||
// but won't work! (setsockopt will return EINVAL)
|
||||
MG_ERROR(("reuseaddr: %s", MG_SOCK_ERRNO));
|
||||
MG_ERROR(("reuseaddr: %d", MG_SOCK_ERRNO));
|
||||
#endif
|
||||
#if MG_ARCH == MG_ARCH_WIN32 && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
||||
} 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));
|
||||
#endif
|
||||
} 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 &&
|
||||
listen(fd, MG_SOCK_LISTEN_BACKLOG_SIZE) != 0)) {
|
||||
// NOTE(lsm): FreeRTOS uses backlog value as a connection limit
|
||||
// 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 {
|
||||
setlocaddr(fd, &c->loc);
|
||||
mg_set_non_blocking_mode(fd);
|
||||
|
Loading…
Reference in New Issue
Block a user