mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 13:37:34 +08:00
Commonize arg checking in cfunctions
Add `mjs_check_arg()` which checks whether argument is provided, and checks its type. It simplifies code and makes it smaller (because error strings are not ad-hoc, so they are not duplicated) As part of that, also commonize type stringifying: implement `mjs_stringify_type` and reimplement `mjs_typeof` on top of that. Use `mjs_check_arg()` in `mjs_string_slice()` and `mjs_string_char_code_at()`. PUBLISHED_FROM=0b72cf479738ff405d991cbd4bf9e75edda0f111
This commit is contained in:
parent
fb04203b72
commit
bd130136bc
19
mongoose.c
19
mongoose.c
@ -3742,20 +3742,19 @@ time_t mg_socket_if_poll(struct mg_iface *iface, int timeout_ms) {
|
|||||||
#if MG_ENABLE_BROADCAST
|
#if MG_ENABLE_BROADCAST
|
||||||
MG_INTERNAL void mg_socketpair_close(sock_t *sock) {
|
MG_INTERNAL void mg_socketpair_close(sock_t *sock) {
|
||||||
while (1) {
|
while (1) {
|
||||||
if (closesocket(*sock) == -1 && errno == EINTR)
|
if (closesocket(*sock) == -1 && errno == EINTR) continue;
|
||||||
continue;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*sock = INVALID_SOCKET;
|
*sock = INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
MG_INTERNAL sock_t mg_socketpair_accept(sock_t sock,
|
MG_INTERNAL sock_t
|
||||||
union socket_address *sa,
|
mg_socketpair_accept(sock_t sock, union socket_address *sa, socklen_t sa_len) {
|
||||||
socklen_t sa_len) {
|
|
||||||
sock_t rc;
|
sock_t rc;
|
||||||
while(1) {
|
while (1) {
|
||||||
if ((rc = accept(sock, &sa->sa, &sa_len)) == INVALID_SOCKET && errno == EINTR)
|
if ((rc = accept(sock, &sa->sa, &sa_len)) == INVALID_SOCKET &&
|
||||||
continue;
|
errno == EINTR)
|
||||||
|
continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
@ -3783,8 +3782,8 @@ int mg_socketpair(sock_t sp[2], int sock_type) {
|
|||||||
} else if (sock_type == SOCK_DGRAM &&
|
} else if (sock_type == SOCK_DGRAM &&
|
||||||
(getsockname(sp[0], &sa.sa, &len) != 0 ||
|
(getsockname(sp[0], &sa.sa, &len) != 0 ||
|
||||||
connect(sock, &sa.sa, len) != 0)) {
|
connect(sock, &sa.sa, len) != 0)) {
|
||||||
} else if ((sp[1] = (sock_type == SOCK_DGRAM ? sock
|
} else if ((sp[1] = (sock_type == SOCK_DGRAM ? sock : mg_socketpair_accept(
|
||||||
: mg_socketpair_accept(sock, &sa, len))) ==
|
sock, &sa, len))) ==
|
||||||
INVALID_SOCKET) {
|
INVALID_SOCKET) {
|
||||||
} else {
|
} else {
|
||||||
mg_set_close_on_exec(sp[0]);
|
mg_set_close_on_exec(sp[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user