aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-18 16:34:17 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-18 16:34:17 +0000
commite22f196d71f9e28095bbc99c3504e8d1d4a1456c (patch)
tree169d830680e6f2d480b6e19162179a73eac2338b
parent1fb16b78538b1e20733b03a9bf6ae02c2adb2cbb (diff)
downloadlibmicrohttpd-e22f196d71f9e28095bbc99c3504e8d1d4a1456c.tar.gz
libmicrohttpd-e22f196d71f9e28095bbc99c3504e8d1d4a1456c.zip
release lock earlier
-rw-r--r--ChangeLog6
-rw-r--r--src/microhttpd/connection.c20
2 files changed, 15 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 296f0d20..eb446b10 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,11 @@
1Wed Sep 18 18:29:24 CEST 2013 1Wed Sep 18 18:29:24 CEST 2013
2 Signal connection termination as OK (and not as ERROR) if the 2 Signal connection termination as OK (and not as ERROR) if the
3 stream was terminated by the callback returning 3 stream was terminated by the callback returning
4 MHD_CONTENT_READER_END_OF_STREAM. -CG 4 MHD_CONTENT_READER_END_OF_STREAM. Also, release response
5 mutex before calling the termination callback, to avoid
6 possible deadlock if the client destroys the response in
7 the termination callback (due to non-recursiveness of the
8 lock). -CG
5 9
6Wed Sep 18 14:31:35 CEST 2013 10Wed Sep 18 14:31:35 CEST 2013
7 Adding #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN. -CG 11 Adding #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN. -CG
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 1a75eb28..7157d6d1 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -317,7 +317,9 @@ connection_close_error (struct MHD_Connection *connection,
317 * #MHD_NO). 317 * #MHD_NO).
318 * 318 *
319 * @param connection the connection 319 * @param connection the connection
320 * @return #MHD_NO if readying the response failed 320 * @return #MHD_NO if readying the response failed (the
321 * lock on the response will have been released already
322 * in this case).
321 */ 323 */
322static int 324static int
323try_ready_normal_body (struct MHD_Connection *connection) 325try_ready_normal_body (struct MHD_Connection *connection)
@@ -364,8 +366,10 @@ try_ready_normal_body (struct MHD_Connection *connection)
364 { 366 {
365 /* either error or http 1.0 transfer, close socket! */ 367 /* either error or http 1.0 transfer, close socket! */
366 response->total_size = connection->response_write_position; 368 response->total_size = connection->response_write_position;
369 if (NULL != response->crc)
370 pthread_mutex_unlock (&response->mutex);
367 if (MHD_CONTENT_READER_END_OF_STREAM == ret) 371 if (MHD_CONTENT_READER_END_OF_STREAM == ret)
368 MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETD_OK); 372 MHD_connection_close (connection, MHD_REQUEST_TERMINATED_COMPLETED_OK);
369 else 373 else
370 CONNECTION_CLOSE_ERROR (connection, 374 CONNECTION_CLOSE_ERROR (connection,
371 "Closing connection (stream error)\n"); 375 "Closing connection (stream error)\n");
@@ -376,6 +380,8 @@ try_ready_normal_body (struct MHD_Connection *connection)
376 if (0 == ret) 380 if (0 == ret)
377 { 381 {
378 connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; 382 connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY;
383 if (NULL != response->crc)
384 pthread_mutex_unlock (&response->mutex);
379 return MHD_NO; 385 return MHD_NO;
380 } 386 }
381 return MHD_YES; 387 return MHD_YES;
@@ -1978,12 +1984,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1978 response = connection->response; 1984 response = connection->response;
1979 if (response->crc != NULL) 1985 if (response->crc != NULL)
1980 pthread_mutex_lock (&response->mutex); 1986 pthread_mutex_lock (&response->mutex);
1981 if (MHD_YES != try_ready_normal_body (connection)) 1987 if (MHD_YES != try_ready_normal_body (connection))
1982 { 1988 break;
1983 if (response->crc != NULL)
1984 pthread_mutex_unlock (&response->mutex);
1985 break;
1986 }
1987 ret = connection->send_cls (connection, 1989 ret = connection->send_cls (connection,
1988 &response->data 1990 &response->data
1989 [connection->response_write_position 1991 [connection->response_write_position
@@ -2351,8 +2353,6 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2351 } 2353 }
2352 if (MHD_YES == try_ready_normal_body (connection)) 2354 if (MHD_YES == try_ready_normal_body (connection))
2353 { 2355 {
2354 if (connection->response->crc != NULL)
2355 pthread_mutex_unlock (&connection->response->mutex);
2356 connection->state = MHD_CONNECTION_NORMAL_BODY_READY; 2356 connection->state = MHD_CONNECTION_NORMAL_BODY_READY;
2357 break; 2357 break;
2358 } 2358 }