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
17
mongoose.c
17
mongoose.c
@ -3742,19 +3742,18 @@ time_t mg_socket_if_poll(struct mg_iface *iface, int timeout_ms) {
|
||||
#if MG_ENABLE_BROADCAST
|
||||
MG_INTERNAL void mg_socketpair_close(sock_t *sock) {
|
||||
while (1) {
|
||||
if (closesocket(*sock) == -1 && errno == EINTR)
|
||||
continue;
|
||||
if (closesocket(*sock) == -1 && errno == EINTR) continue;
|
||||
break;
|
||||
}
|
||||
*sock = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
MG_INTERNAL sock_t mg_socketpair_accept(sock_t sock,
|
||||
union socket_address *sa,
|
||||
socklen_t sa_len) {
|
||||
MG_INTERNAL sock_t
|
||||
mg_socketpair_accept(sock_t sock, union socket_address *sa, socklen_t sa_len) {
|
||||
sock_t rc;
|
||||
while(1) {
|
||||
if ((rc = accept(sock, &sa->sa, &sa_len)) == INVALID_SOCKET && errno == EINTR)
|
||||
while (1) {
|
||||
if ((rc = accept(sock, &sa->sa, &sa_len)) == INVALID_SOCKET &&
|
||||
errno == EINTR)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
@ -3783,8 +3782,8 @@ int mg_socketpair(sock_t sp[2], int sock_type) {
|
||||
} else if (sock_type == SOCK_DGRAM &&
|
||||
(getsockname(sp[0], &sa.sa, &len) != 0 ||
|
||||
connect(sock, &sa.sa, len) != 0)) {
|
||||
} else if ((sp[1] = (sock_type == SOCK_DGRAM ? sock
|
||||
: mg_socketpair_accept(sock, &sa, len))) ==
|
||||
} else if ((sp[1] = (sock_type == SOCK_DGRAM ? sock : mg_socketpair_accept(
|
||||
sock, &sa, len))) ==
|
||||
INVALID_SOCKET) {
|
||||
} else {
|
||||
mg_set_close_on_exec(sp[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user