aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_put_chunked.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_put_chunked.c')
-rw-r--r--src/testcurl/test_put_chunked.c305
1 files changed, 158 insertions, 147 deletions
diff --git a/src/testcurl/test_put_chunked.c b/src/testcurl/test_put_chunked.c
index 9f875a40..6374f4a7 100644
--- a/src/testcurl/test_put_chunked.c
+++ b/src/testcurl/test_put_chunked.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
@@ -92,38 +92,38 @@ ahc_echo (void *cls,
92 struct MHD_Response *response; 92 struct MHD_Response *response;
93 int ret; 93 int ret;
94 int have; 94 int have;
95 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 95 (void) version; (void) unused; /* Unused. Silent compiler warning. */
96 96
97 if (0 != strcmp ("PUT", method)) 97 if (0 != strcmp ("PUT", method))
98 return MHD_NO; /* unexpected method */ 98 return MHD_NO; /* unexpected method */
99 if ((*done) < 8) 99 if ((*done) < 8)
100 {
101 have = *upload_data_size;
102 if (have + *done > 8)
100 { 103 {
101 have = *upload_data_size; 104 printf ("Invalid upload data `%8s'!\n", upload_data);
102 if (have + *done > 8) 105 return MHD_NO;
103 { 106 }
104 printf ("Invalid upload data `%8s'!\n", upload_data); 107 if (0 == have)
105 return MHD_NO;
106 }
107 if (0 == have)
108 return MHD_YES;
109 if (0 == memcmp (upload_data, &"Hello123"[*done], have))
110 {
111 *done += have;
112 *upload_data_size = 0;
113 }
114 else
115 {
116 printf ("Invalid upload data `%8s'!\n", upload_data);
117 return MHD_NO;
118 }
119#if 0
120 fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8);
121#endif
122 return MHD_YES; 108 return MHD_YES;
109 if (0 == memcmp (upload_data, &"Hello123"[*done], have))
110 {
111 *done += have;
112 *upload_data_size = 0;
113 }
114 else
115 {
116 printf ("Invalid upload data `%8s'!\n", upload_data);
117 return MHD_NO;
123 } 118 }
119#if 0
120 fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8);
121#endif
122 return MHD_YES;
123 }
124 response = MHD_create_response_from_buffer (strlen (url), 124 response = MHD_create_response_from_buffer (strlen (url),
125 (void *) url, 125 (void *) url,
126 MHD_RESPMEM_MUST_COPY); 126 MHD_RESPMEM_MUST_COPY);
127 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 127 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
128 MHD_destroy_response (response); 128 MHD_destroy_response (response);
129 return ret; 129 return ret;
@@ -156,16 +156,18 @@ testInternalPut ()
156 if (d == NULL) 156 if (d == NULL)
157 return 1; 157 return 1;
158 if (0 == port) 158 if (0 == port)
159 {
160 const union MHD_DaemonInfo *dinfo;
161 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
162 if ((NULL == dinfo) ||(0 == dinfo->port) )
159 { 163 {
160 const union MHD_DaemonInfo *dinfo; 164 MHD_stop_daemon (d); return 32;
161 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
162 if (NULL == dinfo || 0 == dinfo->port)
163 { MHD_stop_daemon (d); return 32; }
164 port = (int)dinfo->port;
165 } 165 }
166 port = (int) dinfo->port;
167 }
166 c = curl_easy_init (); 168 c = curl_easy_init ();
167 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 169 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
168 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 170 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
169 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 171 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
170 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 172 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
171 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 173 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -184,14 +186,14 @@ testInternalPut ()
184 * crashes on my system! */ 186 * crashes on my system! */
185 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 187 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
186 if (CURLE_OK != (errornum = curl_easy_perform (c))) 188 if (CURLE_OK != (errornum = curl_easy_perform (c)))
187 { 189 {
188 fprintf (stderr, 190 fprintf (stderr,
189 "curl_easy_perform failed: `%s'\n", 191 "curl_easy_perform failed: `%s'\n",
190 curl_easy_strerror (errornum)); 192 curl_easy_strerror (errornum));
191 curl_easy_cleanup (c); 193 curl_easy_cleanup (c);
192 MHD_stop_daemon (d); 194 MHD_stop_daemon (d);
193 return 2; 195 return 2;
194 } 196 }
195 curl_easy_cleanup (c); 197 curl_easy_cleanup (c);
196 MHD_stop_daemon (d); 198 MHD_stop_daemon (d);
197 if (cbc.pos != strlen ("/hello_world")) 199 if (cbc.pos != strlen ("/hello_world"))
@@ -221,22 +223,25 @@ testMultithreadedPut ()
221 cbc.buf = buf; 223 cbc.buf = buf;
222 cbc.size = 2048; 224 cbc.size = 2048;
223 cbc.pos = 0; 225 cbc.pos = 0;
224 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 226 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
227 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
225 port, 228 port,
226 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 229 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
227 if (d == NULL) 230 if (d == NULL)
228 return 16; 231 return 16;
229 if (0 == port) 232 if (0 == port)
233 {
234 const union MHD_DaemonInfo *dinfo;
235 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
236 if ((NULL == dinfo) ||(0 == dinfo->port) )
230 { 237 {
231 const union MHD_DaemonInfo *dinfo; 238 MHD_stop_daemon (d); return 32;
232 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
233 if (NULL == dinfo || 0 == dinfo->port)
234 { MHD_stop_daemon (d); return 32; }
235 port = (int)dinfo->port;
236 } 239 }
240 port = (int) dinfo->port;
241 }
237 c = curl_easy_init (); 242 c = curl_easy_init ();
238 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 243 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
239 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 244 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
240 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 245 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
241 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 246 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
242 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 247 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -255,14 +260,14 @@ testMultithreadedPut ()
255 * crashes on my system! */ 260 * crashes on my system! */
256 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 261 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
257 if (CURLE_OK != (errornum = curl_easy_perform (c))) 262 if (CURLE_OK != (errornum = curl_easy_perform (c)))
258 { 263 {
259 fprintf (stderr, 264 fprintf (stderr,
260 "curl_easy_perform failed: `%s'\n", 265 "curl_easy_perform failed: `%s'\n",
261 curl_easy_strerror (errornum)); 266 curl_easy_strerror (errornum));
262 curl_easy_cleanup (c); 267 curl_easy_cleanup (c);
263 MHD_stop_daemon (d); 268 MHD_stop_daemon (d);
264 return 32; 269 return 32;
265 } 270 }
266 curl_easy_cleanup (c); 271 curl_easy_cleanup (c);
267 MHD_stop_daemon (d); 272 MHD_stop_daemon (d);
268 if (cbc.pos != strlen ("/hello_world")) 273 if (cbc.pos != strlen ("/hello_world"))
@@ -300,16 +305,18 @@ testMultithreadedPoolPut ()
300 if (d == NULL) 305 if (d == NULL)
301 return 16; 306 return 16;
302 if (0 == port) 307 if (0 == port)
308 {
309 const union MHD_DaemonInfo *dinfo;
310 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
311 if ((NULL == dinfo) ||(0 == dinfo->port) )
303 { 312 {
304 const union MHD_DaemonInfo *dinfo; 313 MHD_stop_daemon (d); return 32;
305 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
306 if (NULL == dinfo || 0 == dinfo->port)
307 { MHD_stop_daemon (d); return 32; }
308 port = (int)dinfo->port;
309 } 314 }
315 port = (int) dinfo->port;
316 }
310 c = curl_easy_init (); 317 c = curl_easy_init ();
311 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 318 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
312 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 319 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
313 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 320 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
314 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 321 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
315 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 322 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -328,14 +335,14 @@ testMultithreadedPoolPut ()
328 * crashes on my system! */ 335 * crashes on my system! */
329 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 336 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
330 if (CURLE_OK != (errornum = curl_easy_perform (c))) 337 if (CURLE_OK != (errornum = curl_easy_perform (c)))
331 { 338 {
332 fprintf (stderr, 339 fprintf (stderr,
333 "curl_easy_perform failed: `%s'\n", 340 "curl_easy_perform failed: `%s'\n",
334 curl_easy_strerror (errornum)); 341 curl_easy_strerror (errornum));
335 curl_easy_cleanup (c); 342 curl_easy_cleanup (c);
336 MHD_stop_daemon (d); 343 MHD_stop_daemon (d);
337 return 32; 344 return 32;
338 } 345 }
339 curl_easy_cleanup (c); 346 curl_easy_cleanup (c);
340 MHD_stop_daemon (d); 347 MHD_stop_daemon (d);
341 if (cbc.pos != strlen ("/hello_world")) 348 if (cbc.pos != strlen ("/hello_world"))
@@ -388,16 +395,18 @@ testExternalPut ()
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_READFUNCTION, &putBuffer); 412 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -419,87 +428,89 @@ testExternalPut ()
419 428
420 multi = curl_multi_init (); 429 multi = curl_multi_init ();
421 if (multi == NULL) 430 if (multi == NULL)
431 {
432 curl_easy_cleanup (c);
433 MHD_stop_daemon (d);
434 return 512;
435 }
436 mret = curl_multi_add_handle (multi, c);
437 if (mret != CURLM_OK)
438 {
439 curl_multi_cleanup (multi);
440 curl_easy_cleanup (c);
441 MHD_stop_daemon (d);
442 return 1024;
443 }
444 start = time (NULL);
445 while ((time (NULL) - start < 5) && (multi != NULL))
446 {
447 maxsock = MHD_INVALID_SOCKET;
448 maxposixs = -1;
449 FD_ZERO (&rs);
450 FD_ZERO (&ws);
451 FD_ZERO (&es);
452 curl_multi_perform (multi, &running);
453 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
454 if (mret != CURLM_OK)
422 { 455 {
456 curl_multi_remove_handle (multi, c);
457 curl_multi_cleanup (multi);
423 curl_easy_cleanup (c); 458 curl_easy_cleanup (c);
424 MHD_stop_daemon (d); 459 MHD_stop_daemon (d);
425 return 512; 460 return 2048;
426 } 461 }
427 mret = curl_multi_add_handle (multi, c); 462 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
428 if (mret != CURLM_OK)
429 { 463 {
464 curl_multi_remove_handle (multi, c);
430 curl_multi_cleanup (multi); 465 curl_multi_cleanup (multi);
431 curl_easy_cleanup (c); 466 curl_easy_cleanup (c);
432 MHD_stop_daemon (d); 467 MHD_stop_daemon (d);
433 return 1024; 468 return 4096;
434 } 469 }
435 start = time (NULL); 470 tv.tv_sec = 0;
436 while ((time (NULL) - start < 5) && (multi != NULL)) 471 tv.tv_usec = 1000;
472 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
437 { 473 {
438 maxsock = MHD_INVALID_SOCKET;
439 maxposixs = -1;
440 FD_ZERO (&rs);
441 FD_ZERO (&ws);
442 FD_ZERO (&es);
443 curl_multi_perform (multi, &running);
444 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
445 if (mret != CURLM_OK)
446 {
447 curl_multi_remove_handle (multi, c);
448 curl_multi_cleanup (multi);
449 curl_easy_cleanup (c);
450 MHD_stop_daemon (d);
451 return 2048;
452 }
453 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
454 {
455 curl_multi_remove_handle (multi, c);
456 curl_multi_cleanup (multi);
457 curl_easy_cleanup (c);
458 MHD_stop_daemon (d);
459 return 4096;
460 }
461 tv.tv_sec = 0;
462 tv.tv_usec = 1000;
463 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
464 {
465#ifdef MHD_POSIX_SOCKETS 474#ifdef MHD_POSIX_SOCKETS
466 if (EINTR != errno) 475 if (EINTR != errno)
467 abort (); 476 abort ();
468#else 477#else
469 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 478 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
470 abort (); 479 ws.fd_count)
471 Sleep (1000); 480 ||(0 != es.fd_count) )
481 abort ();
482 Sleep (1000);
472#endif 483#endif
473 }
474 curl_multi_perform (multi, &running);
475 if (running == 0)
476 {
477 msg = curl_multi_info_read (multi, &running);
478 if (msg == NULL)
479 break;
480 if (msg->msg == CURLMSG_DONE)
481 {
482 if (msg->data.result != CURLE_OK)
483 printf ("%s failed at %s:%d: `%s'\n",
484 "curl_multi_perform",
485 __FILE__,
486 __LINE__,
487 curl_easy_strerror (msg->data.result));
488 curl_multi_remove_handle (multi, c);
489 curl_multi_cleanup (multi);
490 curl_easy_cleanup (c);
491 c = NULL;
492 multi = NULL;
493 }
494 }
495 MHD_run (d);
496 } 484 }
497 if (multi != NULL) 485 curl_multi_perform (multi, &running);
486 if (running == 0)
498 { 487 {
499 curl_multi_remove_handle (multi, c); 488 msg = curl_multi_info_read (multi, &running);
500 curl_easy_cleanup (c); 489 if (msg == NULL)
501 curl_multi_cleanup (multi); 490 break;
491 if (msg->msg == CURLMSG_DONE)
492 {
493 if (msg->data.result != CURLE_OK)
494 printf ("%s failed at %s:%d: `%s'\n",
495 "curl_multi_perform",
496 __FILE__,
497 __LINE__,
498 curl_easy_strerror (msg->data.result));
499 curl_multi_remove_handle (multi, c);
500 curl_multi_cleanup (multi);
501 curl_easy_cleanup (c);
502 c = NULL;
503 multi = NULL;
504 }
502 } 505 }
506 MHD_run (d);
507 }
508 if (multi != NULL)
509 {
510 curl_multi_remove_handle (multi, c);
511 curl_easy_cleanup (c);
512 curl_multi_cleanup (multi);
513 }
503 MHD_stop_daemon (d); 514 MHD_stop_daemon (d);
504 if (cbc.pos != strlen ("/hello_world")) 515 if (cbc.pos != strlen ("/hello_world"))
505 return 8192; 516 return 8192;
@@ -514,16 +525,16 @@ int
514main (int argc, char *const *argv) 525main (int argc, char *const *argv)
515{ 526{
516 unsigned int errorCount = 0; 527 unsigned int errorCount = 0;
517 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 528 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
518 529
519 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 530 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
520 return 2; 531 return 2;
521 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 532 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
522 { 533 {
523 errorCount += testInternalPut (); 534 errorCount += testInternalPut ();
524 errorCount += testMultithreadedPut (); 535 errorCount += testMultithreadedPut ();
525 errorCount += testMultithreadedPoolPut (); 536 errorCount += testMultithreadedPoolPut ();
526 } 537 }
527 errorCount += testExternalPut (); 538 errorCount += testExternalPut ();
528 if (errorCount != 0) 539 if (errorCount != 0)
529 fprintf (stderr, "Error (code: %u)\n", errorCount); 540 fprintf (stderr, "Error (code: %u)\n", errorCount);