libmicrohttpd2

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

commit a73a6be16f6fe1da7b3043cf5c77afd19c312737
parent 8f392a9e5a1007b3cdffa196e8389dc1a60191d0
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Sun, 29 Sep 2024 16:37:21 +0200

respect max_wait_millisec even without select/poll/epoll,
other fixes

Diffstat:
Msrc/mhd2/upgrade_net.c | 29++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/mhd2/upgrade_net.c b/src/mhd2/upgrade_net.c @@ -1,6 +1,6 @@ /* This file is part of GNU libmicrohttpd - Copyright (C) 2024 Evgeny Grin (Karlson2k) + Copyright (C) 2024 Evgeny Grin (Karlson2k) & Christian Grothoff GNU libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -23,6 +23,7 @@ * @brief The implementation of functions for network data exchange * for HTTP Upgraded connections * @author Karlson2k (Evgeny Grin) + * @author Christian Grothoff */ #include "mhd_sys_options.h" @@ -56,7 +57,8 @@ /** * Pause execution for specified number of milliseconds. - * @param ms the number of milliseconds to sleep + * + * @param millisec the number of milliseconds to sleep */ static void mhd_sleep (uint_fast32_t millisec) @@ -270,14 +272,13 @@ MHD_upgraded_recv (struct MHD_UpgradeHandle *MHD_RESTRICT urh, # ifndef mhd_HAVE_MHD_SLEEP return MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED; # else /* mhd_HAVE_MHD_SLEEP */ - mhd_sleep (100); + uint_fast32_t wait_millisec = max_wait_millisec; + + if (wait_millisec > 100) + wait_millisec = 100; + mhd_sleep (wait_millisec); if (MHD_WAIT_INDEFINITELY > max_wait_millisec) - { - if (100 > max_wait_millisec) - max_wait_millisec = 0; - else - max_wait_millisec -= 100; - } + max_wait_millisec -= wait_millisec; # endif /* mhd_HAVE_MHD_SLEEP */ } # endif /* ! MHD_WINSOCK_SOCKETS) || ! MHD_USE_SELECT */ @@ -340,7 +341,7 @@ MHD_upgraded_send (struct MHD_UpgradeHandle *MHD_RESTRICT urh, finish_time_set = false; wait_indefinitely = (MHD_WAIT_INDEFINITELY <= max_wait_millisec); - while (0 == send_buf_size) + while (*sent_size != send_buf_size) { enum mhd_SocketError res; size_t last_block_size; @@ -513,7 +514,13 @@ MHD_upgraded_send (struct MHD_UpgradeHandle *MHD_RESTRICT urh, # ifndef mhd_HAVE_MHD_SLEEP return MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED; # else /* mhd_HAVE_MHD_SLEEP */ - mhd_sleep (100); + uint_fast32_t wait_millisec = max_wait_millisec; + + if (wait_millisec > 100) + wait_millisec = 100; + mhd_sleep (wait_millisec); + if (MHD_WAIT_INDEFINITELY > max_wait_millisec) + max_wait_millisec -= wait_millisec; # endif /* mhd_HAVE_MHD_SLEEP */ } # endif /* ! MHD_WINSOCK_SOCKETS) || ! MHD_USE_SELECT */