libmicrohttpd

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

commit 764c0fd56b56da8aa1a2c6cec51dd46d3b7055c7
parent ecd561acd954650eca77c3bd93ff70b90e92dc6a
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu, 18 Aug 2011 09:08:53 +0000

bugfix

Diffstat:
MAUTHORS | 1+
MChangeLog | 5+++++
Msrc/daemon/connection.c | 6++++--
Msrc/testcurl/test_callback.c | 66++++++++++++++++++++++++++++++++++++------------------------------
4 files changed, 46 insertions(+), 32 deletions(-)

diff --git a/AUTHORS b/AUTHORS @@ -32,6 +32,7 @@ Andreas Wehrmann <a.wehrmann@centersystems.com> Eivind Sarto <ivan@espial.com> Thomas Stalder <gnunet@netsolux.ch> Zhimin Huang <zhimin.huang@bqvision.com> +Jan Seeger <jan.seeger@thenybble.de> Documentation contributions also came from: Marco Maggi <marco.maggi-ipsu@poste.it> diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,8 @@ +Thu Aug 18 11:05:16 CEST 2011 + Fixed bug with wrong state transition if callback returned + MHD_CONTENT_READER_END_OF_STREAM causing spurious extra callbacks + to the handler (thanks to Jan Seeger for pointing it out). -CG/JS + Thu Aug 11 11:40:03 CEST 2011 Changing sockets to be non-blocking as suggested by Eivind Sarto on the mailinglist. -CG diff --git a/src/daemon/connection.c b/src/daemon/connection.c @@ -390,7 +390,10 @@ try_ready_normal_body (struct MHD_Connection *connection) response->data_start = connection->response_write_position; response->data_size = ret; if (ret == 0) - return MHD_NO; + { + connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; + return MHD_NO; + } return MHD_YES; } @@ -1847,7 +1850,6 @@ MHD_connection_handle_write (struct MHD_Connection *connection) { if (response->crc != NULL) pthread_mutex_unlock (&response->mutex); - connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; break; } ret = connection->send_cls (connection, diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c @@ -97,7 +97,7 @@ int main(int argc, char **argv) struct timeval tv; int extra; - d = MHD_start_daemon(MHD_USE_DEBUG, + d = MHD_start_daemon(0, 8000, NULL, NULL, @@ -135,15 +135,18 @@ int main(int argc, char **argv) FD_ZERO(&rs); FD_ZERO(&es); curl_multi_perform (multi, &running); - mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); - if (mret != CURLM_OK) - { - curl_multi_remove_handle (multi, c); - curl_multi_cleanup (multi); - curl_easy_cleanup (c); - MHD_stop_daemon (d); - return 3; - } + if (NULL != multi) + { + mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); + if (mret != CURLM_OK) + { + curl_multi_remove_handle (multi, c); + curl_multi_cleanup (multi); + curl_easy_cleanup (c); + MHD_stop_daemon (d); + return 3; + } + } if (MHD_YES != MHD_get_fdset(d, &rs, &ws, &es, &max)) { @@ -156,26 +159,29 @@ int main(int argc, char **argv) tv.tv_sec = 0; tv.tv_usec = 1000; select(max + 1, &rs, &ws, &es, &tv); - curl_multi_perform (multi, &running); - if (running == 0) - { - msg = curl_multi_info_read (multi, &running); - if (msg == NULL) - break; - if (msg->msg == CURLMSG_DONE) - { - if (msg->data.result != CURLE_OK) - printf ("%s failed at %s:%d: `%s'\n", - "curl_multi_perform", - __FILE__, - __LINE__, curl_easy_strerror (msg->data.result)); - curl_multi_remove_handle (multi, c); - curl_multi_cleanup (multi); - curl_easy_cleanup (c); - c = NULL; - multi = NULL; - } - } + if (NULL != multi) + { + curl_multi_perform (multi, &running); + if (running == 0) + { + msg = curl_multi_info_read (multi, &running); + if (msg == NULL) + break; + if (msg->msg == CURLMSG_DONE) + { + if (msg->data.result != CURLE_OK) + printf ("%s failed at %s:%d: `%s'\n", + "curl_multi_perform", + __FILE__, + __LINE__, curl_easy_strerror (msg->data.result)); + curl_multi_remove_handle (multi, c); + curl_multi_cleanup (multi); + curl_easy_cleanup (c); + c = NULL; + multi = NULL; + } + } + } MHD_run(d); } MHD_stop_daemon(d);