commit 86cbb04673c55de61af47bed92ecf101e48ffe06
parent 95f6ae86c11407e8b25501aacb22813555753a2d
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 21 Jun 2014 22:22:55 +0000
lock when modifying response object to add missing headers
Diffstat:
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Jun 22 00:22:08 CEST 2014
+ Lock on response if adding headers, needed if response
+ object is shared across threads and connections. -CG
+
Thu Jun 19 17:32:32 CEST 2014
Ensure that listen FD is bound to epoll FD even before
MHD_run() is called if running with MHD_USE_EPOLL_LINUX_ONLY
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -2466,13 +2466,16 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
continue;
if (NULL == connection->response)
break; /* try again next time */
+ (void) MHD_mutex_lock_ (&connection->response->mutex);
if (MHD_NO == build_header_response (connection))
{
/* oops - close! */
+ (void) MHD_mutex_unlock_ (&connection->response->mutex);
CONNECTION_CLOSE_ERROR (connection,
"Closing connection (failed to create response header)\n");
continue;
}
+ (void) MHD_mutex_unlock_ (&connection->response->mutex);
connection->state = MHD_CONNECTION_HEADERS_SENDING;
#if HAVE_DECL_TCP_CORK
@@ -2539,7 +2542,16 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
(void) MHD_mutex_unlock_ (&connection->response->mutex);
break;
case MHD_CONNECTION_BODY_SENT:
- build_header_response (connection);
+ (void) MHD_mutex_lock_ (&connection->response->mutex);
+ if (MHD_NO == build_header_response (connection))
+ {
+ /* oops - close! */
+ (void) MHD_mutex_unlock_ (&connection->response->mutex);
+ CONNECTION_CLOSE_ERROR (connection,
+ "Closing connection (failed to create response header)\n");
+ continue;
+ }
+ (void) MHD_mutex_unlock_ (&connection->response->mutex);
if ( (MHD_NO == connection->have_chunked_upload) ||
(connection->write_buffer_send_offset ==
connection->write_buffer_append_offset) )