From 0294603dfc23128e02b8b60f5e3c07db6107a057 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Thu, 12 May 2022 15:07:02 +0100 Subject: [PATCH] MG_ARCH_RTX nits --- docs/README.md | 5 +++++ mongoose.c | 3 ++- mongoose.h | 4 +++- src/arch_rtx.h | 2 ++ src/config.h | 2 +- src/sock.c | 3 ++- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 6f12e60e..7334f68c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -244,6 +244,11 @@ struct mg_connection { mg_http_printf_chunk(c, "%s", "bar"); mg_http_printf_chunk(c, ""); // Don't forget the last empty chunk ``` +- On embedded environment, make sure that serving task has enough stack: + give it 2k for simple RESTful serving, or 4-8k for complex dynamic/static + serving. In certain environments, it is necessary to adjust heap size, too. + By default, IO buffer allocation size `MG_IO_SIZE` is 2048: change it to 512 + to trim run-time per-connection memory consumption. ## Build options diff --git a/mongoose.c b/mongoose.c index 36e52c03..6927bc55 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3543,7 +3543,8 @@ static bool mg_socketpair(SOCKET sp[2], union usa usa[2]) { usa[1] = usa[0]; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) != INVALID_SOCKET && - bind(sock, &usa[0].sa, len) == 0 && listen(sock, 3) == 0 && + bind(sock, &usa[0].sa, len) == 0 && + listen(sock, MG_SOCK_LISTEN_BACKLOG_SIZE) == 0 && getsockname(sock, &usa[0].sa, &len) == 0 && (sp[0] = socket(AF_INET, SOCK_STREAM, 0)) != INVALID_SOCKET && connect(sp[0], &usa[0].sa, len) == 0 && diff --git a/mongoose.h b/mongoose.h index cf36714d..4a3ab101 100644 --- a/mongoose.h +++ b/mongoose.h @@ -335,6 +335,8 @@ struct timeval { #include +#define MG_IO_SIZE 512 +#define MG_SOCK_LISTEN_BACKLOG_SIZE 1 #define MG_ENABLE_CUSTOM_MILLIS 1 typedef int socklen_t; #define closesocket(x) closesocket(x) @@ -629,7 +631,7 @@ int sscanf(const char *, const char *, ...); #endif #ifndef MG_SOCK_LISTEN_BACKLOG_SIZE -#define MG_SOCK_LISTEN_BACKLOG_SIZE 128 +#define MG_SOCK_LISTEN_BACKLOG_SIZE 3 #endif #ifndef MG_DIRSEP diff --git a/src/arch_rtx.h b/src/arch_rtx.h index 8b7dfbc5..6c53f529 100644 --- a/src/arch_rtx.h +++ b/src/arch_rtx.h @@ -15,6 +15,8 @@ #include +#define MG_IO_SIZE 512 +#define MG_SOCK_LISTEN_BACKLOG_SIZE 1 #define MG_ENABLE_CUSTOM_MILLIS 1 typedef int socklen_t; #define closesocket(x) closesocket(x) diff --git a/src/config.h b/src/config.h index 49074dae..e4a69758 100644 --- a/src/config.h +++ b/src/config.h @@ -80,7 +80,7 @@ #endif #ifndef MG_SOCK_LISTEN_BACKLOG_SIZE -#define MG_SOCK_LISTEN_BACKLOG_SIZE 128 +#define MG_SOCK_LISTEN_BACKLOG_SIZE 3 #endif #ifndef MG_DIRSEP diff --git a/src/sock.c b/src/sock.c index 8de82d75..6bc7d974 100644 --- a/src/sock.c +++ b/src/sock.c @@ -406,7 +406,8 @@ static bool mg_socketpair(SOCKET sp[2], union usa usa[2]) { usa[1] = usa[0]; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) != INVALID_SOCKET && - bind(sock, &usa[0].sa, len) == 0 && listen(sock, 3) == 0 && + bind(sock, &usa[0].sa, len) == 0 && + listen(sock, MG_SOCK_LISTEN_BACKLOG_SIZE) == 0 && getsockname(sock, &usa[0].sa, &len) == 0 && (sp[0] = socket(AF_INET, SOCK_STREAM, 0)) != INVALID_SOCKET && connect(sp[0], &usa[0].sa, len) == 0 &&