diff options
Diffstat (limited to 'src/testcurl/test_get.c')
-rw-r--r-- | src/testcurl/test_get.c | 134 |
1 files changed, 68 insertions, 66 deletions
diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c index b16c1554..4f4a0944 100644 --- a/src/testcurl/test_get.c +++ b/src/testcurl/test_get.c | |||
@@ -55,6 +55,7 @@ | |||
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | static int oneone; | 57 | static int oneone; |
58 | static int global_port; | ||
58 | 59 | ||
59 | struct CBC | 60 | struct CBC |
60 | { | 61 | { |
@@ -117,35 +118,35 @@ testInternalGet (int poll_flag) | |||
117 | char buf[2048]; | 118 | char buf[2048]; |
118 | struct CBC cbc; | 119 | struct CBC cbc; |
119 | CURLcode errornum; | 120 | CURLcode errornum; |
120 | int port; | ||
121 | 121 | ||
122 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 122 | if (0 == global_port) |
123 | port = 0; | ||
124 | else | ||
125 | { | 123 | { |
126 | port = 1220; | 124 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
127 | if (oneone) | 125 | { |
128 | port += 20; | 126 | global_port = 1220; |
127 | if (oneone) | ||
128 | global_port += 20; | ||
129 | } | ||
129 | } | 130 | } |
130 | 131 | ||
131 | cbc.buf = buf; | 132 | cbc.buf = buf; |
132 | cbc.size = 2048; | 133 | cbc.size = 2048; |
133 | cbc.pos = 0; | 134 | cbc.pos = 0; |
134 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 135 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
135 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 136 | global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
136 | if (d == NULL) | 137 | if (d == NULL) |
137 | return 1; | 138 | return 1; |
138 | if (0 == port) | 139 | if (0 == global_port) |
139 | { | 140 | { |
140 | const union MHD_DaemonInfo *dinfo; | 141 | const union MHD_DaemonInfo *dinfo; |
141 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | 142 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); |
142 | if (NULL == dinfo || 0 == dinfo->port) | 143 | if (NULL == dinfo || 0 == dinfo->port) |
143 | { MHD_stop_daemon (d); return 32; } | 144 | { MHD_stop_daemon (d); return 32; } |
144 | port = (int)dinfo->port; | 145 | global_port = (int)dinfo->port; |
145 | } | 146 | } |
146 | c = curl_easy_init (); | 147 | c = curl_easy_init (); |
147 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 148 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
148 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 149 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
149 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 150 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
150 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 151 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
151 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 152 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
@@ -186,35 +187,35 @@ testMultithreadedGet (int poll_flag) | |||
186 | char buf[2048]; | 187 | char buf[2048]; |
187 | struct CBC cbc; | 188 | struct CBC cbc; |
188 | CURLcode errornum; | 189 | CURLcode errornum; |
189 | int port; | ||
190 | 190 | ||
191 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 191 | if (0 == global_port) |
192 | port = 0; | ||
193 | else | ||
194 | { | 192 | { |
195 | port = 1221; | 193 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
196 | if (oneone) | 194 | { |
197 | port += 20; | 195 | global_port = 1221; |
196 | if (oneone) | ||
197 | global_port += 20; | ||
198 | } | ||
198 | } | 199 | } |
199 | 200 | ||
200 | cbc.buf = buf; | 201 | cbc.buf = buf; |
201 | cbc.size = 2048; | 202 | cbc.size = 2048; |
202 | cbc.pos = 0; | 203 | cbc.pos = 0; |
203 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 204 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
204 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 205 | global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
205 | if (d == NULL) | 206 | if (d == NULL) |
206 | return 16; | 207 | return 16; |
207 | if (0 == port) | 208 | if (0 == global_port) |
208 | { | 209 | { |
209 | const union MHD_DaemonInfo *dinfo; | 210 | const union MHD_DaemonInfo *dinfo; |
210 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | 211 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); |
211 | if (NULL == dinfo || 0 == dinfo->port) | 212 | if (NULL == dinfo || 0 == dinfo->port) |
212 | { MHD_stop_daemon (d); return 32; } | 213 | { MHD_stop_daemon (d); return 32; } |
213 | port = (int)dinfo->port; | 214 | global_port = (int)dinfo->port; |
214 | } | 215 | } |
215 | c = curl_easy_init (); | 216 | c = curl_easy_init (); |
216 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 217 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
217 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 218 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
218 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 219 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
219 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 220 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
220 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 221 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
@@ -255,36 +256,36 @@ testMultithreadedPoolGet (int poll_flag) | |||
255 | char buf[2048]; | 256 | char buf[2048]; |
256 | struct CBC cbc; | 257 | struct CBC cbc; |
257 | CURLcode errornum; | 258 | CURLcode errornum; |
258 | int port; | ||
259 | 259 | ||
260 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 260 | if (0 == global_port) |
261 | port = 0; | ||
262 | else | ||
263 | { | 261 | { |
264 | port = 1222; | 262 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
265 | if (oneone) | 263 | { |
266 | port += 20; | 264 | global_port = 1222; |
265 | if (oneone) | ||
266 | global_port += 20; | ||
267 | } | ||
267 | } | 268 | } |
268 | 269 | ||
269 | cbc.buf = buf; | 270 | cbc.buf = buf; |
270 | cbc.size = 2048; | 271 | cbc.size = 2048; |
271 | cbc.pos = 0; | 272 | cbc.pos = 0; |
272 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 273 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
273 | port, NULL, NULL, &ahc_echo, "GET", | 274 | global_port, NULL, NULL, &ahc_echo, "GET", |
274 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); | 275 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); |
275 | if (d == NULL) | 276 | if (d == NULL) |
276 | return 16; | 277 | return 16; |
277 | if (0 == port) | 278 | if (0 == global_port) |
278 | { | 279 | { |
279 | const union MHD_DaemonInfo *dinfo; | 280 | const union MHD_DaemonInfo *dinfo; |
280 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | 281 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); |
281 | if (NULL == dinfo || 0 == dinfo->port) | 282 | if (NULL == dinfo || 0 == dinfo->port) |
282 | { MHD_stop_daemon (d); return 32; } | 283 | { MHD_stop_daemon (d); return 32; } |
283 | port = (int)dinfo->port; | 284 | global_port = (int)dinfo->port; |
284 | } | 285 | } |
285 | c = curl_easy_init (); | 286 | c = curl_easy_init (); |
286 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 287 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
287 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 288 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
288 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 289 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
289 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 290 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
290 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 291 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
@@ -339,15 +340,15 @@ testExternalGet () | |||
339 | struct CURLMsg *msg; | 340 | struct CURLMsg *msg; |
340 | time_t start; | 341 | time_t start; |
341 | struct timeval tv; | 342 | struct timeval tv; |
342 | int port; | ||
343 | 343 | ||
344 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 344 | if (0 == global_port) |
345 | port = 0; | ||
346 | else | ||
347 | { | 345 | { |
348 | port = 1223; | 346 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
349 | if (oneone) | 347 | { |
350 | port += 20; | 348 | global_port = 1223; |
349 | if (oneone) | ||
350 | global_port += 20; | ||
351 | } | ||
351 | } | 352 | } |
352 | 353 | ||
353 | multi = NULL; | 354 | multi = NULL; |
@@ -355,20 +356,20 @@ testExternalGet () | |||
355 | cbc.size = 2048; | 356 | cbc.size = 2048; |
356 | cbc.pos = 0; | 357 | cbc.pos = 0; |
357 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, | 358 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, |
358 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 359 | global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
359 | if (d == NULL) | 360 | if (d == NULL) |
360 | return 256; | 361 | return 256; |
361 | if (0 == port) | 362 | if (0 == global_port) |
362 | { | 363 | { |
363 | const union MHD_DaemonInfo *dinfo; | 364 | const union MHD_DaemonInfo *dinfo; |
364 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | 365 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); |
365 | if (NULL == dinfo || 0 == dinfo->port) | 366 | if (NULL == dinfo || 0 == dinfo->port) |
366 | { MHD_stop_daemon (d); return 32; } | 367 | { MHD_stop_daemon (d); return 32; } |
367 | port = (int)dinfo->port; | 368 | global_port = (int)dinfo->port; |
368 | } | 369 | } |
369 | c = curl_easy_init (); | 370 | c = curl_easy_init (); |
370 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 371 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
371 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 372 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
372 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 373 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
373 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 374 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
374 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 375 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
@@ -565,28 +566,28 @@ testStopRace (int poll_flag) | |||
565 | struct sockaddr_in sin; | 566 | struct sockaddr_in sin; |
566 | MHD_socket fd; | 567 | MHD_socket fd; |
567 | struct MHD_Daemon *d; | 568 | struct MHD_Daemon *d; |
568 | int port; | ||
569 | 569 | ||
570 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 570 | if (0 == global_port) |
571 | port = 0; | ||
572 | else | ||
573 | { | 571 | { |
574 | port = 1224; | 572 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
575 | if (oneone) | 573 | { |
576 | port += 20; | 574 | global_port = 1224; |
575 | if (oneone) | ||
576 | global_port += 20; | ||
577 | } | ||
577 | } | 578 | } |
578 | 579 | ||
579 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 580 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
580 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 581 | global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
581 | if (d == NULL) | 582 | if (d == NULL) |
582 | return 16; | 583 | return 16; |
583 | if (0 == port) | 584 | if (0 == global_port) |
584 | { | 585 | { |
585 | const union MHD_DaemonInfo *dinfo; | 586 | const union MHD_DaemonInfo *dinfo; |
586 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | 587 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); |
587 | if (NULL == dinfo || 0 == dinfo->port) | 588 | if (NULL == dinfo || 0 == dinfo->port) |
588 | { MHD_stop_daemon (d); return 32; } | 589 | { MHD_stop_daemon (d); return 32; } |
589 | port = (int)dinfo->port; | 590 | global_port = (int)dinfo->port; |
590 | } | 591 | } |
591 | 592 | ||
592 | fd = socket (PF_INET, SOCK_STREAM, 0); | 593 | fd = socket (PF_INET, SOCK_STREAM, 0); |
@@ -598,7 +599,7 @@ testStopRace (int poll_flag) | |||
598 | 599 | ||
599 | memset(&sin, 0, sizeof(sin)); | 600 | memset(&sin, 0, sizeof(sin)); |
600 | sin.sin_family = AF_INET; | 601 | sin.sin_family = AF_INET; |
601 | sin.sin_port = htons(port); | 602 | sin.sin_port = htons(global_port); |
602 | sin.sin_addr.s_addr = htonl(0x7f000001); | 603 | sin.sin_addr.s_addr = htonl(0x7f000001); |
603 | 604 | ||
604 | if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0) | 605 | if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0) |
@@ -680,35 +681,35 @@ testEmptyGet (int poll_flag) | |||
680 | struct CBC cbc; | 681 | struct CBC cbc; |
681 | CURLcode errornum; | 682 | CURLcode errornum; |
682 | int excess_found = 0; | 683 | int excess_found = 0; |
683 | int port; | ||
684 | 684 | ||
685 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 685 | if (0 == global_port) |
686 | port = 0; | ||
687 | else | ||
688 | { | 686 | { |
689 | port = 1225; | 687 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
690 | if (oneone) | 688 | { |
691 | port += 20; | 689 | global_port = 1225; |
690 | if (oneone) | ||
691 | global_port += 20; | ||
692 | } | ||
692 | } | 693 | } |
693 | 694 | ||
694 | cbc.buf = buf; | 695 | cbc.buf = buf; |
695 | cbc.size = 2048; | 696 | cbc.size = 2048; |
696 | cbc.pos = 0; | 697 | cbc.pos = 0; |
697 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 698 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
698 | port, NULL, NULL, &ahc_empty, NULL, MHD_OPTION_END); | 699 | global_port, NULL, NULL, &ahc_empty, NULL, MHD_OPTION_END); |
699 | if (d == NULL) | 700 | if (d == NULL) |
700 | return 4194304; | 701 | return 4194304; |
701 | if (0 == port) | 702 | if (0 == global_port) |
702 | { | 703 | { |
703 | const union MHD_DaemonInfo *dinfo; | 704 | const union MHD_DaemonInfo *dinfo; |
704 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | 705 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); |
705 | if (NULL == dinfo || 0 == dinfo->port) | 706 | if (NULL == dinfo || 0 == dinfo->port) |
706 | { MHD_stop_daemon (d); return 32; } | 707 | { MHD_stop_daemon (d); return 32; } |
707 | port = (int)dinfo->port; | 708 | global_port = (int)dinfo->port; |
708 | } | 709 | } |
709 | c = curl_easy_init (); | 710 | c = curl_easy_init (); |
710 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 711 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
711 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 712 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
712 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 713 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
713 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 714 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
714 | curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound); | 715 | curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound); |
@@ -754,6 +755,7 @@ main (int argc, char *const *argv) | |||
754 | (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; | 755 | (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; |
755 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 756 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
756 | return 2; | 757 | return 2; |
758 | global_port = 0; | ||
757 | errorCount += testInternalGet (0); | 759 | errorCount += testInternalGet (0); |
758 | errorCount += testMultithreadedGet (0); | 760 | errorCount += testMultithreadedGet (0); |
759 | errorCount += testMultithreadedPoolGet (0); | 761 | errorCount += testMultithreadedPoolGet (0); |