libmicrohttpd2

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

commit 12c83da4c13883e11ed2a198c4b069d467e0a742
parent 35320a70895ce138917883d71bdd4ccb66a3a150
Author: Evgeny Grin <k2k@drgrin.dev>
Date:   Thu, 15 May 2025 21:13:31 +0300

json_echo.c: fixed compatibility with W32

Diffstat:
Msrc/examples2/json_echo.c | 22++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/examples2/json_echo.c b/src/examples2/json_echo.c @@ -32,6 +32,8 @@ #if ! defined(_WIN32) || defined (__CYGWIN__) # include <sys/select.h> # include <unistd.h> +#else +# include <conio.h> #endif #include <assert.h> struct AppSockContext; /* Forward declaration */ @@ -81,7 +83,7 @@ static fd_set es; /** * Maximum FD in any set. */ -static int max_fd; +static MHD_Socket max_fd = 0; /** * Head of our internal list of sockets to select() on. @@ -318,23 +320,39 @@ main (int argc, FD_ZERO (&rs); FD_ZERO (&ws); FD_ZERO (&es); +#ifdef MHD_SOCKETS_KIND_POSIX FD_SET (STDIN_FILENO, &rs); max_fd = STDIN_FILENO; +#endif /* MHD_SOCKETS_KIND_POSIX */ + /* This will cause MHD to call the #sock_reg_update_cb() */ MHD_daemon_process_reg_events (d, &next_wait); +#ifdef MHD_SOCKETS_KIND_POSIX ts.tv_sec = (time_t) (next_wait / 1000000); +#else /* W32 */ + /* W32 cannot monitor "stdin" with select(). + Use poor man replacement. */ + if (300000u < next_wait) + next_wait = 300000u; + ts.tv_sec = (long) (next_wait / 1000000); +#endif /* W32 */ ts.tv_usec = (long) (next_wait % 1000000); /* Real applications may do nicer error handling here */ - (void) select (max_fd + 1, + (void) select ((int) max_fd + 1, &rs, &ws, &es, &ts); +#ifdef MHD_SOCKETS_KIND_POSIX if (FD_ISSET (STDIN_FILENO, &rs)) break; /* exit on input on stdin */ +#else /* W32 */ + if (0 != _kbhit ()) + break; /* exit on console input */ +#endif /* W32 */ /* Now we need to tell MHD which events were triggered */ for (pos = head; NULL != pos; pos = pos->next)