diff options
Diffstat (limited to 'src/testcurl/test_quiesce.c')
-rw-r--r-- | src/testcurl/test_quiesce.c | 510 |
1 files changed, 265 insertions, 245 deletions
diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c index 69b07618..c42880ce 100644 --- a/src/testcurl/test_quiesce.c +++ b/src/testcurl/test_quiesce.c | |||
@@ -40,10 +40,10 @@ | |||
40 | #include <sys/socket.h> | 40 | #include <sys/socket.h> |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 43 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
44 | #undef CPU_COUNT | 44 | #undef CPU_COUNT |
45 | #endif | 45 | #endif |
46 | #if !defined(CPU_COUNT) | 46 | #if ! defined(CPU_COUNT) |
47 | #define CPU_COUNT 2 | 47 | #define CPU_COUNT 2 |
48 | #endif | 48 | #endif |
49 | 49 | ||
@@ -83,19 +83,19 @@ ahc_echo (void *cls, | |||
83 | const char *me = cls; | 83 | const char *me = cls; |
84 | struct MHD_Response *response; | 84 | struct MHD_Response *response; |
85 | int ret; | 85 | int ret; |
86 | (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 86 | (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
87 | 87 | ||
88 | if (0 != strcmp (me, method)) | 88 | if (0 != strcmp (me, method)) |
89 | return MHD_NO; /* unexpected method */ | 89 | return MHD_NO; /* unexpected method */ |
90 | if (&ptr != *unused) | 90 | if (&ptr != *unused) |
91 | { | 91 | { |
92 | *unused = &ptr; | 92 | *unused = &ptr; |
93 | return MHD_YES; | 93 | return MHD_YES; |
94 | } | 94 | } |
95 | *unused = NULL; | 95 | *unused = NULL; |
96 | response = MHD_create_response_from_buffer (strlen (url), | 96 | response = MHD_create_response_from_buffer (strlen (url), |
97 | (void *) url, | 97 | (void *) url, |
98 | MHD_RESPMEM_MUST_COPY); | 98 | MHD_RESPMEM_MUST_COPY); |
99 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 99 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
100 | MHD_destroy_response (response); | 100 | MHD_destroy_response (response); |
101 | if (ret == MHD_NO) | 101 | if (ret == MHD_NO) |
@@ -106,16 +106,16 @@ ahc_echo (void *cls, | |||
106 | 106 | ||
107 | static void | 107 | static void |
108 | request_completed (void *cls, struct MHD_Connection *connection, | 108 | request_completed (void *cls, struct MHD_Connection *connection, |
109 | void **con_cls, enum MHD_RequestTerminationCode code) | 109 | void **con_cls, enum MHD_RequestTerminationCode code) |
110 | { | 110 | { |
111 | (void)connection;(void)con_cls;(void)code; /* Unused. Silent compiler warning. */ | 111 | (void) connection; (void) con_cls; (void) code; /* Unused. Silent compiler warning. */ |
112 | int *done = (int *)cls; | 112 | int *done = (int *) cls; |
113 | *done = 1; | 113 | *done = 1; |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | static void * | 117 | static void * |
118 | ServeOneRequest(void *param) | 118 | ServeOneRequest (void *param) |
119 | { | 119 | { |
120 | struct MHD_Daemon *d; | 120 | struct MHD_Daemon *d; |
121 | fd_set rs; | 121 | fd_set rs; |
@@ -138,38 +138,40 @@ ServeOneRequest(void *param) | |||
138 | 138 | ||
139 | start = time (NULL); | 139 | start = time (NULL); |
140 | while ((time (NULL) - start < 5) && done == 0) | 140 | while ((time (NULL) - start < 5) && done == 0) |
141 | { | ||
142 | max = 0; | ||
143 | FD_ZERO (&rs); | ||
144 | FD_ZERO (&ws); | ||
145 | FD_ZERO (&es); | ||
146 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
147 | { | ||
148 | MHD_stop_daemon (d); | ||
149 | MHD_socket_close_chk_ (fd); | ||
150 | return "MHD_get_fdset() failed"; | ||
151 | } | ||
152 | tv.tv_sec = 0; | ||
153 | tv.tv_usec = 1000; | ||
154 | if (-1 == MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv)) | ||
141 | { | 155 | { |
142 | max = 0; | ||
143 | FD_ZERO (&rs); | ||
144 | FD_ZERO (&ws); | ||
145 | FD_ZERO (&es); | ||
146 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
147 | { | ||
148 | MHD_stop_daemon (d); | ||
149 | MHD_socket_close_chk_(fd); | ||
150 | return "MHD_get_fdset() failed"; | ||
151 | } | ||
152 | tv.tv_sec = 0; | ||
153 | tv.tv_usec = 1000; | ||
154 | if (-1 == MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv)) | ||
155 | { | ||
156 | #ifdef MHD_POSIX_SOCKETS | 156 | #ifdef MHD_POSIX_SOCKETS |
157 | if (EINTR != errno) | 157 | if (EINTR != errno) |
158 | abort (); | 158 | abort (); |
159 | #else | 159 | #else |
160 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 160 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
161 | abort (); | 161 | ws.fd_count) |
162 | Sleep (1000); | 162 | ||(0 != es.fd_count) ) |
163 | abort (); | ||
164 | Sleep (1000); | ||
163 | #endif | 165 | #endif |
164 | } | ||
165 | MHD_run (d); | ||
166 | } | 166 | } |
167 | MHD_run (d); | ||
168 | } | ||
167 | fd = MHD_quiesce_daemon (d); | 169 | fd = MHD_quiesce_daemon (d); |
168 | if (MHD_INVALID_SOCKET == fd) | 170 | if (MHD_INVALID_SOCKET == fd) |
169 | { | 171 | { |
170 | MHD_stop_daemon (d); | 172 | MHD_stop_daemon (d); |
171 | return "MHD_quiesce_daemon() failed in ServeOneRequest()"; | 173 | return "MHD_quiesce_daemon() failed in ServeOneRequest()"; |
172 | } | 174 | } |
173 | MHD_stop_daemon (d); | 175 | MHD_stop_daemon (d); |
174 | return done ? NULL : "Requests was not served by ServeOneRequest()"; | 176 | return done ? NULL : "Requests was not served by ServeOneRequest()"; |
175 | } | 177 | } |
@@ -182,7 +184,7 @@ setupCURL (void *cbc) | |||
182 | 184 | ||
183 | c = curl_easy_init (); | 185 | c = curl_easy_init (); |
184 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 186 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
185 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 187 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
186 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 188 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
187 | curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc); | 189 | curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc); |
188 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 190 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -218,44 +220,51 @@ testGet (int type, int pool_count, int poll_flag) | |||
218 | cbc.buf = buf; | 220 | cbc.buf = buf; |
219 | cbc.size = 2048; | 221 | cbc.size = 2048; |
220 | cbc.pos = 0; | 222 | cbc.pos = 0; |
221 | if (pool_count > 0) { | 223 | if (pool_count > 0) |
224 | { | ||
222 | d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, | 225 | d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, |
223 | port, NULL, NULL, &ahc_echo, "GET", | 226 | port, NULL, NULL, &ahc_echo, "GET", |
224 | MHD_OPTION_THREAD_POOL_SIZE, pool_count, MHD_OPTION_END); | 227 | MHD_OPTION_THREAD_POOL_SIZE, pool_count, |
228 | MHD_OPTION_END); | ||
225 | 229 | ||
226 | } else { | 230 | } |
231 | else { | ||
227 | d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, | 232 | d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, |
228 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 233 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
229 | } | 234 | } |
230 | if (d == NULL) | 235 | if (d == NULL) |
231 | return 1; | 236 | return 1; |
232 | if (0 == port) | 237 | if (0 == port) |
238 | { | ||
239 | const union MHD_DaemonInfo *dinfo; | ||
240 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
241 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
233 | { | 242 | { |
234 | const union MHD_DaemonInfo *dinfo; | 243 | MHD_stop_daemon (d); return 32; |
235 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
236 | if (NULL == dinfo || 0 == dinfo->port) | ||
237 | { MHD_stop_daemon (d); return 32; } | ||
238 | port = (int)dinfo->port; | ||
239 | } | 244 | } |
245 | port = (int) dinfo->port; | ||
246 | } | ||
240 | 247 | ||
241 | c = setupCURL(&cbc); | 248 | c = setupCURL (&cbc); |
242 | 249 | ||
243 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 250 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
244 | { | 251 | { |
245 | fprintf (stderr, | 252 | fprintf (stderr, |
246 | "curl_easy_perform failed: `%s'\n", | 253 | "curl_easy_perform failed: `%s'\n", |
247 | curl_easy_strerror (errornum)); | 254 | curl_easy_strerror (errornum)); |
248 | curl_easy_cleanup (c); | 255 | curl_easy_cleanup (c); |
249 | MHD_stop_daemon (d); | 256 | MHD_stop_daemon (d); |
250 | return 2; | 257 | return 2; |
251 | } | 258 | } |
252 | 259 | ||
253 | if (cbc.pos != strlen ("/hello_world")) { | 260 | if (cbc.pos != strlen ("/hello_world")) |
261 | { | ||
254 | curl_easy_cleanup (c); | 262 | curl_easy_cleanup (c); |
255 | MHD_stop_daemon (d); | 263 | MHD_stop_daemon (d); |
256 | return 4; | 264 | return 4; |
257 | } | 265 | } |
258 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) { | 266 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
267 | { | ||
259 | curl_easy_cleanup (c); | 268 | curl_easy_cleanup (c); |
260 | MHD_stop_daemon (d); | 269 | MHD_stop_daemon (d); |
261 | return 8; | 270 | return 8; |
@@ -263,78 +272,79 @@ testGet (int type, int pool_count, int poll_flag) | |||
263 | 272 | ||
264 | fd = MHD_quiesce_daemon (d); | 273 | fd = MHD_quiesce_daemon (d); |
265 | if (MHD_INVALID_SOCKET == fd) | 274 | if (MHD_INVALID_SOCKET == fd) |
266 | { | 275 | { |
267 | fprintf (stderr, | 276 | fprintf (stderr, |
268 | "MHD_quiesce_daemon failed.\n"); | 277 | "MHD_quiesce_daemon failed.\n"); |
269 | curl_easy_cleanup (c); | 278 | curl_easy_cleanup (c); |
270 | MHD_stop_daemon (d); | 279 | MHD_stop_daemon (d); |
271 | return 2; | 280 | return 2; |
272 | } | 281 | } |
273 | if (0 != pthread_create(&thrd, NULL, &ServeOneRequest, (void*)(intptr_t) fd)) | 282 | if (0 != pthread_create (&thrd, NULL, &ServeOneRequest, |
274 | { | 283 | (void*) (intptr_t) fd)) |
275 | fprintf (stderr, "pthread_create failed\n"); | 284 | { |
276 | curl_easy_cleanup (c); | 285 | fprintf (stderr, "pthread_create failed\n"); |
277 | MHD_stop_daemon (d); | 286 | curl_easy_cleanup (c); |
278 | return 16; | 287 | MHD_stop_daemon (d); |
279 | } | 288 | return 16; |
289 | } | ||
280 | 290 | ||
281 | cbc.pos = 0; | 291 | cbc.pos = 0; |
282 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 292 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
283 | { | 293 | { |
284 | fprintf (stderr, | 294 | fprintf (stderr, |
285 | "curl_easy_perform failed: `%s'\n", | 295 | "curl_easy_perform failed: `%s'\n", |
286 | curl_easy_strerror (errornum)); | 296 | curl_easy_strerror (errornum)); |
287 | curl_easy_cleanup (c); | 297 | curl_easy_cleanup (c); |
288 | MHD_stop_daemon (d); | 298 | MHD_stop_daemon (d); |
289 | return 2; | 299 | return 2; |
290 | } | 300 | } |
291 | 301 | ||
292 | if (0 != pthread_join(thrd, (void**)&thrdRet)) | 302 | if (0 != pthread_join (thrd, (void**) &thrdRet)) |
293 | { | 303 | { |
294 | fprintf (stderr, "pthread_join failed\n"); | 304 | fprintf (stderr, "pthread_join failed\n"); |
295 | curl_easy_cleanup (c); | 305 | curl_easy_cleanup (c); |
296 | MHD_stop_daemon (d); | 306 | MHD_stop_daemon (d); |
297 | return 16; | 307 | return 16; |
298 | } | 308 | } |
299 | if (NULL != thrdRet) | 309 | if (NULL != thrdRet) |
300 | { | 310 | { |
301 | fprintf (stderr, "ServeOneRequest() error: %s\n", thrdRet); | 311 | fprintf (stderr, "ServeOneRequest() error: %s\n", thrdRet); |
302 | curl_easy_cleanup (c); | 312 | curl_easy_cleanup (c); |
303 | MHD_stop_daemon (d); | 313 | MHD_stop_daemon (d); |
304 | return 16; | 314 | return 16; |
305 | } | 315 | } |
306 | 316 | ||
307 | if (cbc.pos != strlen ("/hello_world")) | 317 | if (cbc.pos != strlen ("/hello_world")) |
308 | { | 318 | { |
309 | fprintf(stderr, "%s\n", cbc.buf); | 319 | fprintf (stderr, "%s\n", cbc.buf); |
310 | curl_easy_cleanup (c); | 320 | curl_easy_cleanup (c); |
311 | MHD_stop_daemon (d); | 321 | MHD_stop_daemon (d); |
312 | MHD_socket_close_chk_(fd); | 322 | MHD_socket_close_chk_ (fd); |
313 | return 4; | 323 | return 4; |
314 | } | 324 | } |
315 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 325 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
316 | { | 326 | { |
317 | fprintf(stderr, "%s\n", cbc.buf); | 327 | fprintf (stderr, "%s\n", cbc.buf); |
318 | curl_easy_cleanup (c); | 328 | curl_easy_cleanup (c); |
319 | MHD_stop_daemon (d); | 329 | MHD_stop_daemon (d); |
320 | MHD_socket_close_chk_(fd); | 330 | MHD_socket_close_chk_ (fd); |
321 | return 8; | 331 | return 8; |
322 | } | 332 | } |
323 | 333 | ||
324 | /* at this point, the forked server quit, and the new | 334 | /* at this point, the forked server quit, and the new |
325 | * server has quiesced, so new requests should fail | 335 | * server has quiesced, so new requests should fail |
326 | */ | 336 | */ |
327 | if (CURLE_OK == (errornum = curl_easy_perform (c))) | 337 | if (CURLE_OK == (errornum = curl_easy_perform (c))) |
328 | { | 338 | { |
329 | fprintf (stderr, "curl_easy_perform should fail\n"); | 339 | fprintf (stderr, "curl_easy_perform should fail\n"); |
330 | curl_easy_cleanup (c); | 340 | curl_easy_cleanup (c); |
331 | MHD_stop_daemon (d); | 341 | MHD_stop_daemon (d); |
332 | MHD_socket_close_chk_(fd); | 342 | MHD_socket_close_chk_ (fd); |
333 | return 2; | 343 | return 2; |
334 | } | 344 | } |
335 | curl_easy_cleanup (c); | 345 | curl_easy_cleanup (c); |
336 | MHD_stop_daemon (d); | 346 | MHD_stop_daemon (d); |
337 | MHD_socket_close_chk_(fd); | 347 | MHD_socket_close_chk_ (fd); |
338 | 348 | ||
339 | return 0; | 349 | return 0; |
340 | } | 350 | } |
@@ -382,136 +392,141 @@ testExternalGet () | |||
382 | if (d == NULL) | 392 | if (d == NULL) |
383 | return 256; | 393 | return 256; |
384 | if (0 == port) | 394 | if (0 == port) |
395 | { | ||
396 | const union MHD_DaemonInfo *dinfo; | ||
397 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
398 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
385 | { | 399 | { |
386 | const union MHD_DaemonInfo *dinfo; | 400 | MHD_stop_daemon (d); return 32; |
387 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
388 | if (NULL == dinfo || 0 == dinfo->port) | ||
389 | { MHD_stop_daemon (d); return 32; } | ||
390 | port = (int)dinfo->port; | ||
391 | } | 401 | } |
392 | c = setupCURL(&cbc); | 402 | port = (int) dinfo->port; |
403 | } | ||
404 | c = setupCURL (&cbc); | ||
393 | 405 | ||
394 | multi = curl_multi_init (); | 406 | multi = curl_multi_init (); |
395 | if (multi == NULL) | 407 | if (multi == NULL) |
396 | { | 408 | { |
397 | curl_easy_cleanup (c); | 409 | curl_easy_cleanup (c); |
398 | MHD_stop_daemon (d); | 410 | MHD_stop_daemon (d); |
399 | return 512; | 411 | return 512; |
400 | } | 412 | } |
401 | mret = curl_multi_add_handle (multi, c); | 413 | mret = curl_multi_add_handle (multi, c); |
402 | if (mret != CURLM_OK) | 414 | if (mret != CURLM_OK) |
403 | { | 415 | { |
404 | curl_multi_cleanup (multi); | 416 | curl_multi_cleanup (multi); |
405 | curl_easy_cleanup (c); | 417 | curl_easy_cleanup (c); |
406 | MHD_stop_daemon (d); | 418 | MHD_stop_daemon (d); |
407 | return 1024; | 419 | return 1024; |
408 | } | 420 | } |
409 | 421 | ||
410 | for (i = 0; i < 2; i++) | 422 | for (i = 0; i < 2; i++) |
423 | { | ||
424 | start = time (NULL); | ||
425 | while ( (time (NULL) - start < 5) && | ||
426 | (NULL != multi) ) | ||
411 | { | 427 | { |
412 | start = time (NULL); | 428 | maxsock = MHD_INVALID_SOCKET; |
413 | while ( (time (NULL) - start < 5) && | 429 | maxposixs = -1; |
414 | (NULL != multi) ) | 430 | FD_ZERO (&rs); |
415 | { | 431 | FD_ZERO (&ws); |
416 | maxsock = MHD_INVALID_SOCKET; | 432 | FD_ZERO (&es); |
417 | maxposixs = -1; | 433 | curl_multi_perform (multi, &running); |
418 | FD_ZERO (&rs); | 434 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); |
419 | FD_ZERO (&ws); | 435 | if (mret != CURLM_OK) |
420 | FD_ZERO (&es); | 436 | { |
421 | curl_multi_perform (multi, &running); | 437 | curl_multi_remove_handle (multi, c); |
422 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | 438 | curl_multi_cleanup (multi); |
423 | if (mret != CURLM_OK) | 439 | curl_easy_cleanup (c); |
424 | { | 440 | MHD_stop_daemon (d); |
425 | curl_multi_remove_handle (multi, c); | 441 | return 2048; |
426 | curl_multi_cleanup (multi); | 442 | } |
427 | curl_easy_cleanup (c); | 443 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
428 | MHD_stop_daemon (d); | 444 | { |
429 | return 2048; | 445 | curl_multi_remove_handle (multi, c); |
430 | } | 446 | curl_multi_cleanup (multi); |
431 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | 447 | curl_easy_cleanup (c); |
432 | { | 448 | MHD_stop_daemon (d); |
433 | curl_multi_remove_handle (multi, c); | 449 | return 4096; |
434 | curl_multi_cleanup (multi); | 450 | } |
435 | curl_easy_cleanup (c); | 451 | tv.tv_sec = 0; |
436 | MHD_stop_daemon (d); | 452 | tv.tv_usec = 1000; |
437 | return 4096; | 453 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) |
438 | } | 454 | { |
439 | tv.tv_sec = 0; | ||
440 | tv.tv_usec = 1000; | ||
441 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
442 | { | ||
443 | #ifdef MHD_POSIX_SOCKETS | 455 | #ifdef MHD_POSIX_SOCKETS |
444 | if (EINTR != errno) | 456 | if (EINTR != errno) |
445 | abort (); | 457 | abort (); |
446 | #else | 458 | #else |
447 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 459 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
448 | abort (); | 460 | ws. |
449 | Sleep (1000); | 461 | fd_count) |
462 | ||(0 != es.fd_count) ) | ||
463 | abort (); | ||
464 | Sleep (1000); | ||
450 | #endif | 465 | #endif |
451 | } | 466 | } |
452 | curl_multi_perform (multi, &running); | 467 | curl_multi_perform (multi, &running); |
453 | if (0 == running) | 468 | if (0 == running) |
454 | { | 469 | { |
455 | msg = curl_multi_info_read (multi, &running); | 470 | msg = curl_multi_info_read (multi, &running); |
456 | if (NULL == msg) | 471 | if (NULL == msg) |
457 | break; | 472 | break; |
458 | if (msg->msg == CURLMSG_DONE) | 473 | if (msg->msg == CURLMSG_DONE) |
459 | { | ||
460 | if (i == 0 && msg->data.result != CURLE_OK) | ||
461 | printf ("%s failed at %s:%d: `%s'\n", | ||
462 | "curl_multi_perform", | ||
463 | __FILE__, | ||
464 | __LINE__, | ||
465 | curl_easy_strerror (msg->data.result)); | ||
466 | else if ( (i == 1) && | ||
467 | (msg->data.result == CURLE_OK) ) | ||
468 | printf ("%s should have failed at %s:%d\n", | ||
469 | "curl_multi_perform", | ||
470 | __FILE__, | ||
471 | __LINE__); | ||
472 | curl_multi_remove_handle (multi, c); | ||
473 | curl_multi_cleanup (multi); | ||
474 | curl_easy_cleanup (c); | ||
475 | c = NULL; | ||
476 | multi = NULL; | ||
477 | } | ||
478 | } | ||
479 | MHD_run (d); | ||
480 | } | ||
481 | |||
482 | if (0 == i) | ||
483 | { | 474 | { |
484 | /* quiesce the daemon on the 1st iteration, so the 2nd should fail */ | 475 | if ((i == 0) &&(msg->data.result != CURLE_OK) ) |
485 | fd = MHD_quiesce_daemon(d); | 476 | printf ("%s failed at %s:%d: `%s'\n", |
486 | if (MHD_INVALID_SOCKET == fd) | 477 | "curl_multi_perform", |
487 | { | 478 | __FILE__, |
488 | fprintf (stderr, | 479 | __LINE__, |
489 | "MHD_quiesce_daemon failed.\n"); | 480 | curl_easy_strerror (msg->data.result)); |
490 | curl_multi_remove_handle (multi, c); | 481 | else if ( (i == 1) && |
491 | curl_multi_cleanup (multi); | 482 | (msg->data.result == CURLE_OK) ) |
492 | curl_easy_cleanup (c); | 483 | printf ("%s should have failed at %s:%d\n", |
493 | MHD_stop_daemon (d); | 484 | "curl_multi_perform", |
494 | return 2; | 485 | __FILE__, |
495 | } | 486 | __LINE__); |
496 | c = setupCURL (&cbc); | 487 | curl_multi_remove_handle (multi, c); |
497 | multi = curl_multi_init (); | 488 | curl_multi_cleanup (multi); |
498 | mret = curl_multi_add_handle (multi, c); | 489 | curl_easy_cleanup (c); |
499 | if (mret != CURLM_OK) | 490 | c = NULL; |
500 | { | 491 | multi = NULL; |
501 | curl_multi_remove_handle (multi, c); | ||
502 | curl_multi_cleanup (multi); | ||
503 | curl_easy_cleanup (c); | ||
504 | MHD_stop_daemon (d); | ||
505 | return 32768; | ||
506 | } | ||
507 | } | 492 | } |
493 | } | ||
494 | MHD_run (d); | ||
508 | } | 495 | } |
509 | if (NULL != multi) | 496 | |
497 | if (0 == i) | ||
510 | { | 498 | { |
511 | curl_multi_remove_handle (multi, c); | 499 | /* quiesce the daemon on the 1st iteration, so the 2nd should fail */ |
512 | curl_easy_cleanup (c); | 500 | fd = MHD_quiesce_daemon (d); |
513 | curl_multi_cleanup (multi); | 501 | if (MHD_INVALID_SOCKET == fd) |
502 | { | ||
503 | fprintf (stderr, | ||
504 | "MHD_quiesce_daemon failed.\n"); | ||
505 | curl_multi_remove_handle (multi, c); | ||
506 | curl_multi_cleanup (multi); | ||
507 | curl_easy_cleanup (c); | ||
508 | MHD_stop_daemon (d); | ||
509 | return 2; | ||
510 | } | ||
511 | c = setupCURL (&cbc); | ||
512 | multi = curl_multi_init (); | ||
513 | mret = curl_multi_add_handle (multi, c); | ||
514 | if (mret != CURLM_OK) | ||
515 | { | ||
516 | curl_multi_remove_handle (multi, c); | ||
517 | curl_multi_cleanup (multi); | ||
518 | curl_easy_cleanup (c); | ||
519 | MHD_stop_daemon (d); | ||
520 | return 32768; | ||
521 | } | ||
514 | } | 522 | } |
523 | } | ||
524 | if (NULL != multi) | ||
525 | { | ||
526 | curl_multi_remove_handle (multi, c); | ||
527 | curl_easy_cleanup (c); | ||
528 | curl_multi_cleanup (multi); | ||
529 | } | ||
515 | MHD_stop_daemon (d); | 530 | MHD_stop_daemon (d); |
516 | MHD_socket_close_chk_ (fd); | 531 | MHD_socket_close_chk_ (fd); |
517 | if (cbc.pos != strlen ("/hello_world")) | 532 | if (cbc.pos != strlen ("/hello_world")) |
@@ -526,32 +541,37 @@ int | |||
526 | main (int argc, char *const *argv) | 541 | main (int argc, char *const *argv) |
527 | { | 542 | { |
528 | unsigned int errorCount = 0; | 543 | unsigned int errorCount = 0; |
529 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 544 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
530 | 545 | ||
531 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 546 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
532 | return 2; | 547 | return 2; |
533 | errorCount += testExternalGet (); | 548 | errorCount += testExternalGet (); |
534 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 549 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
550 | { | ||
551 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); | ||
552 | errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION | ||
553 | | MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); | ||
554 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, 0); | ||
555 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL)) | ||
535 | { | 556 | { |
536 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); | 557 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_POLL); |
537 | errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); | 558 | errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION |
538 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, 0); | 559 | | MHD_USE_INTERNAL_POLLING_THREAD, 0, |
539 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL)) | 560 | MHD_USE_POLL); |
540 | { | 561 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, |
541 | errorCount += testGet(MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_POLL); | 562 | MHD_USE_POLL); |
542 | errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_POLL); | ||
543 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, MHD_USE_POLL); | ||
544 | } | ||
545 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL)) | ||
546 | { | ||
547 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_EPOLL); | ||
548 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, MHD_USE_EPOLL); | ||
549 | } | ||
550 | } | 563 | } |
564 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL)) | ||
565 | { | ||
566 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_EPOLL); | ||
567 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, | ||
568 | MHD_USE_EPOLL); | ||
569 | } | ||
570 | } | ||
551 | if (0 != errorCount) | 571 | if (0 != errorCount) |
552 | fprintf (stderr, | 572 | fprintf (stderr, |
553 | "Error (code: %u)\n", | 573 | "Error (code: %u)\n", |
554 | errorCount); | 574 | errorCount); |
555 | curl_global_cleanup (); | 575 | curl_global_cleanup (); |
556 | return errorCount != 0; /* 0 == pass */ | 576 | return errorCount != 0; /* 0 == pass */ |
557 | } | 577 | } |