libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 5b241496eba488f33b89b44578ff33b16ddf0c37
parent 56fe7ad2895e939907bfad5d8357fc4dd86c8e7e
Author: Evgeny Grin <k2k@drgrin.dev>
Date:   Thu, 15 May 2025 18:11:14 +0300

json_echo.c: properly use MHD2 API

Diffstat:
Msrc/examples2/json_echo.c | 17++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/examples2/json_echo.c b/src/examples2/json_echo.c @@ -1,6 +1,7 @@ /* This file is part of libmicrohttpd - Copyright (C) 2025 Christian Grothoff (and other contributing authors) + Copyright (C) 2025 Christian Grothoff, Evgeny Grin (and other + contributing authors) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -20,6 +21,7 @@ * @file json_echo.c * @brief example for processing POST requests with JSON uploads, echos the JSON back to the client * @author Christian Grothoff + * @author Karlson2k (Evgeny Grin) */ #include <stdlib.h> #include <string.h> @@ -156,9 +158,10 @@ sock_reg_update_cb ( "reg update on %d - %d\n", fd, watch_for); - /* Note: This code only works on UNIX where MHD_Socket is an "int". */ - if (fd >= FD_SETSIZE) - return NULL; /* not allowed by select() */ +#ifdef MHD_SOCKETS_KIND_POSIX + /* The value is limited by MHD_D_OPTION_FD_NUMBER_LIMIT() */ + assert (fd < FD_SETSIZE); +#endif /* MHD_SOCKETS_KIND_POSIX */ if (MHD_FD_STATE_NONE == watch_for) { /* Remove from DLL */ @@ -193,9 +196,8 @@ sock_reg_update_cb ( } /* MHD could change its associated context, so always update */ app_cntx->ecb_cntx = ecb_cntx; - /* Since we are level-triggered and thus called by MHD in every - iteration, we simply build the event sets for select() - here directly. */ + /* Since we are called by MHD in every iteration, we simply build + the event sets for select() here directly. */ if (watch_for & MHD_FD_STATE_RECV) FD_SET (fd, &rs); @@ -293,6 +295,7 @@ main (int argc, MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL ( &sock_reg_update_cb, NULL), + MHD_D_OPTION_FD_NUMBER_LIMIT (FD_SETSIZE), MHD_D_OPTION_DEFAULT_TIMEOUT (120 /* seconds */), MHD_D_OPTION_CONN_MEMORY_LIMIT (256 * 1024), MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO,