diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-14 17:08:40 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-14 17:08:40 +0100 |
commit | 8a84902f7447edd6f677dfa9983c16146dacc7c5 (patch) | |
tree | 17369fe20b3a53b62dd7bdad73a219b61f8edeb0 /src/microhttpd | |
parent | 73e423312cc7a32f5a260ec7992ed5a15abd4858 (diff) | |
download | libmicrohttpd-8a84902f7447edd6f677dfa9983c16146dacc7c5.tar.gz libmicrohttpd-8a84902f7447edd6f677dfa9983c16146dacc7c5.zip |
mark 'was_closed' as volatile; move connection resumption to end of upgrade routine to avoid race issue; eliminate dead code
Diffstat (limited to 'src/microhttpd')
-rw-r--r-- | src/microhttpd/daemon.c | 27 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 2 | ||||
-rw-r--r-- | src/microhttpd/response.c | 14 |
3 files changed, 8 insertions, 35 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 97fcc813..fda7f51b 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -5696,33 +5696,6 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
5696 | } | 5696 | } |
5697 | 5697 | ||
5698 | 5698 | ||
5699 | #ifdef EPOLL_SUPPORT | ||
5700 | /** | ||
5701 | * Shutdown epoll()-event loop by adding write end of 'itc' to its event set. | ||
5702 | * | ||
5703 | * @param daemon daemon of which the epoll() instance must be signalled | ||
5704 | */ | ||
5705 | static void | ||
5706 | epoll_shutdown (struct MHD_Daemon *daemon) | ||
5707 | { | ||
5708 | struct epoll_event event; | ||
5709 | |||
5710 | if (MHD_ITC_IS_INVALID_(daemon->itc)) | ||
5711 | { | ||
5712 | /* itc was required in this mode, how could this happen? */ | ||
5713 | MHD_PANIC (_("Internal error\n")); | ||
5714 | } | ||
5715 | event.events = EPOLLOUT; | ||
5716 | event.data.ptr = NULL; | ||
5717 | if (0 != epoll_ctl (daemon->epoll_fd, | ||
5718 | EPOLL_CTL_ADD, | ||
5719 | MHD_itc_w_fd_ (daemon->itc), | ||
5720 | &event)) | ||
5721 | MHD_PANIC (_("Failed to add inter-thread communication channel FD to epoll set to signal termination\n")); | ||
5722 | } | ||
5723 | #endif | ||
5724 | |||
5725 | |||
5726 | /** | 5699 | /** |
5727 | * Shutdown an HTTP daemon. | 5700 | * Shutdown an HTTP daemon. |
5728 | * | 5701 | * |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 8b15db97..5acc21d9 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -1104,7 +1104,7 @@ struct MHD_UpgradeResponseHandle | |||
1104 | * connection to cleanup list. | 1104 | * connection to cleanup list. |
1105 | * @remark This flag could be changed from any thread. | 1105 | * @remark This flag could be changed from any thread. |
1106 | */ | 1106 | */ |
1107 | bool was_closed; | 1107 | volatile bool was_closed; |
1108 | 1108 | ||
1109 | /** | 1109 | /** |
1110 | * Set to #MHD_YES if connection is ready for cleanup. | 1110 | * Set to #MHD_YES if connection is ready for cleanup. |
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index 4ea251d3..d9055416 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -667,13 +667,6 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, | |||
667 | return MHD_NO; /* Already closed. */ | 667 | return MHD_NO; /* Already closed. */ |
668 | 668 | ||
669 | /* transition to special 'closed' state for start of cleanup */ | 669 | /* transition to special 'closed' state for start of cleanup */ |
670 | urh->was_closed = true; | ||
671 | EXTRA_CHECK (MHD_CONNECTION_UPGRADE == connection->state); | ||
672 | connection->state = MHD_CONNECTION_UPGRADE_CLOSED; | ||
673 | /* As soon as connection will be marked with BOTH | ||
674 | * 'urh->was_closed' AND 'urh->clean_ready', it will | ||
675 | * be moved to cleanup list by MHD_resume_connection(). */ | ||
676 | MHD_resume_connection (connection); | ||
677 | #ifdef HTTPS_SUPPORT | 670 | #ifdef HTTPS_SUPPORT |
678 | if (0 != (daemon->options & MHD_USE_TLS) ) | 671 | if (0 != (daemon->options & MHD_USE_TLS) ) |
679 | { | 672 | { |
@@ -683,6 +676,13 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, | |||
683 | SHUT_RDWR); | 676 | SHUT_RDWR); |
684 | } | 677 | } |
685 | #endif /* HTTPS_SUPPORT */ | 678 | #endif /* HTTPS_SUPPORT */ |
679 | urh->was_closed = true; | ||
680 | EXTRA_CHECK (MHD_CONNECTION_UPGRADE == connection->state); | ||
681 | connection->state = MHD_CONNECTION_UPGRADE_CLOSED; | ||
682 | /* As soon as connection will be marked with BOTH | ||
683 | * 'urh->was_closed' AND 'urh->clean_ready', it will | ||
684 | * be moved to cleanup list by MHD_resume_connection(). */ | ||
685 | MHD_resume_connection (connection); | ||
686 | return MHD_YES; | 686 | return MHD_YES; |
687 | default: | 687 | default: |
688 | /* we don't understand this one */ | 688 | /* we don't understand this one */ |