libmicrohttpd

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

commit e03de7c2016df62e82a1c38226e12e2a2acda69e
parent 0ecf4f26e4c1a4c03d66e1d04bf4cae62bd236a0
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sun, 21 May 2017 23:01:21 +0300

Fixed HTTP "upgrade" after 7d3050325e3b77a061b40ea9ce77a360d14b4dea

Diffstat:
Msrc/microhttpd/daemon.c | 91+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Msrc/microhttpd/internal.h | 11+++++++++++
Msrc/microhttpd/response.c | 2+-
3 files changed, 66 insertions(+), 38 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -2699,29 +2699,7 @@ internal_add_connection (struct MHD_Daemon *daemon, /** - * Suspend handling of network data for a given connection. This can - * be used to dequeue a connection from MHD's event loop (external - * select, internal select or thread pool; not applicable to - * thread-per-connection!) for a while. - * - * If you use this API in conjunction with a internal select or a - * thread pool, you must set the option #MHD_USE_ITC to - * ensure that a resumed connection is immediately processed by MHD. - * - * Suspended connections continue to count against the total number of - * connections allowed (per daemon, as well as per IP, if such limits - * are set). Suspended connections will NOT time out; timeouts will - * restart when the connection handling is resumed. While a - * connection is suspended, MHD will not detect disconnects by the - * client. - * - * The only safe time to suspend a connection is from the - * #MHD_AccessHandlerCallback. - * - * Finally, it is an API violation to call #MHD_stop_daemon while - * having suspended connections (this will at least create memory and - * socket leaks or lead to undefined behavior). You must explicitly - * resume all connections before stopping the daemon. + * Internal version of ::MHD_suspend_connection(). * * @remark In thread-per-connection mode: can be called from any thread, * in any other mode: to be called only from thread that process @@ -2730,24 +2708,11 @@ internal_add_connection (struct MHD_Daemon *daemon, * @param connection the connection to suspend */ void -MHD_suspend_connection (struct MHD_Connection *connection) +internal_suspend_connection_ (struct MHD_Connection *connection) { struct MHD_Daemon *daemon = connection->daemon; - if (0 == (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) - MHD_PANIC (_("Cannot suspend connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n")); MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); -#ifdef UPGRADE_SUPPORT - if (NULL != connection->urh) - { -#ifdef HAVE_MESSAGES - MHD_DLOG (daemon, - _("Error: connection sheduled for \"upgrade\" cannot be suspended")); -#endif /* HAVE_MESSAGES */ - MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); - return; - } -#endif /* UPGRADE_SUPPORT */ if (connection->resuming) { /* suspending again while we didn't even complete resuming yet */ @@ -2801,6 +2766,58 @@ MHD_suspend_connection (struct MHD_Connection *connection) /** + * Suspend handling of network data for a given connection. This can + * be used to dequeue a connection from MHD's event loop (external + * select, internal select or thread pool; not applicable to + * thread-per-connection!) for a while. + * + * If you use this API in conjunction with a internal select or a + * thread pool, you must set the option #MHD_USE_ITC to + * ensure that a resumed connection is immediately processed by MHD. + * + * Suspended connections continue to count against the total number of + * connections allowed (per daemon, as well as per IP, if such limits + * are set). Suspended connections will NOT time out; timeouts will + * restart when the connection handling is resumed. While a + * connection is suspended, MHD will not detect disconnects by the + * client. + * + * The only safe time to suspend a connection is from the + * #MHD_AccessHandlerCallback. + * + * Finally, it is an API violation to call #MHD_stop_daemon while + * having suspended connections (this will at least create memory and + * socket leaks or lead to undefined behavior). You must explicitly + * resume all connections before stopping the daemon. + * + * @remark In thread-per-connection mode: can be called from any thread, + * in any other mode: to be called only from thread that process + * daemon's select()/poll()/etc. + * + * @param connection the connection to suspend + */ +void +MHD_suspend_connection (struct MHD_Connection *connection) +{ + struct MHD_Daemon * const daemon = connection->daemon; + + if (0 == (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME)) + MHD_PANIC (_("Cannot suspend connections without enabling MHD_ALLOW_SUSPEND_RESUME!\n")); +#ifdef UPGRADE_SUPPORT + if (NULL != connection->urh) + { +#ifdef HAVE_MESSAGES + MHD_DLOG (daemon, + _("Error: connection scheduled for \"upgrade\" cannot be suspended")); +#endif /* HAVE_MESSAGES */ + return; + } +#endif /* UPGRADE_SUPPORT */ + internal_suspend_connection_ (connection); +} + + +/** * Resume handling of network data for suspended connection. It is * safe to resume a suspended connection at any time. Calling this function * on a connection that was not previously suspended will result diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -1926,5 +1926,16 @@ MHD_check_response_header_token_ci (const struct MHD_Response *response, #define MHD_check_response_header_s_token_ci(r,k,tkn) \ MHD_check_response_header_token_ci((r),(k),(tkn),MHD_STATICSTR_LEN_(tkn)) +/** + * Internal version of ::MHD_suspend_connection(). + * + * @remark In thread-per-connection mode: can be called from any thread, + * in any other mode: to be called only from thread that process + * daemon's select()/poll()/etc. + * + * @param connection the connection to suspend + */ +void +internal_suspend_connection_ (struct MHD_Connection *connection); #endif diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -962,7 +962,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, /* As far as MHD's event loops are concerned, this connection is suspended; it will be resumed once application is done by the #MHD_upgrade_action() function */ - MHD_suspend_connection (connection); + internal_suspend_connection_ (connection); /* hand over socket to application */ response->upgrade_handler (response->upgrade_handler_cls,