libmicrohttpd

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

commit 8a84902f7447edd6f677dfa9983c16146dacc7c5
parent 73e423312cc7a32f5a260ec7992ed5a15abd4858
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 14 Feb 2017 17:08:40 +0100

mark 'was_closed' as volatile; move connection resumption to end of upgrade routine to avoid race issue; eliminate dead code

Diffstat:
Msrc/microhttpd/daemon.c | 27---------------------------
Msrc/microhttpd/internal.h | 2+-
Msrc/microhttpd/response.c | 14+++++++-------
3 files changed, 8 insertions(+), 35 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -5696,33 +5696,6 @@ close_all_connections (struct MHD_Daemon *daemon) } -#ifdef EPOLL_SUPPORT -/** - * Shutdown epoll()-event loop by adding write end of 'itc' to its event set. - * - * @param daemon daemon of which the epoll() instance must be signalled - */ -static void -epoll_shutdown (struct MHD_Daemon *daemon) -{ - struct epoll_event event; - - if (MHD_ITC_IS_INVALID_(daemon->itc)) - { - /* itc was required in this mode, how could this happen? */ - MHD_PANIC (_("Internal error\n")); - } - event.events = EPOLLOUT; - event.data.ptr = NULL; - if (0 != epoll_ctl (daemon->epoll_fd, - EPOLL_CTL_ADD, - MHD_itc_w_fd_ (daemon->itc), - &event)) - MHD_PANIC (_("Failed to add inter-thread communication channel FD to epoll set to signal termination\n")); -} -#endif - - /** * Shutdown an HTTP daemon. * diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -1104,7 +1104,7 @@ struct MHD_UpgradeResponseHandle * connection to cleanup list. * @remark This flag could be changed from any thread. */ - bool was_closed; + volatile bool was_closed; /** * Set to #MHD_YES if connection is ready for cleanup. diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -667,13 +667,6 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, return MHD_NO; /* Already closed. */ /* transition to special 'closed' state for start of cleanup */ - urh->was_closed = true; - EXTRA_CHECK (MHD_CONNECTION_UPGRADE == connection->state); - connection->state = MHD_CONNECTION_UPGRADE_CLOSED; - /* As soon as connection will be marked with BOTH - * 'urh->was_closed' AND 'urh->clean_ready', it will - * be moved to cleanup list by MHD_resume_connection(). */ - MHD_resume_connection (connection); #ifdef HTTPS_SUPPORT if (0 != (daemon->options & MHD_USE_TLS) ) { @@ -683,6 +676,13 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, SHUT_RDWR); } #endif /* HTTPS_SUPPORT */ + urh->was_closed = true; + EXTRA_CHECK (MHD_CONNECTION_UPGRADE == connection->state); + connection->state = MHD_CONNECTION_UPGRADE_CLOSED; + /* As soon as connection will be marked with BOTH + * 'urh->was_closed' AND 'urh->clean_ready', it will + * be moved to cleanup list by MHD_resume_connection(). */ + MHD_resume_connection (connection); return MHD_YES; default: /* we don't understand this one */