libmicrohttpd

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

commit b25731eb2555aed201955633bd57d810b70b5001
parent 6f3759be399e9a6cb32f83c82db2a0f45b42b8fe
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun,  4 Sep 2016 11:25:48 +0000

-extend upgrade plaintext test to cover thread-per-connection mode, plus minor bugfix

Diffstat:
Msrc/microhttpd/connection.c | 1+
Msrc/microhttpd/mhd_sem.c | 8++++----
Msrc/microhttpd/response.c | 14+++++++-------
Msrc/microhttpd/test_upgrade.c | 14++++++++++----
4 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -3185,6 +3185,7 @@ MHD_queue_response (struct MHD_Connection *connection, return MHD_NO; } if ( (NULL != response->upgrade_handler) && + (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && (0 == (daemon->options & MHD_USE_SUSPEND_RESUME)) ) { #ifdef HAVE_MESSAGES diff --git a/src/microhttpd/mhd_sem.c b/src/microhttpd/mhd_sem.c @@ -88,7 +88,7 @@ MHD_semaphore_create (unsigned int init) void MHD_semaphore_down (struct MHD_Semaphore *sem) { - if (! pthread_mutex_lock (&sem->mutex)) + if (0 != pthread_mutex_lock (&sem->mutex)) MHD_PANIC ("pthread_mutex_lock for semaphore failed\n"); while (0 == sem->counter) { @@ -97,7 +97,7 @@ MHD_semaphore_down (struct MHD_Semaphore *sem) MHD_PANIC ("pthread_cond_wait failed\n"); } sem->counter--; - if (! pthread_mutex_unlock (&sem->mutex)) + if (0 != pthread_mutex_unlock (&sem->mutex)) MHD_PANIC ("pthread_mutex_unlock for semaphore failed\n"); } @@ -110,11 +110,11 @@ MHD_semaphore_down (struct MHD_Semaphore *sem) void MHD_semaphore_up (struct MHD_Semaphore *sem) { - if (! pthread_mutex_lock (&sem->mutex)) + if (0 != pthread_mutex_lock (&sem->mutex)) MHD_PANIC ("pthread_mutex_lock for semaphore failed\n"); sem->counter++; pthread_cond_signal (&sem->cv); - if (! pthread_mutex_unlock (&sem->mutex)) + if (0 != pthread_mutex_unlock (&sem->mutex)) MHD_PANIC ("pthread_mutex_unlock for semaphore failed\n"); } diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -867,13 +867,6 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, urh->app.socket = MHD_INVALID_SOCKET; urh->mhd.socket = MHD_INVALID_SOCKET; #endif - response->upgrade_handler (response->upgrade_handler_cls, - connection, - connection->client_context, - connection->read_buffer, - rbo, - connection->socket_fd, - urh); if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) { /* Need to give the thread something to block on... */ @@ -899,6 +892,13 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, #MHD_upgrade_action() function */ MHD_suspend_connection (connection); } + response->upgrade_handler (response->upgrade_handler_cls, + connection, + connection->client_context, + connection->read_buffer, + rbo, + connection->socket_fd, + urh); return MHD_YES; } diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c @@ -286,7 +286,9 @@ test_upgrade_internal (int flags, MHD_socket sock; struct sockaddr_in sa; - d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_USE_SUSPEND_RESUME, + if (0 == (flags & MHD_USE_THREAD_PER_CONNECTION)) + flags |= MHD_USE_SUSPEND_RESUME; + d = MHD_start_daemon (flags | MHD_USE_DEBUG, 1080, NULL, NULL, &ahc_upgrade, NULL, @@ -325,19 +327,23 @@ main (int argc, { int error_count = 0; + error_count += test_upgrade_internal (MHD_USE_THREAD_PER_CONNECTION, + 0); + error_count += test_upgrade_internal (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_POLL, + 0); error_count += test_upgrade_internal (MHD_USE_SELECT_INTERNALLY, - 1); + 0); error_count += test_upgrade_internal (MHD_USE_SELECT_INTERNALLY, 2); #ifdef HAVE_POLL error_count += test_upgrade_internal (MHD_USE_POLL_INTERNALLY, - 1); + 0); error_count += test_upgrade_internal (MHD_USE_POLL_INTERNALLY, 2); #endif #ifdef EPOLL_SUPPORT error_count += test_upgrade_internal (MHD_USE_EPOLL_INTERNALLY, - 1); + 0); error_count += test_upgrade_internal (MHD_USE_EPOLL_INTERNALLY, 2); #endif