diff options
-rw-r--r-- | src/daemon/daemon.c | 13 | ||||
-rw-r--r-- | src/daemon/daemontest.c | 13 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 490317ea..58e2e058 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -319,17 +319,22 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) { | |||
319 | /** | 319 | /** |
320 | * Main select call. | 320 | * Main select call. |
321 | * | 321 | * |
322 | * @param may_block YES if blocking, NO if non-blocking | ||
322 | * @return MHD_NO on serious errors, MHD_YES on success | 323 | * @return MHD_NO on serious errors, MHD_YES on success |
323 | */ | 324 | */ |
324 | static int | 325 | static int |
325 | MHD_select(struct MHD_Daemon * daemon) { | 326 | MHD_select(struct MHD_Daemon * daemon, |
327 | int may_block) { | ||
326 | struct MHD_Session * pos; | 328 | struct MHD_Session * pos; |
327 | int num_ready; | 329 | int num_ready; |
328 | fd_set rs; | 330 | fd_set rs; |
329 | fd_set ws; | 331 | fd_set ws; |
330 | fd_set es; | 332 | fd_set es; |
331 | int max; | 333 | int max; |
334 | struct timeval timeout; | ||
332 | 335 | ||
336 | timeout.tv_sec = 0; | ||
337 | timeout.tv_usec = 0; | ||
333 | if(daemon == NULL) | 338 | if(daemon == NULL) |
334 | abort(); | 339 | abort(); |
335 | FD_ZERO(&rs); | 340 | FD_ZERO(&rs); |
@@ -354,7 +359,7 @@ MHD_select(struct MHD_Daemon * daemon) { | |||
354 | &rs, | 359 | &rs, |
355 | &ws, | 360 | &ws, |
356 | &es, | 361 | &es, |
357 | NULL); | 362 | may_block == MHD_NO ? &timeout : NULL); |
358 | if (num_ready < 0) { | 363 | if (num_ready < 0) { |
359 | if (errno == EINTR) | 364 | if (errno == EINTR) |
360 | return MHD_YES; | 365 | return MHD_YES; |
@@ -397,7 +402,7 @@ MHD_run(struct MHD_Daemon * daemon) { | |||
397 | (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || | 402 | (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || |
398 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) | 403 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) |
399 | return MHD_NO; | 404 | return MHD_NO; |
400 | MHD_select(daemon); | 405 | MHD_select(daemon, MHD_NO); |
401 | MHD_cleanup_sessions(daemon); | 406 | MHD_cleanup_sessions(daemon); |
402 | return MHD_YES; | 407 | return MHD_YES; |
403 | } | 408 | } |
@@ -411,7 +416,7 @@ static void * | |||
411 | MHD_select_thread(void * cls) { | 416 | MHD_select_thread(void * cls) { |
412 | struct MHD_Daemon * daemon = cls; | 417 | struct MHD_Daemon * daemon = cls; |
413 | while (daemon->shutdown == 0) { | 418 | while (daemon->shutdown == 0) { |
414 | MHD_select(daemon); | 419 | MHD_select(daemon, MHD_YES); |
415 | MHD_cleanup_sessions(daemon); | 420 | MHD_cleanup_sessions(daemon); |
416 | } | 421 | } |
417 | return NULL; | 422 | return NULL; |
diff --git a/src/daemon/daemontest.c b/src/daemon/daemontest.c index 38aadbea..3fccce9d 100644 --- a/src/daemon/daemontest.c +++ b/src/daemon/daemontest.c | |||
@@ -78,7 +78,7 @@ static int testStartStop() { | |||
78 | 78 | ||
79 | static int testExternalRun() { | 79 | static int testExternalRun() { |
80 | struct MHD_Daemon * d; | 80 | struct MHD_Daemon * d; |
81 | fd_set read; | 81 | fd_set rs; |
82 | int maxfd; | 82 | int maxfd; |
83 | int i; | 83 | int i; |
84 | 84 | ||
@@ -93,13 +93,16 @@ static int testExternalRun() { | |||
93 | return 4; | 93 | return 4; |
94 | i = 0; | 94 | i = 0; |
95 | while(i < 15) { | 95 | while(i < 15) { |
96 | MHD_get_fdset(d, &read, &read, &read, &maxfd); | 96 | maxfd = 0; |
97 | FD_ZERO(&rs); | ||
98 | MHD_get_fdset(d, &rs, &rs, &rs, &maxfd); | ||
97 | if (MHD_run(d) == MHD_NO) { | 99 | if (MHD_run(d) == MHD_NO) { |
98 | MHD_stop_daemon(d); | 100 | MHD_stop_daemon(d); |
99 | return 8; | 101 | return 8; |
100 | } | 102 | } |
101 | i++; | 103 | i++; |
102 | } | 104 | } |
105 | MHD_stop_daemon(d); | ||
103 | return 0; | 106 | return 0; |
104 | } | 107 | } |
105 | 108 | ||
@@ -114,7 +117,7 @@ static int testThread() { | |||
114 | 117 | ||
115 | if (d == NULL) | 118 | if (d == NULL) |
116 | return 16; | 119 | return 16; |
117 | if (MHD_run(d) == MHD_NO) | 120 | if (MHD_run(d) != MHD_NO) |
118 | return 32; | 121 | return 32; |
119 | MHD_stop_daemon(d); | 122 | MHD_stop_daemon(d); |
120 | return 0; | 123 | return 0; |
@@ -131,8 +134,8 @@ static int testMultithread() { | |||
131 | 134 | ||
132 | if (d == NULL) | 135 | if (d == NULL) |
133 | return 64; | 136 | return 64; |
134 | if (MHD_run(d) == MHD_NO) | 137 | if (MHD_run(d) != MHD_NO) |
135 | return 128; | 138 | return 128; |
136 | MHD_stop_daemon(d); | 139 | MHD_stop_daemon(d); |
137 | return 0; | 140 | return 0; |
138 | } | 141 | } |