aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_delete.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_delete.c')
-rw-r--r--src/testcurl/test_delete.c287
1 files changed, 149 insertions, 138 deletions
diff --git a/src/testcurl/test_delete.c b/src/testcurl/test_delete.c
index 35e9dc62..a3d14661 100644
--- a/src/testcurl/test_delete.c
+++ b/src/testcurl/test_delete.c
@@ -37,10 +37,10 @@
37#include <unistd.h> 37#include <unistd.h>
38#endif 38#endif
39 39
40#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 40#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
41#undef CPU_COUNT 41#undef CPU_COUNT
42#endif 42#endif
43#if !defined(CPU_COUNT) 43#if ! defined(CPU_COUNT)
44#define CPU_COUNT 2 44#define CPU_COUNT 2
45#endif 45#endif
46 46
@@ -91,28 +91,28 @@ ahc_echo (void *cls,
91 int *done = cls; 91 int *done = cls;
92 struct MHD_Response *response; 92 struct MHD_Response *response;
93 int ret; 93 int ret;
94 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 94 (void) version; (void) unused; /* Unused. Silent compiler warning. */
95 95
96 if (0 != strcasecmp ("DELETE", method)) 96 if (0 != strcasecmp ("DELETE", method))
97 return MHD_NO; /* unexpected method */ 97 return MHD_NO; /* unexpected method */
98 if ((*done) == 0) 98 if ((*done) == 0)
99 {
100 if (*upload_data_size != 8)
101 return MHD_YES; /* not yet ready */
102 if (0 == memcmp (upload_data, "Hello123", 8))
99 { 103 {
100 if (*upload_data_size != 8) 104 *upload_data_size = 0;
101 return MHD_YES; /* not yet ready */
102 if (0 == memcmp (upload_data, "Hello123", 8))
103 {
104 *upload_data_size = 0;
105 }
106 else
107 {
108 printf ("Invalid upload data `%8s'!\n", upload_data);
109 return MHD_NO;
110 }
111 *done = 1;
112 return MHD_YES;
113 } 105 }
106 else
107 {
108 printf ("Invalid upload data `%8s'!\n", upload_data);
109 return MHD_NO;
110 }
111 *done = 1;
112 return MHD_YES;
113 }
114 response = MHD_create_response_from_buffer (strlen (url), (void*) url, 114 response = MHD_create_response_from_buffer (strlen (url), (void*) url,
115 MHD_RESPMEM_MUST_COPY); 115 MHD_RESPMEM_MUST_COPY);
116 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 116 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
117 MHD_destroy_response (response); 117 MHD_destroy_response (response);
118 return ret; 118 return ret;
@@ -145,16 +145,18 @@ testInternalDelete ()
145 if (d == NULL) 145 if (d == NULL)
146 return 1; 146 return 1;
147 if (0 == port) 147 if (0 == port)
148 {
149 const union MHD_DaemonInfo *dinfo;
150 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
151 if ((NULL == dinfo) ||(0 == dinfo->port) )
148 { 152 {
149 const union MHD_DaemonInfo *dinfo; 153 MHD_stop_daemon (d); return 32;
150 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
151 if (NULL == dinfo || 0 == dinfo->port)
152 { MHD_stop_daemon (d); return 32; }
153 port = (int)dinfo->port;
154 } 154 }
155 port = (int) dinfo->port;
156 }
155 c = curl_easy_init (); 157 c = curl_easy_init ();
156 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 158 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
157 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 159 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
158 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 160 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
159 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 161 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
160 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 162 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -174,14 +176,14 @@ testInternalDelete ()
174 * crashes on my system! */ 176 * crashes on my system! */
175 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 177 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
176 if (CURLE_OK != (errornum = curl_easy_perform (c))) 178 if (CURLE_OK != (errornum = curl_easy_perform (c)))
177 { 179 {
178 fprintf (stderr, 180 fprintf (stderr,
179 "curl_easy_perform failed: `%s'\n", 181 "curl_easy_perform failed: `%s'\n",
180 curl_easy_strerror (errornum)); 182 curl_easy_strerror (errornum));
181 curl_easy_cleanup (c); 183 curl_easy_cleanup (c);
182 MHD_stop_daemon (d); 184 MHD_stop_daemon (d);
183 return 2; 185 return 2;
184 } 186 }
185 curl_easy_cleanup (c); 187 curl_easy_cleanup (c);
186 MHD_stop_daemon (d); 188 MHD_stop_daemon (d);
187 if (cbc.pos != strlen ("/hello_world")) 189 if (cbc.pos != strlen ("/hello_world"))
@@ -212,22 +214,25 @@ testMultithreadedDelete ()
212 cbc.buf = buf; 214 cbc.buf = buf;
213 cbc.size = 2048; 215 cbc.size = 2048;
214 cbc.pos = 0; 216 cbc.pos = 0;
215 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 217 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
218 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
216 port, 219 port,
217 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 220 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
218 if (d == NULL) 221 if (d == NULL)
219 return 16; 222 return 16;
220 if (0 == port) 223 if (0 == port)
224 {
225 const union MHD_DaemonInfo *dinfo;
226 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
227 if ((NULL == dinfo) ||(0 == dinfo->port) )
221 { 228 {
222 const union MHD_DaemonInfo *dinfo; 229 MHD_stop_daemon (d); return 32;
223 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
224 if (NULL == dinfo || 0 == dinfo->port)
225 { MHD_stop_daemon (d); return 32; }
226 port = (int)dinfo->port;
227 } 230 }
231 port = (int) dinfo->port;
232 }
228 c = curl_easy_init (); 233 c = curl_easy_init ();
229 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 234 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
230 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 235 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
231 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 236 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
232 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 237 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
233 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 238 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -247,14 +252,14 @@ testMultithreadedDelete ()
247 * crashes on my system! */ 252 * crashes on my system! */
248 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 253 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
249 if (CURLE_OK != (errornum = curl_easy_perform (c))) 254 if (CURLE_OK != (errornum = curl_easy_perform (c)))
250 { 255 {
251 fprintf (stderr, 256 fprintf (stderr,
252 "curl_easy_perform failed: `%s'\n", 257 "curl_easy_perform failed: `%s'\n",
253 curl_easy_strerror (errornum)); 258 curl_easy_strerror (errornum));
254 curl_easy_cleanup (c); 259 curl_easy_cleanup (c);
255 MHD_stop_daemon (d); 260 MHD_stop_daemon (d);
256 return 32; 261 return 32;
257 } 262 }
258 curl_easy_cleanup (c); 263 curl_easy_cleanup (c);
259 MHD_stop_daemon (d); 264 MHD_stop_daemon (d);
260 if (cbc.pos != strlen ("/hello_world")) 265 if (cbc.pos != strlen ("/hello_world"))
@@ -292,16 +297,18 @@ testMultithreadedPoolDelete ()
292 if (d == NULL) 297 if (d == NULL)
293 return 16; 298 return 16;
294 if (0 == port) 299 if (0 == port)
300 {
301 const union MHD_DaemonInfo *dinfo;
302 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
303 if ((NULL == dinfo) ||(0 == dinfo->port) )
295 { 304 {
296 const union MHD_DaemonInfo *dinfo; 305 MHD_stop_daemon (d); return 32;
297 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
298 if (NULL == dinfo || 0 == dinfo->port)
299 { MHD_stop_daemon (d); return 32; }
300 port = (int)dinfo->port;
301 } 306 }
307 port = (int) dinfo->port;
308 }
302 c = curl_easy_init (); 309 c = curl_easy_init ();
303 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 310 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
304 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 311 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
305 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 312 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
306 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 313 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
307 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 314 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -321,14 +328,14 @@ testMultithreadedPoolDelete ()
321 * crashes on my system! */ 328 * crashes on my system! */
322 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 329 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
323 if (CURLE_OK != (errornum = curl_easy_perform (c))) 330 if (CURLE_OK != (errornum = curl_easy_perform (c)))
324 { 331 {
325 fprintf (stderr, 332 fprintf (stderr,
326 "curl_easy_perform failed: `%s'\n", 333 "curl_easy_perform failed: `%s'\n",
327 curl_easy_strerror (errornum)); 334 curl_easy_strerror (errornum));
328 curl_easy_cleanup (c); 335 curl_easy_cleanup (c);
329 MHD_stop_daemon (d); 336 MHD_stop_daemon (d);
330 return 32; 337 return 32;
331 } 338 }
332 curl_easy_cleanup (c); 339 curl_easy_cleanup (c);
333 MHD_stop_daemon (d); 340 MHD_stop_daemon (d);
334 if (cbc.pos != strlen ("/hello_world")) 341 if (cbc.pos != strlen ("/hello_world"))
@@ -381,16 +388,18 @@ testExternalDelete ()
381 if (d == NULL) 388 if (d == NULL)
382 return 256; 389 return 256;
383 if (0 == port) 390 if (0 == port)
391 {
392 const union MHD_DaemonInfo *dinfo;
393 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
394 if ((NULL == dinfo) ||(0 == dinfo->port) )
384 { 395 {
385 const union MHD_DaemonInfo *dinfo; 396 MHD_stop_daemon (d); return 32;
386 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
387 if (NULL == dinfo || 0 == dinfo->port)
388 { MHD_stop_daemon (d); return 32; }
389 port = (int)dinfo->port;
390 } 397 }
398 port = (int) dinfo->port;
399 }
391 c = curl_easy_init (); 400 c = curl_easy_init ();
392 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 401 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
393 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 402 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
394 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 403 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
395 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 404 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
396 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 405 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -413,86 +422,88 @@ testExternalDelete ()
413 422
414 multi = curl_multi_init (); 423 multi = curl_multi_init ();
415 if (multi == NULL) 424 if (multi == NULL)
425 {
426 curl_easy_cleanup (c);
427 MHD_stop_daemon (d);
428 return 512;
429 }
430 mret = curl_multi_add_handle (multi, c);
431 if (mret != CURLM_OK)
432 {
433 curl_multi_cleanup (multi);
434 curl_easy_cleanup (c);
435 MHD_stop_daemon (d);
436 return 1024;
437 }
438 start = time (NULL);
439 while ((time (NULL) - start < 5) && (multi != NULL))
440 {
441 maxsock = MHD_INVALID_SOCKET;
442 maxposixs = -1;
443 FD_ZERO (&rs);
444 FD_ZERO (&ws);
445 FD_ZERO (&es);
446 curl_multi_perform (multi, &running);
447 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
448 if (mret != CURLM_OK)
416 { 449 {
450 curl_multi_remove_handle (multi, c);
451 curl_multi_cleanup (multi);
417 curl_easy_cleanup (c); 452 curl_easy_cleanup (c);
418 MHD_stop_daemon (d); 453 MHD_stop_daemon (d);
419 return 512; 454 return 2048;
420 } 455 }
421 mret = curl_multi_add_handle (multi, c); 456 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
422 if (mret != CURLM_OK)
423 { 457 {
458 curl_multi_remove_handle (multi, c);
424 curl_multi_cleanup (multi); 459 curl_multi_cleanup (multi);
425 curl_easy_cleanup (c); 460 curl_easy_cleanup (c);
426 MHD_stop_daemon (d); 461 MHD_stop_daemon (d);
427 return 1024; 462 return 4096;
428 } 463 }
429 start = time (NULL); 464 tv.tv_sec = 0;
430 while ((time (NULL) - start < 5) && (multi != NULL)) 465 tv.tv_usec = 1000;
466 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
431 { 467 {
432 maxsock = MHD_INVALID_SOCKET;
433 maxposixs = -1;
434 FD_ZERO (&rs);
435 FD_ZERO (&ws);
436 FD_ZERO (&es);
437 curl_multi_perform (multi, &running);
438 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
439 if (mret != CURLM_OK)
440 {
441 curl_multi_remove_handle (multi, c);
442 curl_multi_cleanup (multi);
443 curl_easy_cleanup (c);
444 MHD_stop_daemon (d);
445 return 2048;
446 }
447 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
448 {
449 curl_multi_remove_handle (multi, c);
450 curl_multi_cleanup (multi);
451 curl_easy_cleanup (c);
452 MHD_stop_daemon (d);
453 return 4096;
454 }
455 tv.tv_sec = 0;
456 tv.tv_usec = 1000;
457 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
458 {
459#ifdef MHD_POSIX_SOCKETS 468#ifdef MHD_POSIX_SOCKETS
460 if (EINTR != errno) 469 if (EINTR != errno)
461 abort (); 470 abort ();
462#else 471#else
463 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 472 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
464 abort (); 473 ws.fd_count)
465 Sleep (1000); 474 ||(0 != es.fd_count) )
475 abort ();
476 Sleep (1000);
466#endif 477#endif
467 }
468 curl_multi_perform (multi, &running);
469 if (running == 0)
470 {
471 msg = curl_multi_info_read (multi, &running);
472 if (msg == NULL)
473 break;
474 if (msg->msg == CURLMSG_DONE)
475 {
476 if (msg->data.result != CURLE_OK)
477 printf ("%s failed at %s:%d: `%s'\n",
478 "curl_multi_perform",
479 __FILE__,
480 __LINE__, curl_easy_strerror (msg->data.result));
481 curl_multi_remove_handle (multi, c);
482 curl_multi_cleanup (multi);
483 curl_easy_cleanup (c);
484 c = NULL;
485 multi = NULL;
486 }
487 }
488 MHD_run (d);
489 } 478 }
490 if (multi != NULL) 479 curl_multi_perform (multi, &running);
480 if (running == 0)
491 { 481 {
492 curl_multi_remove_handle (multi, c); 482 msg = curl_multi_info_read (multi, &running);
493 curl_easy_cleanup (c); 483 if (msg == NULL)
494 curl_multi_cleanup (multi); 484 break;
485 if (msg->msg == CURLMSG_DONE)
486 {
487 if (msg->data.result != CURLE_OK)
488 printf ("%s failed at %s:%d: `%s'\n",
489 "curl_multi_perform",
490 __FILE__,
491 __LINE__, curl_easy_strerror (msg->data.result));
492 curl_multi_remove_handle (multi, c);
493 curl_multi_cleanup (multi);
494 curl_easy_cleanup (c);
495 c = NULL;
496 multi = NULL;
497 }
495 } 498 }
499 MHD_run (d);
500 }
501 if (multi != NULL)
502 {
503 curl_multi_remove_handle (multi, c);
504 curl_easy_cleanup (c);
505 curl_multi_cleanup (multi);
506 }
496 MHD_stop_daemon (d); 507 MHD_stop_daemon (d);
497 if (cbc.pos != strlen ("/hello_world")) 508 if (cbc.pos != strlen ("/hello_world"))
498 return 8192; 509 return 8192;
@@ -507,19 +518,19 @@ int
507main (int argc, char *const *argv) 518main (int argc, char *const *argv)
508{ 519{
509 unsigned int errorCount = 0; 520 unsigned int errorCount = 0;
510 (void)argc; /* Unused. Silent compiler warning. */ 521 (void) argc; /* Unused. Silent compiler warning. */
511 522
512 if (NULL == argv || 0 == argv[0]) 523 if ((NULL == argv)||(0 == argv[0]))
513 return 99; 524 return 99;
514 oneone = has_in_name (argv[0], "11"); 525 oneone = has_in_name (argv[0], "11");
515 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 526 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
516 return 2; 527 return 2;
517 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 528 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
518 { 529 {
519 errorCount += testInternalDelete (); 530 errorCount += testInternalDelete ();
520 errorCount += testMultithreadedDelete (); 531 errorCount += testMultithreadedDelete ();
521 errorCount += testMultithreadedPoolDelete (); 532 errorCount += testMultithreadedPoolDelete ();
522 } 533 }
523 errorCount += testExternalDelete (); 534 errorCount += testExternalDelete ();
524 if (errorCount != 0) 535 if (errorCount != 0)
525 fprintf (stderr, "Error (code: %u)\n", errorCount); 536 fprintf (stderr, "Error (code: %u)\n", errorCount);