libmicrohttpd

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

commit b6a83f00076a84e9322323031734cadf2930e159
parent 53918b01dc591cc732312088712c54ef86386bbe
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 13 Jun 2007 22:16:26 +0000

fix

Diffstat:
Msrc/daemon/daemon.c | 13+++++++++----
Msrc/daemon/daemontest.c | 13++++++++-----
2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -319,17 +319,22 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) { /** * Main select call. * + * @param may_block YES if blocking, NO if non-blocking * @return MHD_NO on serious errors, MHD_YES on success */ static int -MHD_select(struct MHD_Daemon * daemon) { +MHD_select(struct MHD_Daemon * daemon, + int may_block) { struct MHD_Session * pos; int num_ready; fd_set rs; fd_set ws; fd_set es; int max; + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 0; if(daemon == NULL) abort(); FD_ZERO(&rs); @@ -354,7 +359,7 @@ MHD_select(struct MHD_Daemon * daemon) { &rs, &ws, &es, - NULL); + may_block == MHD_NO ? &timeout : NULL); if (num_ready < 0) { if (errno == EINTR) return MHD_YES; @@ -397,7 +402,7 @@ MHD_run(struct MHD_Daemon * daemon) { (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) return MHD_NO; - MHD_select(daemon); + MHD_select(daemon, MHD_NO); MHD_cleanup_sessions(daemon); return MHD_YES; } @@ -411,7 +416,7 @@ static void * MHD_select_thread(void * cls) { struct MHD_Daemon * daemon = cls; while (daemon->shutdown == 0) { - MHD_select(daemon); + MHD_select(daemon, MHD_YES); MHD_cleanup_sessions(daemon); } return NULL; diff --git a/src/daemon/daemontest.c b/src/daemon/daemontest.c @@ -78,7 +78,7 @@ static int testStartStop() { static int testExternalRun() { struct MHD_Daemon * d; - fd_set read; + fd_set rs; int maxfd; int i; @@ -93,13 +93,16 @@ static int testExternalRun() { return 4; i = 0; while(i < 15) { - MHD_get_fdset(d, &read, &read, &read, &maxfd); + maxfd = 0; + FD_ZERO(&rs); + MHD_get_fdset(d, &rs, &rs, &rs, &maxfd); if (MHD_run(d) == MHD_NO) { MHD_stop_daemon(d); return 8; } i++; } + MHD_stop_daemon(d); return 0; } @@ -114,7 +117,7 @@ static int testThread() { if (d == NULL) return 16; - if (MHD_run(d) == MHD_NO) + if (MHD_run(d) != MHD_NO) return 32; MHD_stop_daemon(d); return 0; @@ -131,8 +134,8 @@ static int testMultithread() { if (d == NULL) return 64; - if (MHD_run(d) == MHD_NO) - return 128; + if (MHD_run(d) != MHD_NO) + return 128; MHD_stop_daemon(d); return 0; }