libmicrohttpd

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

commit 71a67ca95997fb2c3a90108a776f61fe1b95e68c
parent 7f1dbb2aef40573861d9d19add648d1a327386f2
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri,  2 Mar 2018 20:42:56 +0100

remove dead IN_CLEANUP state, revert previous patch that called completed callback from wrong thread

Diffstat:
Msrc/lib/connection_add.c | 31++++++++++++++-----------------
Msrc/lib/connection_call_handlers.c | 6------
Msrc/lib/internal.h | 101++++++++++++++++++++++++++++++++++++++-----------------------------------------
Msrc/lib/request_info.c | 7+++----
Msrc/lib/request_resume.c | 2--
Msrc/microhttpd/connection.c | 9+--------
Msrc/microhttpd/daemon.c | 21++++++++-------------
Msrc/microhttpd/internal.h | 5-----
8 files changed, 74 insertions(+), 108 deletions(-)

diff --git a/src/lib/connection_add.c b/src/lib/connection_add.c @@ -110,7 +110,7 @@ thread_main_handle_connection (void *data) const bool use_poll = false; #endif /* ! HAVE_POLL */ bool was_suspended = false; - + MHD_thread_init_(&con->pid); while ( (! daemon->shutdown) && @@ -398,7 +398,7 @@ thread_main_handle_connection (void *data) { /* Normal HTTP processing is finished, * notify application. */ - if (NULL != con->request.response->termination_cb) + if (NULL != con->request.response->termination_cb) con->request.response->termination_cb (con->request.response->termination_cb_cls, MHD_REQUEST_TERMINATED_COMPLETED_OK, @@ -419,22 +419,19 @@ thread_main_handle_connection (void *data) } #endif /* UPGRADE_SUPPORT */ } - if (MHD_REQUEST_IN_CLEANUP != con->request.state) - { #if DEBUG_CLOSE #ifdef HAVE_MESSAGES - MHD_DLOG (con->daemon, - MHD_SC_THREAD_TERMINATING, - _("Processing thread terminating. Closing connection\n")); + MHD_DLOG (con->daemon, + MHD_SC_THREAD_TERMINATING, + _("Processing thread terminating. Closing connection\n")); #endif #endif - if (MHD_REQUEST_CLOSED != con->request.state) - MHD_connection_close_ (con, - (daemon->shutdown) ? - MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: - MHD_REQUEST_TERMINATED_WITH_ERROR); - MHD_request_handle_idle_ (&con->request); - } + if (MHD_REQUEST_CLOSED != con->request.state) + MHD_connection_close_ (con, + (daemon->shutdown) ? + MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: + MHD_REQUEST_TERMINATED_WITH_ERROR); + MHD_request_handle_idle_ (&con->request); exit: if (NULL != con->request.response) { @@ -892,7 +889,7 @@ internal_add_connection (struct MHD_Daemon *daemon, #endif } return MHD_SC_OK; - + cleanup: if (NULL != daemon->notify_connection_cb) daemon->notify_connection_cb (daemon->notify_connection_cb_cls, @@ -908,7 +905,7 @@ internal_add_connection (struct MHD_Daemon *daemon, addr, addrlen); MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); - if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_model) + if (MHD_TM_THREAD_PER_CONNECTION != daemon->threading_model) { XDLL_remove (daemon->normal_timeout_head, daemon->normal_timeout_tail, @@ -976,7 +973,7 @@ MHD_daemon_add_connection (struct MHD_Daemon *daemon, { sk_nonbl = true; } - + if ( (daemon->enable_turbo) && (! MHD_socket_noninheritable_ (client_socket)) ) { diff --git a/src/lib/connection_call_handlers.c b/src/lib/connection_call_handlers.c @@ -971,9 +971,6 @@ MHD_request_handle_write_ (struct MHD_Request *request) return; case MHD_REQUEST_CLOSED: return; - case MHD_REQUEST_IN_CLEANUP: - mhd_assert (0); - return; #ifdef UPGRADE_SUPPORT case MHD_REQUEST_UPGRADE: mhd_assert (0); @@ -3048,9 +3045,6 @@ connection_update_event_loop_info (struct MHD_Connection *connection) case MHD_REQUEST_CLOSED: request->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; return; /* do nothing, not even reading */ - case MHD_REQUEST_IN_CLEANUP: - mhd_assert (0); - break; #ifdef UPGRADE_SUPPORT case MHD_REQUEST_UPGRADE: mhd_assert (0); diff --git a/src/lib/internal.h b/src/lib/internal.h @@ -209,7 +209,7 @@ typedef ssize_t * not have to be completed yet). A transition to * #MHD_REQUEST_CLOSED or #MHD_REQUEST_INIT requires the write * to be complete. - */ + */ enum MHD_REQUEST_STATE // FIXME: fix capitalization! { /** @@ -317,11 +317,6 @@ enum MHD_REQUEST_STATE // FIXME: fix capitalization! */ MHD_REQUEST_CLOSED = MHD_REQUEST_FOOTERS_SENT + 1, - /** - * 20: This request is finished (only to be freed) - */ - MHD_REQUEST_IN_CLEANUP = MHD_REQUEST_CLOSED + 1, - #ifdef UPGRADE_SUPPORT /** * Request was "upgraded" and socket is now under the @@ -369,7 +364,7 @@ struct MHD_Request { /** - * Reference to the `struct MHD_Daemon`. + * Reference to the `struct MHD_Daemon`. */ struct MHD_Daemon *daemon; @@ -383,7 +378,7 @@ struct MHD_Request * it is available. */ struct MHD_Response *response; - + /** * Linked list of parsed headers. */ @@ -554,7 +549,7 @@ struct MHD_Request * HTTP method, as an enum. */ enum MHD_Method method; - + /** * What is this request waiting for? */ @@ -633,7 +628,7 @@ enum MHD_EpollState /** * State kept per HTTP connection. - */ + */ struct MHD_Connection { @@ -687,7 +682,7 @@ struct MHD_Connection * address (which persists across individual requests). */ struct MemoryPool *pool; - + /** * We allow the main application to associate some pointer with the * TCP connection (which may span multiple HTTP requests). Here is @@ -703,7 +698,7 @@ struct MHD_Connection */ struct MHD_TLS_ConnectionState *tls_cs; #endif - + /** * Function used for reading HTTP request stream. */ @@ -727,7 +722,7 @@ struct MHD_Connection MHD_thread_handle_ID_ pid; /** - * Foreign address (of length @e addr_len). + * Foreign address (of length @e addr_len). */ struct sockaddr_storage addr; @@ -794,7 +789,7 @@ struct MHD_Connection * from this socket). */ bool read_closed; - + }; @@ -1013,7 +1008,7 @@ struct MHD_Daemon */ void *rc_cls; - /** + /** * Function to call for logging. */ MHD_LoggingCallback logger; @@ -1021,7 +1016,7 @@ struct MHD_Daemon /** * Closure for @e logger. */ - void *logger_cls; + void *logger_cls; /** * Function to call to accept/reject connections based on @@ -1076,7 +1071,7 @@ struct MHD_Daemon */ struct MHD_Daemon *worker_pool; - + #if HTTPS_SUPPORT #ifdef UPGRADE_SUPPORT /** @@ -1098,7 +1093,7 @@ struct MHD_Daemon * Which TLS backend should be used. NULL for no TLS. * This is merely the handle to the dlsym() object, not * the API. - */ + */ void *tls_backend_lib; /** @@ -1152,7 +1147,7 @@ struct MHD_Daemon * Not used in MHD_USE_THREAD_PER_CONNECTION mode. */ struct MHD_Connection *manual_timeout_tail; - + /** * Head of doubly-linked list of our current, active connections. */ @@ -1251,8 +1246,8 @@ struct MHD_Daemon * The select thread handle (if we have internal select) */ MHD_thread_handle_ID_ pid; - - /** + + /** * Socket address to bind to for the listen socket. */ struct sockaddr_storage listen_sa; @@ -1267,8 +1262,8 @@ struct MHD_Daemon * "manual_timeout" DLLs. */ MHD_mutex_ cleanup_connection_mutex; - - /** + + /** * Number of (valid) bytes in @e listen_sa. Zero * if @e listen_sa is not initialized. */ @@ -1277,7 +1272,7 @@ struct MHD_Daemon /** * Default size of the per-connection memory pool. */ -#define POOL_SIZE_DEFAULT (32 * 1024) +#define POOL_SIZE_DEFAULT (32 * 1024) /** * Buffer size to use for each connection. Default * is #POOL_SIZE_DEFAULT. @@ -1292,7 +1287,7 @@ struct MHD_Daemon * space). */ #define BUF_INC_SIZE_DEFAULT 1024 - + /** * Increment to use when growing the read buffer. Smaller * than @e connection_memory_limit_b. @@ -1306,7 +1301,7 @@ struct MHD_Daemon size_t thread_stack_limit_b; #if ENABLE_DAUTH - + /** * Size of @e digest_auth_random_buf. */ @@ -1316,14 +1311,14 @@ struct MHD_Daemon * Default value for @e digest_nc_length. */ #define DIGEST_NC_LENGTH_DEFAULT 4 - + /** * Desired length of the internal array with the nonce and * nonce counters for digest authentication. */ size_t digest_nc_length; #endif - + /** * Default value we use for the listen backlog. */ @@ -1332,13 +1327,13 @@ struct MHD_Daemon #else /* !SOMAXCONN */ #define LISTEN_BACKLOG_DEFAULT 511 #endif - + /** - * Backlog argument to use for listen. See + * Backlog argument to use for listen. See * #MHD_daemon_listen_backlog(). */ int listen_backlog; - + /** * Default queue length to use with fast open. */ @@ -1373,8 +1368,8 @@ struct MHD_Daemon * Default timeout in seconds for idle connections. */ time_t connection_default_timeout; - - /** + + /** * Listen socket we should use, MHD_INVALID_SOCKET means * we are to initialize the socket from the other options given. */ @@ -1407,23 +1402,23 @@ struct MHD_Daemon #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ #endif - + /** * Inter-thread communication channel. */ struct MHD_itc_ itc; - + /** * Which threading model do we use? Postive * numbers indicate the number of worker threads to be used. * Values larger than 1 imply a thread pool. */ enum MHD_ThreadingModel threading_model; - + /** - * When should we use TCP_FASTOPEN? + * When should we use TCP_FASTOPEN? * See #MHD_daemon_tcp_fastopen(). - */ + */ enum MHD_FastOpenMethod fast_open_method; /** @@ -1445,36 +1440,36 @@ struct MHD_Daemon */ enum MHD_ProtocolStrictLevel protocol_strict_level; - /** + /** * On which port should we listen on? Only effective if we were not * given a listen socket or a full address via * #MHD_daemon_bind_sa(). 0 means to bind to random free port. */ uint16_t listen_port; - + /** * Suppress generating the "Date:" header, this system * lacks an RTC (or developer is hyper-optimizing). See * #MHD_daemon_suppress_date_no_clock(). - */ + */ bool suppress_date; /** * The use of the inter-thread communication channel is disabled. * See #MHD_daemon_disable_itc(). - */ + */ bool disable_itc; /** * Disable #MHD_action_suspend() functionality. See * #MHD_daemon_disallow_suspend_resume(). - */ + */ bool disallow_suspend_resume; /** * Disable #MHD_action_upgrade() functionality. See * #MHD_daemon_disallow_upgrade(). - */ + */ bool disallow_upgrade; /** @@ -1523,12 +1518,12 @@ struct MHD_Daemon * MHD should speak SHOUTcast instead of HTTP. */ bool enable_shoutcast; - + /** * Are we shutting down? */ volatile bool shutdown; - + }; @@ -1559,9 +1554,9 @@ struct MHD_Action /** * Closure for @a action - */ + */ void *action_cls; - + }; @@ -1577,7 +1572,7 @@ struct MHD_Response * must be the first field in a response! */ struct MHD_Action action; - + /** * Headers to send for the response. Initially * the linked list is created in inverse order; @@ -1610,7 +1605,7 @@ struct MHD_Response MHD_ContentReaderFreeCallback crfc; /** - * Function to call once MHD is finished with + * Function to call once MHD is finished with * the request, may be NULL. */ MHD_RequestTerminationCallback termination_cb; @@ -1619,7 +1614,7 @@ struct MHD_Response * Closure for @e termination_cb. */ void *termination_cb_cls; - + #ifdef UPGRADE_SUPPORT /** * Application function to call once we are done sending the headers @@ -1671,7 +1666,7 @@ struct MHD_Response * HTTP status code of the response. */ enum MHD_HTTP_StatusCode status_code; - + /** * Reference count for this response. Free once the counter hits * zero. @@ -1692,7 +1687,7 @@ struct MHD_Response * Use ShoutCAST format. */ bool icy; - + }; diff --git a/src/lib/request_info.c b/src/lib/request_info.c @@ -48,7 +48,7 @@ MHD_request_get_information_sz (struct MHD_Request *request, { #define CHECK_SIZE(type) if (sizeof(type) < return_value_size) \ return MHD_NO - + switch (info_type) { case MHD_REQUEST_INFORMATION_CONNECTION: @@ -70,8 +70,7 @@ MHD_request_get_information_sz (struct MHD_Request *request, case MHD_REQUEST_INFORMATION_HEADER_SIZE: CHECK_SIZE (size_t); if ( (MHD_REQUEST_HEADERS_RECEIVED > request->state) || - (MHD_REQUEST_CLOSED == request->state) || - (MHD_REQUEST_IN_CLEANUP == request->state) ) + (MHD_REQUEST_CLOSED == request->state) ) return MHD_NO; /* invalid, too early! */ return_value->header_size = request->header_size; return MHD_YES; @@ -79,7 +78,7 @@ MHD_request_get_information_sz (struct MHD_Request *request, default: return MHD_NO; } - + #undef CHECK_SIZE } diff --git a/src/lib/request_resume.c b/src/lib/request_resume.c @@ -159,8 +159,6 @@ MHD_resume_suspended_connections_ (struct MHD_Daemon *daemon) /* Data forwarding was finished (for TLS connections) AND * application was closed upgraded connection. * Insert connection into cleanup list. */ - MHD_connection_close_ (pos, - MHD_CONNECTION_NOTIFY_CLOSED); DLL_insert (daemon->cleanup_head, daemon->cleanup_tail, pos); diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -1948,9 +1948,6 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection) case MHD_CONNECTION_CLOSED: connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; return; /* do nothing, not even reading */ - case MHD_CONNECTION_IN_CLEANUP: - mhd_assert (0); - break; #ifdef UPGRADE_SUPPORT case MHD_CONNECTION_UPGRADE: mhd_assert (0); @@ -3151,9 +3148,6 @@ MHD_connection_handle_write (struct MHD_Connection *connection) return; case MHD_CONNECTION_CLOSED: return; - case MHD_CONNECTION_IN_CLEANUP: - mhd_assert (0); - return; #ifdef UPGRADE_SUPPORT case MHD_CONNECTION_UPGRADE: mhd_assert (0); @@ -3857,8 +3851,7 @@ MHD_get_connection_info (struct MHD_Connection *connection, return (const union MHD_ConnectionInfo *) &connection->connection_timeout_dummy; case MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE: if ( (MHD_CONNECTION_HEADERS_RECEIVED > connection->state) || - (MHD_CONNECTION_CLOSED == connection->state) || - (MHD_CONNECTION_IN_CLEANUP == connection->state) ) + (MHD_CONNECTION_CLOSED == connection->state) ) return NULL; /* invalid, too early! */ return (const union MHD_ConnectionInfo *) &connection->header_size; default: diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -2066,21 +2066,18 @@ thread_main_handle_connection (void *data) } #endif /* UPGRADE_SUPPORT */ } - if (MHD_CONNECTION_IN_CLEANUP != con->state) - { #if DEBUG_CLOSE #ifdef HAVE_MESSAGES - MHD_DLOG (con->daemon, - _("Processing thread terminating. Closing connection\n")); + MHD_DLOG (con->daemon, + _("Processing thread terminating. Closing connection\n")); #endif #endif - if (MHD_CONNECTION_CLOSED != con->state) - MHD_connection_close_ (con, - (daemon->shutdown) ? - MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: - MHD_REQUEST_TERMINATED_WITH_ERROR); - MHD_connection_handle_idle (con); - } + if (MHD_CONNECTION_CLOSED != con->state) + MHD_connection_close_ (con, + (daemon->shutdown) ? + MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: + MHD_REQUEST_TERMINATED_WITH_ERROR); + MHD_connection_handle_idle (con); exit: if (NULL != con->response) { @@ -2790,8 +2787,6 @@ resume_suspended_connections (struct MHD_Daemon *daemon) /* Data forwarding was finished (for TLS connections) AND * application was closed upgraded connection. * Insert connection into cleanup list. */ - MHD_connection_close_ (pos, - MHD_REQUEST_TERMINATED_COMPLETED_OK); DLL_insert (daemon->cleanup_head, daemon->cleanup_tail, pos); diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -507,11 +507,6 @@ enum MHD_CONNECTION_STATE */ MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1, - /** - * 20: This connection is finished (only to be freed) - */ - MHD_CONNECTION_IN_CLEANUP = MHD_CONNECTION_CLOSED + 1, - #ifdef UPGRADE_SUPPORT /** * Connection was "upgraded" and socket is now under the