From 4b6e4c630dc6027ee5046d3c558864d94c6758c7 Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Wed, 15 Mar 2017 18:15:02 +0300 Subject: upgraded connections: removed redundant states and checks and unified processing logic. Fixed early close in TLS thread-per-connection mode. --- src/microhttpd/connection.c | 6 ------ src/microhttpd/daemon.c | 24 +++++++----------------- src/microhttpd/internal.h | 7 ------- src/microhttpd/response.c | 3 +-- 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index f192a1bb..7380c662 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c @@ -2446,8 +2446,6 @@ MHD_connection_handle_read (struct MHD_Connection *connection) case MHD_CONNECTION_UPGRADE: EXTRA_CHECK (0); break; - case MHD_CONNECTION_UPGRADE_CLOSED: - break; #endif /* UPGRADE_SUPPORT */ default: /* shrink read buffer to how much is actually used */ @@ -2635,8 +2633,6 @@ MHD_connection_handle_write (struct MHD_Connection *connection) case MHD_CONNECTION_UPGRADE: EXTRA_CHECK (0); break; - case MHD_CONNECTION_UPGRADE_CLOSED: - break; #endif /* UPGRADE_SUPPORT */ default: EXTRA_CHECK (0); @@ -3202,8 +3198,6 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) #ifdef UPGRADE_SUPPORT case MHD_CONNECTION_UPGRADE: return MHD_YES; /* keep open */ - case MHD_CONNECTION_UPGRADE_CLOSED: - return MHD_YES; /* "Upgraded" connection should be closed in special way. */ #endif /* UPGRADE_SUPPORT */ default: EXTRA_CHECK (0); diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 6f0fe9f2..84d9afe3 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c @@ -1620,7 +1620,9 @@ thread_main_connection_upgrade (struct MHD_Connection *con) if ( (0 != (daemon->options & MHD_USE_TLS)) && (0 == (daemon->options & MHD_USE_POLL))) { - while ( (MHD_CONNECTION_UPGRADE == con->state) || + while ( (0 != urh->in_buffer_size) || + (0 != urh->out_buffer_size) || + (0 != urh->in_buffer_used) || (0 != urh->out_buffer_used) ) { /* use select */ @@ -1690,11 +1692,6 @@ thread_main_connection_upgrade (struct MHD_Connection *con) &ws, &es); process_urh (urh); - if ( (0 == urh->in_buffer_size) && - (0 == urh->out_buffer_size) && - (0 == urh->in_buffer_used) && - (0 == urh->out_buffer_used) ) - break; /* connections died, we have no more purpose here */ } } #ifdef HAVE_POLL @@ -1708,7 +1705,9 @@ thread_main_connection_upgrade (struct MHD_Connection *con) p[0].fd = urh->connection->socket_fd; p[1].fd = urh->mhd.socket; - while ( (MHD_CONNECTION_UPGRADE == con->state) || + while ( (0 != urh->in_buffer_size) || + (0 != urh->out_buffer_size) || + (0 != urh->in_buffer_used) || (0 != urh->out_buffer_used) ) { int timeout; @@ -1738,11 +1737,6 @@ thread_main_connection_upgrade (struct MHD_Connection *con) } urh_from_pollfd(urh, p); process_urh (urh); - if ( (0 == urh->in_buffer_size) && - (0 == urh->out_buffer_size) && - (0 == urh->in_buffer_used) && - (0 == urh->out_buffer_used) ) - break; /* connections died, we have no more purpose here */ } } /* end POLL */ @@ -2070,11 +2064,7 @@ thread_main_handle_connection (void *data) } #endif #ifdef UPGRADE_SUPPORT - /* Check for 'MHD_CONNECTION_UPGRADE_CLOSED' too: - * application can finish with "upgraded" connection - * before this thread process it for the first time. */ - if ( (MHD_CONNECTION_UPGRADE == con->state) || - (MHD_CONNECTION_UPGRADE_CLOSED == con->state) ) + if (MHD_CONNECTION_UPGRADE == con->state) { /* Normal HTTP processing is finished, * notify application. */ diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 62c60a31..f9172372 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h @@ -514,13 +514,6 @@ enum MHD_CONNECTION_STATE * control of the application. */ MHD_CONNECTION_UPGRADE = MHD_TLS_CONNECTION_INIT + 1, - - /** - * Connection was "upgraded" and subsequently closed - * by the application. We now need to do our own - * internal cleanup. - */ - MHD_CONNECTION_UPGRADE_CLOSED = MHD_CONNECTION_UPGRADE + 1 #endif /* UPGRADE_SUPPORT */ }; diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index 26ad649b..9004013f 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c @@ -678,9 +678,8 @@ 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; + urh->was_closed = true; /* 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(). */ -- cgit v1.2.3