aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_get_chunked.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_get_chunked.c')
-rw-r--r--src/testcurl/test_get_chunked.c289
1 files changed, 150 insertions, 139 deletions
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c
index c7be5c83..9916a902 100644
--- a/src/testcurl/test_get_chunked.c
+++ b/src/testcurl/test_get_chunked.c
@@ -40,10 +40,10 @@
40#include <unistd.h> 40#include <unistd.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
@@ -120,19 +120,19 @@ ahc_echo (void *cls,
120 struct MHD_Response **responseptr; 120 struct MHD_Response **responseptr;
121 int ret; 121 int ret;
122 122
123 (void)url; 123 (void) url;
124 (void)version; /* Unused. Silent compiler warning. */ 124 (void) version; /* Unused. Silent compiler warning. */
125 (void)upload_data; 125 (void) upload_data;
126 (void)upload_data_size; /* Unused. Silent compiler warning. */ 126 (void) upload_data_size; /* Unused. Silent compiler warning. */
127 127
128 if (0 != strcmp (me, method)) 128 if (0 != strcmp (me, method))
129 return MHD_NO; /* unexpected method */ 129 return MHD_NO; /* unexpected method */
130 if (&aptr != *ptr) 130 if (&aptr != *ptr)
131 { 131 {
132 /* do never respond on first call */ 132 /* do never respond on first call */
133 *ptr = &aptr; 133 *ptr = &aptr;
134 return MHD_YES; 134 return MHD_YES;
135 } 135 }
136 responseptr = malloc (sizeof (struct MHD_Response *)); 136 responseptr = malloc (sizeof (struct MHD_Response *));
137 if (NULL == responseptr) 137 if (NULL == responseptr)
138 return MHD_NO; 138 return MHD_NO;
@@ -165,16 +165,16 @@ validate (struct CBC cbc, int ebase)
165 return ebase; 165 return ebase;
166 166
167 for (i = 0; i < 10; i++) 167 for (i = 0; i < 10; i++)
168 {
169 memset (buf, 'A' + i, 128);
170 if (0 != memcmp (buf, &cbc.buf[i * 128], 128))
168 { 171 {
169 memset (buf, 'A' + i, 128); 172 fprintf (stderr,
170 if (0 != memcmp (buf, &cbc.buf[i * 128], 128)) 173 "Got `%.*s'\nWant `%.*s'\n",
171 { 174 128, buf, 128, &cbc.buf[i * 128]);
172 fprintf (stderr, 175 return ebase * 2;
173 "Got `%.*s'\nWant `%.*s'\n",
174 128, buf, 128, &cbc.buf[i * 128]);
175 return ebase * 2;
176 }
177 } 176 }
177 }
178 return 0; 178 return 0;
179} 179}
180 180
@@ -201,16 +201,18 @@ testInternalGet ()
201 if (d == NULL) 201 if (d == NULL)
202 return 1; 202 return 1;
203 if (0 == port) 203 if (0 == port)
204 {
205 const union MHD_DaemonInfo *dinfo;
206 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
207 if ((NULL == dinfo) ||(0 == dinfo->port) )
204 { 208 {
205 const union MHD_DaemonInfo *dinfo; 209 MHD_stop_daemon (d); return 32;
206 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
207 if (NULL == dinfo || 0 == dinfo->port)
208 { MHD_stop_daemon (d); return 32; }
209 port = (int)dinfo->port;
210 } 210 }
211 port = (int) dinfo->port;
212 }
211 c = curl_easy_init (); 213 c = curl_easy_init ();
212 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 214 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
213 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 215 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
214 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 216 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
215 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 217 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
216 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 218 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -222,14 +224,14 @@ testInternalGet ()
222 * crashes on my system! */ 224 * crashes on my system! */
223 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 225 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
224 if (CURLE_OK != (errornum = curl_easy_perform (c))) 226 if (CURLE_OK != (errornum = curl_easy_perform (c)))
225 { 227 {
226 fprintf (stderr, 228 fprintf (stderr,
227 "curl_easy_perform failed: `%s'\n", 229 "curl_easy_perform failed: `%s'\n",
228 curl_easy_strerror (errornum)); 230 curl_easy_strerror (errornum));
229 curl_easy_cleanup (c); 231 curl_easy_cleanup (c);
230 MHD_stop_daemon (d); 232 MHD_stop_daemon (d);
231 return 2; 233 return 2;
232 } 234 }
233 curl_easy_cleanup (c); 235 curl_easy_cleanup (c);
234 MHD_stop_daemon (d); 236 MHD_stop_daemon (d);
235 return validate (cbc, 4); 237 return validate (cbc, 4);
@@ -253,21 +255,24 @@ testMultithreadedGet ()
253 cbc.buf = buf; 255 cbc.buf = buf;
254 cbc.size = 2048; 256 cbc.size = 2048;
255 cbc.pos = 0; 257 cbc.pos = 0;
256 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 258 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
259 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
257 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 260 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
258 if (d == NULL) 261 if (d == NULL)
259 return 16; 262 return 16;
260 if (0 == port) 263 if (0 == port)
264 {
265 const union MHD_DaemonInfo *dinfo;
266 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
267 if ((NULL == dinfo) ||(0 == dinfo->port) )
261 { 268 {
262 const union MHD_DaemonInfo *dinfo; 269 MHD_stop_daemon (d); return 32;
263 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
264 if (NULL == dinfo || 0 == dinfo->port)
265 { MHD_stop_daemon (d); return 32; }
266 port = (int)dinfo->port;
267 } 270 }
271 port = (int) dinfo->port;
272 }
268 c = curl_easy_init (); 273 c = curl_easy_init ();
269 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 274 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
270 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 275 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
271 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 276 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
272 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 277 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
273 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 278 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -279,14 +284,14 @@ testMultithreadedGet ()
279 * crashes on my system! */ 284 * crashes on my system! */
280 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 285 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
281 if (CURLE_OK != (errornum = curl_easy_perform (c))) 286 if (CURLE_OK != (errornum = curl_easy_perform (c)))
282 { 287 {
283 fprintf (stderr, 288 fprintf (stderr,
284 "curl_easy_perform failed: `%s'\n", 289 "curl_easy_perform failed: `%s'\n",
285 curl_easy_strerror (errornum)); 290 curl_easy_strerror (errornum));
286 curl_easy_cleanup (c); 291 curl_easy_cleanup (c);
287 MHD_stop_daemon (d); 292 MHD_stop_daemon (d);
288 return 32; 293 return 32;
289 } 294 }
290 curl_easy_cleanup (c); 295 curl_easy_cleanup (c);
291 MHD_stop_daemon (d); 296 MHD_stop_daemon (d);
292 return validate (cbc, 64); 297 return validate (cbc, 64);
@@ -316,16 +321,18 @@ testMultithreadedPoolGet ()
316 if (d == NULL) 321 if (d == NULL)
317 return 16; 322 return 16;
318 if (0 == port) 323 if (0 == port)
324 {
325 const union MHD_DaemonInfo *dinfo;
326 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
327 if ((NULL == dinfo) ||(0 == dinfo->port) )
319 { 328 {
320 const union MHD_DaemonInfo *dinfo; 329 MHD_stop_daemon (d); return 32;
321 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
322 if (NULL == dinfo || 0 == dinfo->port)
323 { MHD_stop_daemon (d); return 32; }
324 port = (int)dinfo->port;
325 } 330 }
331 port = (int) dinfo->port;
332 }
326 c = curl_easy_init (); 333 c = curl_easy_init ();
327 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 334 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
328 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 335 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
329 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 336 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
330 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 337 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
331 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 338 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -337,14 +344,14 @@ testMultithreadedPoolGet ()
337 * crashes on my system! */ 344 * crashes on my system! */
338 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 345 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
339 if (CURLE_OK != (errornum = curl_easy_perform (c))) 346 if (CURLE_OK != (errornum = curl_easy_perform (c)))
340 { 347 {
341 fprintf (stderr, 348 fprintf (stderr,
342 "curl_easy_perform failed: `%s'\n", 349 "curl_easy_perform failed: `%s'\n",
343 curl_easy_strerror (errornum)); 350 curl_easy_strerror (errornum));
344 curl_easy_cleanup (c); 351 curl_easy_cleanup (c);
345 MHD_stop_daemon (d); 352 MHD_stop_daemon (d);
346 return 32; 353 return 32;
347 } 354 }
348 curl_easy_cleanup (c); 355 curl_easy_cleanup (c);
349 MHD_stop_daemon (d); 356 MHD_stop_daemon (d);
350 return validate (cbc, 64); 357 return validate (cbc, 64);
@@ -388,16 +395,18 @@ testExternalGet ()
388 if (d == NULL) 395 if (d == NULL)
389 return 256; 396 return 256;
390 if (0 == port) 397 if (0 == port)
398 {
399 const union MHD_DaemonInfo *dinfo;
400 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
401 if ((NULL == dinfo) ||(0 == dinfo->port) )
391 { 402 {
392 const union MHD_DaemonInfo *dinfo; 403 MHD_stop_daemon (d); return 32;
393 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
394 if (NULL == dinfo || 0 == dinfo->port)
395 { MHD_stop_daemon (d); return 32; }
396 port = (int)dinfo->port;
397 } 404 }
405 port = (int) dinfo->port;
406 }
398 c = curl_easy_init (); 407 c = curl_easy_init ();
399 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 408 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
400 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 409 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
401 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 410 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
402 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 411 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
403 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 412 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -412,86 +421,88 @@ testExternalGet ()
412 421
413 multi = curl_multi_init (); 422 multi = curl_multi_init ();
414 if (multi == NULL) 423 if (multi == NULL)
424 {
425 curl_easy_cleanup (c);
426 MHD_stop_daemon (d);
427 return 512;
428 }
429 mret = curl_multi_add_handle (multi, c);
430 if (mret != CURLM_OK)
431 {
432 curl_multi_cleanup (multi);
433 curl_easy_cleanup (c);
434 MHD_stop_daemon (d);
435 return 1024;
436 }
437 start = time (NULL);
438 while ((time (NULL) - start < 5) && (multi != NULL))
439 {
440 maxsock = MHD_INVALID_SOCKET;
441 maxposixs = -1;
442 FD_ZERO (&rs);
443 FD_ZERO (&ws);
444 FD_ZERO (&es);
445 curl_multi_perform (multi, &running);
446 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
447 if (mret != CURLM_OK)
415 { 448 {
449 curl_multi_remove_handle (multi, c);
450 curl_multi_cleanup (multi);
416 curl_easy_cleanup (c); 451 curl_easy_cleanup (c);
417 MHD_stop_daemon (d); 452 MHD_stop_daemon (d);
418 return 512; 453 return 2048;
419 } 454 }
420 mret = curl_multi_add_handle (multi, c); 455 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
421 if (mret != CURLM_OK)
422 { 456 {
457 curl_multi_remove_handle (multi, c);
423 curl_multi_cleanup (multi); 458 curl_multi_cleanup (multi);
424 curl_easy_cleanup (c); 459 curl_easy_cleanup (c);
425 MHD_stop_daemon (d); 460 MHD_stop_daemon (d);
426 return 1024; 461 return 4096;
427 } 462 }
428 start = time (NULL); 463 tv.tv_sec = 0;
429 while ((time (NULL) - start < 5) && (multi != NULL)) 464 tv.tv_usec = 1000;
465 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
430 { 466 {
431 maxsock = MHD_INVALID_SOCKET;
432 maxposixs = -1;
433 FD_ZERO (&rs);
434 FD_ZERO (&ws);
435 FD_ZERO (&es);
436 curl_multi_perform (multi, &running);
437 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
438 if (mret != CURLM_OK)
439 {
440 curl_multi_remove_handle (multi, c);
441 curl_multi_cleanup (multi);
442 curl_easy_cleanup (c);
443 MHD_stop_daemon (d);
444 return 2048;
445 }
446 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
447 {
448 curl_multi_remove_handle (multi, c);
449 curl_multi_cleanup (multi);
450 curl_easy_cleanup (c);
451 MHD_stop_daemon (d);
452 return 4096;
453 }
454 tv.tv_sec = 0;
455 tv.tv_usec = 1000;
456 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
457 {
458#ifdef MHD_POSIX_SOCKETS 467#ifdef MHD_POSIX_SOCKETS
459 if (EINTR != errno) 468 if (EINTR != errno)
460 abort (); 469 abort ();
461#else 470#else
462 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 471 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
463 abort (); 472 ws.fd_count)
464 Sleep (1000); 473 ||(0 != es.fd_count) )
474 abort ();
475 Sleep (1000);
465#endif 476#endif
466 }
467 curl_multi_perform (multi, &running);
468 if (running == 0)
469 {
470 msg = curl_multi_info_read (multi, &running);
471 if (msg == NULL)
472 break;
473 if (msg->msg == CURLMSG_DONE)
474 {
475 if (msg->data.result != CURLE_OK)
476 printf ("%s failed at %s:%d: `%s'\n",
477 "curl_multi_perform",
478 __FILE__,
479 __LINE__, curl_easy_strerror (msg->data.result));
480 curl_multi_remove_handle (multi, c);
481 curl_multi_cleanup (multi);
482 curl_easy_cleanup (c);
483 c = NULL;
484 multi = NULL;
485 }
486 }
487 MHD_run (d);
488 } 477 }
489 if (multi != NULL) 478 curl_multi_perform (multi, &running);
479 if (running == 0)
490 { 480 {
491 curl_multi_remove_handle (multi, c); 481 msg = curl_multi_info_read (multi, &running);
492 curl_easy_cleanup (c); 482 if (msg == NULL)
493 curl_multi_cleanup (multi); 483 break;
484 if (msg->msg == CURLMSG_DONE)
485 {
486 if (msg->data.result != CURLE_OK)
487 printf ("%s failed at %s:%d: `%s'\n",
488 "curl_multi_perform",
489 __FILE__,
490 __LINE__, curl_easy_strerror (msg->data.result));
491 curl_multi_remove_handle (multi, c);
492 curl_multi_cleanup (multi);
493 curl_easy_cleanup (c);
494 c = NULL;
495 multi = NULL;
496 }
494 } 497 }
498 MHD_run (d);
499 }
500 if (multi != NULL)
501 {
502 curl_multi_remove_handle (multi, c);
503 curl_easy_cleanup (c);
504 curl_multi_cleanup (multi);
505 }
495 MHD_stop_daemon (d); 506 MHD_stop_daemon (d);
496 return validate (cbc, 8192); 507 return validate (cbc, 8192);
497} 508}
@@ -502,16 +513,16 @@ int
502main (int argc, char *const *argv) 513main (int argc, char *const *argv)
503{ 514{
504 unsigned int errorCount = 0; 515 unsigned int errorCount = 0;
505 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 516 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
506 517
507 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 518 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
508 return 2; 519 return 2;
509 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 520 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
510 { 521 {
511 errorCount += testInternalGet (); 522 errorCount += testInternalGet ();
512 errorCount += testMultithreadedGet (); 523 errorCount += testMultithreadedGet ();
513 errorCount += testMultithreadedPoolGet (); 524 errorCount += testMultithreadedPoolGet ();
514 } 525 }
515 errorCount += testExternalGet (); 526 errorCount += testExternalGet ();
516 if (errorCount != 0) 527 if (errorCount != 0)
517 fprintf (stderr, "Error (code: %u)\n", errorCount); 528 fprintf (stderr, "Error (code: %u)\n", errorCount);