libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 035048e67676e25146e248ac7e09ea09fce3e5ea
parent 33628f624579d1ecdc833e91aad3616c85623de9
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon, 21 Sep 2020 11:24:30 +0300

test_upgrade_large.c: used portable way of inter-thread communication

Diffstat:
Msrc/microhttpd/Makefile.am | 4++--
Msrc/microhttpd/test_upgrade_large.c | 36++++++++++++++++--------------------
2 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am @@ -233,7 +233,7 @@ test_upgrade_LDADD = \ $(PTHREAD_LIBS) test_upgrade_large_SOURCES = \ - test_upgrade_large.c test_helpers.h mhd_sockets.h + test_upgrade_large.c test_helpers.h mhd_sockets.h mhd_sockets.c mhd_itc.h mhd_itc_types.h mhd_itc.c test_upgrade_large_CPPFLAGS = \ $(AM_CPPFLAGS) $(MHD_TLS_LIB_CPPFLAGS) test_upgrade_large_CFLAGS = \ @@ -259,7 +259,7 @@ test_upgrade_tls_LDADD = \ $(PTHREAD_LIBS) test_upgrade_large_tls_SOURCES = \ - test_upgrade_large.c test_helpers.h mhd_sockets.h + test_upgrade_large.c test_helpers.h mhd_sockets.h mhd_sockets.c mhd_itc.h mhd_itc_types.h mhd_itc.c test_upgrade_large_tls_CPPFLAGS = \ $(AM_CPPFLAGS) $(MHD_TLS_LIB_CPPFLAGS) test_upgrade_large_tls_CFLAGS = \ diff --git a/src/microhttpd/test_upgrade_large.c b/src/microhttpd/test_upgrade_large.c @@ -48,6 +48,7 @@ #include "platform.h" #include "microhttpd.h" +#include "mhd_itc.h" #include "test_helpers.h" @@ -69,7 +70,7 @@ static int verbose = 0; -static int kicker[2] = {-1, -1}; +static struct MHD_itc_ kicker = MHD_ITC_STATIC_INIT_INVALID; enum tls_tool { @@ -588,9 +589,9 @@ make_blocking (MHD_socket fd) static void kick_select () { - if (-1 != kicker[1]) + if (MHD_ITC_IS_VALID_(kicker)) { - (void) write (kicker[1], "K", 1); + MHD_itc_activate_ (kicker, "K"); } } @@ -917,9 +918,8 @@ run_mhd_select_loop (struct MHD_Daemon *daemon) MHD_socket max_fd; MHD_UNSIGNED_LONG_LONG to; struct timeval tv; - char drain[128]; - if (0 != pipe (kicker)) + if (!MHD_itc_init_ (kicker)) abort (); while (! done) { @@ -929,7 +929,7 @@ run_mhd_select_loop (struct MHD_Daemon *daemon) max_fd = -1; to = 1000; - FD_SET (kicker[0], &rs); + FD_SET (MHD_itc_r_fd_ (kicker), &rs); if (MHD_YES != MHD_get_fdset (daemon, &rs, @@ -949,17 +949,15 @@ run_mhd_select_loop (struct MHD_Daemon *daemon) &es, &tv)) abort (); - if (FD_ISSET (kicker[0], &rs)) - (void) read (kicker[0], drain, sizeof (drain)); + if (FD_ISSET (MHD_itc_r_fd_ (kicker), &rs)) + MHD_itc_clear_ (kicker); MHD_run_from_select (daemon, &rs, &ws, &es); } - close (kicker[0]); - close (kicker[1]); - kicker[0] = -1; - kicker[1] = -1; + MHD_itc_destroy_ (kicker); + MHD_itc_set_invalid_ (kicker); } @@ -1001,13 +999,13 @@ run_mhd_epoll_loop (struct MHD_Daemon *daemon) di = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_EPOLL_FD); ep = di->listen_fd; - if (0 != pipe (kicker)) + if (!MHD_itc_init_ (kicker)) abort (); while (! done) { FD_ZERO (&rs); to = 1000; - FD_SET (kicker[0], &rs); + FD_SET (MHD_itc_r_fd_ (kicker), &rs); FD_SET (ep, &rs); (void) MHD_get_timeout (daemon, &to); @@ -1024,14 +1022,12 @@ run_mhd_epoll_loop (struct MHD_Daemon *daemon) (EAGAIN != errno) && (EINTR != errno) ) abort (); - if (FD_ISSET (kicker[0], &rs)) - (void) read (kicker[0], drain, sizeof (drain)); + if (FD_ISSET (MHD_itc_r_fd_ (kicker), &rs)) + MHD_itc_clear_ (kicker); MHD_run (daemon); } - close (kicker[0]); - close (kicker[1]); - kicker[0] = -1; - kicker[1] = -1; + MHD_itc_destroy_ (kicker); + MHD_itc_set_invalid_ (kicker); }