diff options
Diffstat (limited to 'src/testcurl/test_get_sendfile.c')
-rw-r--r-- | src/testcurl/test_get_sendfile.c | 394 |
1 files changed, 204 insertions, 190 deletions
diff --git a/src/testcurl/test_get_sendfile.c b/src/testcurl/test_get_sendfile.c index 3e68647b..7651ff56 100644 --- a/src/testcurl/test_get_sendfile.c +++ b/src/testcurl/test_get_sendfile.c | |||
@@ -40,14 +40,15 @@ | |||
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 | ||
50 | #define TESTSTR "This is the content of the test file we are sending using sendfile (if available)" | 50 | #define TESTSTR \ |
51 | "This is the content of the test file we are sending using sendfile (if available)" | ||
51 | 52 | ||
52 | static char *sourcefile; | 53 | static char *sourcefile; |
53 | 54 | ||
@@ -88,25 +89,25 @@ ahc_echo (void *cls, | |||
88 | struct MHD_Response *response; | 89 | struct MHD_Response *response; |
89 | int ret; | 90 | int ret; |
90 | int fd; | 91 | int fd; |
91 | (void)url;(void)version; /* Unused. Silent compiler warning. */ | 92 | (void) url; (void) version; /* Unused. Silent compiler warning. */ |
92 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 93 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
93 | 94 | ||
94 | if (0 != strcmp (me, method)) | 95 | if (0 != strcmp (me, method)) |
95 | return MHD_NO; /* unexpected method */ | 96 | return MHD_NO; /* unexpected method */ |
96 | if (&ptr != *unused) | 97 | if (&ptr != *unused) |
97 | { | 98 | { |
98 | *unused = &ptr; | 99 | *unused = &ptr; |
99 | return MHD_YES; | 100 | return MHD_YES; |
100 | } | 101 | } |
101 | *unused = NULL; | 102 | *unused = NULL; |
102 | fd = open (sourcefile, O_RDONLY); | 103 | fd = open (sourcefile, O_RDONLY); |
103 | if (fd == -1) | 104 | if (fd == -1) |
104 | { | 105 | { |
105 | fprintf (stderr, "Failed to open `%s': %s\n", | 106 | fprintf (stderr, "Failed to open `%s': %s\n", |
106 | sourcefile, | 107 | sourcefile, |
107 | strerror (errno)); | 108 | strerror (errno)); |
108 | exit (1); | 109 | exit (1); |
109 | } | 110 | } |
110 | response = MHD_create_response_from_fd (strlen (TESTSTR), fd); | 111 | response = MHD_create_response_from_fd (strlen (TESTSTR), fd); |
111 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 112 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
112 | MHD_destroy_response (response); | 113 | MHD_destroy_response (response); |
@@ -129,11 +130,11 @@ testInternalGet () | |||
129 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 130 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
130 | port = 0; | 131 | port = 0; |
131 | else | 132 | else |
132 | { | 133 | { |
133 | port = 1200; | 134 | port = 1200; |
134 | if (oneone) | 135 | if (oneone) |
135 | port += 10; | 136 | port += 10; |
136 | } | 137 | } |
137 | 138 | ||
138 | cbc.buf = buf; | 139 | cbc.buf = buf; |
139 | cbc.size = 2048; | 140 | cbc.size = 2048; |
@@ -143,16 +144,18 @@ testInternalGet () | |||
143 | if (d == NULL) | 144 | if (d == NULL) |
144 | return 1; | 145 | return 1; |
145 | if (0 == port) | 146 | if (0 == port) |
147 | { | ||
148 | const union MHD_DaemonInfo *dinfo; | ||
149 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
150 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
146 | { | 151 | { |
147 | const union MHD_DaemonInfo *dinfo; | 152 | MHD_stop_daemon (d); return 32; |
148 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
149 | if (NULL == dinfo || 0 == dinfo->port) | ||
150 | { MHD_stop_daemon (d); return 32; } | ||
151 | port = (int)dinfo->port; | ||
152 | } | 153 | } |
154 | port = (int) dinfo->port; | ||
155 | } | ||
153 | c = curl_easy_init (); | 156 | c = curl_easy_init (); |
154 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); | 157 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); |
155 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 158 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
156 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 159 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
157 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 160 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
158 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 161 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -167,14 +170,14 @@ testInternalGet () | |||
167 | crashes on my system!*/ | 170 | crashes on my system!*/ |
168 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 171 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
169 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 172 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
170 | { | 173 | { |
171 | fprintf (stderr, | 174 | fprintf (stderr, |
172 | "curl_easy_perform failed: `%s'\n", | 175 | "curl_easy_perform failed: `%s'\n", |
173 | curl_easy_strerror (errornum)); | 176 | curl_easy_strerror (errornum)); |
174 | curl_easy_cleanup (c); | 177 | curl_easy_cleanup (c); |
175 | MHD_stop_daemon (d); | 178 | MHD_stop_daemon (d); |
176 | return 2; | 179 | return 2; |
177 | } | 180 | } |
178 | curl_easy_cleanup (c); | 181 | curl_easy_cleanup (c); |
179 | MHD_stop_daemon (d); | 182 | MHD_stop_daemon (d); |
180 | if (cbc.pos != strlen (TESTSTR)) | 183 | if (cbc.pos != strlen (TESTSTR)) |
@@ -198,30 +201,33 @@ testMultithreadedGet () | |||
198 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 201 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
199 | port = 0; | 202 | port = 0; |
200 | else | 203 | else |
201 | { | 204 | { |
202 | port = 1201; | 205 | port = 1201; |
203 | if (oneone) | 206 | if (oneone) |
204 | port += 10; | 207 | port += 10; |
205 | } | 208 | } |
206 | 209 | ||
207 | cbc.buf = buf; | 210 | cbc.buf = buf; |
208 | cbc.size = 2048; | 211 | cbc.size = 2048; |
209 | cbc.pos = 0; | 212 | cbc.pos = 0; |
210 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 213 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
214 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
211 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 215 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
212 | if (d == NULL) | 216 | if (d == NULL) |
213 | return 16; | 217 | return 16; |
214 | if (0 == port) | 218 | if (0 == port) |
219 | { | ||
220 | const union MHD_DaemonInfo *dinfo; | ||
221 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
222 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
215 | { | 223 | { |
216 | const union MHD_DaemonInfo *dinfo; | 224 | MHD_stop_daemon (d); return 32; |
217 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
218 | if (NULL == dinfo || 0 == dinfo->port) | ||
219 | { MHD_stop_daemon (d); return 32; } | ||
220 | port = (int)dinfo->port; | ||
221 | } | 225 | } |
226 | port = (int) dinfo->port; | ||
227 | } | ||
222 | c = curl_easy_init (); | 228 | c = curl_easy_init (); |
223 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); | 229 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); |
224 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 230 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
225 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 231 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
226 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 232 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
227 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 233 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -236,14 +242,14 @@ testMultithreadedGet () | |||
236 | crashes on my system! */ | 242 | crashes on my system! */ |
237 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 243 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
238 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 244 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
239 | { | 245 | { |
240 | fprintf (stderr, | 246 | fprintf (stderr, |
241 | "curl_easy_perform failed: `%s'\n", | 247 | "curl_easy_perform failed: `%s'\n", |
242 | curl_easy_strerror (errornum)); | 248 | curl_easy_strerror (errornum)); |
243 | curl_easy_cleanup (c); | 249 | curl_easy_cleanup (c); |
244 | MHD_stop_daemon (d); | 250 | MHD_stop_daemon (d); |
245 | return 32; | 251 | return 32; |
246 | } | 252 | } |
247 | curl_easy_cleanup (c); | 253 | curl_easy_cleanup (c); |
248 | MHD_stop_daemon (d); | 254 | MHD_stop_daemon (d); |
249 | if (cbc.pos != strlen (TESTSTR)) | 255 | if (cbc.pos != strlen (TESTSTR)) |
@@ -267,11 +273,11 @@ testMultithreadedPoolGet () | |||
267 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 273 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
268 | port = 0; | 274 | port = 0; |
269 | else | 275 | else |
270 | { | 276 | { |
271 | port = 1202; | 277 | port = 1202; |
272 | if (oneone) | 278 | if (oneone) |
273 | port += 10; | 279 | port += 10; |
274 | } | 280 | } |
275 | 281 | ||
276 | cbc.buf = buf; | 282 | cbc.buf = buf; |
277 | cbc.size = 2048; | 283 | cbc.size = 2048; |
@@ -282,16 +288,18 @@ testMultithreadedPoolGet () | |||
282 | if (d == NULL) | 288 | if (d == NULL) |
283 | return 16; | 289 | return 16; |
284 | if (0 == port) | 290 | if (0 == port) |
291 | { | ||
292 | const union MHD_DaemonInfo *dinfo; | ||
293 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
294 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
285 | { | 295 | { |
286 | const union MHD_DaemonInfo *dinfo; | 296 | MHD_stop_daemon (d); return 32; |
287 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
288 | if (NULL == dinfo || 0 == dinfo->port) | ||
289 | { MHD_stop_daemon (d); return 32; } | ||
290 | port = (int)dinfo->port; | ||
291 | } | 297 | } |
298 | port = (int) dinfo->port; | ||
299 | } | ||
292 | c = curl_easy_init (); | 300 | c = curl_easy_init (); |
293 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); | 301 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); |
294 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 302 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
295 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 303 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
296 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 304 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
297 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 305 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -306,14 +314,14 @@ testMultithreadedPoolGet () | |||
306 | crashes on my system!*/ | 314 | crashes on my system!*/ |
307 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 315 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
308 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 316 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
309 | { | 317 | { |
310 | fprintf (stderr, | 318 | fprintf (stderr, |
311 | "curl_easy_perform failed: `%s'\n", | 319 | "curl_easy_perform failed: `%s'\n", |
312 | curl_easy_strerror (errornum)); | 320 | curl_easy_strerror (errornum)); |
313 | curl_easy_cleanup (c); | 321 | curl_easy_cleanup (c); |
314 | MHD_stop_daemon (d); | 322 | MHD_stop_daemon (d); |
315 | return 32; | 323 | return 32; |
316 | } | 324 | } |
317 | curl_easy_cleanup (c); | 325 | curl_easy_cleanup (c); |
318 | MHD_stop_daemon (d); | 326 | MHD_stop_daemon (d); |
319 | if (cbc.pos != strlen (TESTSTR)) | 327 | if (cbc.pos != strlen (TESTSTR)) |
@@ -351,11 +359,11 @@ testExternalGet () | |||
351 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 359 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
352 | port = 0; | 360 | port = 0; |
353 | else | 361 | else |
354 | { | 362 | { |
355 | port = 1203; | 363 | port = 1203; |
356 | if (oneone) | 364 | if (oneone) |
357 | port += 10; | 365 | port += 10; |
358 | } | 366 | } |
359 | 367 | ||
360 | multi = NULL; | 368 | multi = NULL; |
361 | cbc.buf = buf; | 369 | cbc.buf = buf; |
@@ -366,16 +374,18 @@ testExternalGet () | |||
366 | if (d == NULL) | 374 | if (d == NULL) |
367 | return 256; | 375 | return 256; |
368 | if (0 == port) | 376 | if (0 == port) |
377 | { | ||
378 | const union MHD_DaemonInfo *dinfo; | ||
379 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
380 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
369 | { | 381 | { |
370 | const union MHD_DaemonInfo *dinfo; | 382 | MHD_stop_daemon (d); return 32; |
371 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
372 | if (NULL == dinfo || 0 == dinfo->port) | ||
373 | { MHD_stop_daemon (d); return 32; } | ||
374 | port = (int)dinfo->port; | ||
375 | } | 383 | } |
384 | port = (int) dinfo->port; | ||
385 | } | ||
376 | c = curl_easy_init (); | 386 | c = curl_easy_init (); |
377 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); | 387 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); |
378 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 388 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
379 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 389 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
380 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 390 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
381 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 391 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -393,86 +403,88 @@ testExternalGet () | |||
393 | 403 | ||
394 | multi = curl_multi_init (); | 404 | multi = curl_multi_init (); |
395 | if (multi == NULL) | 405 | if (multi == NULL) |
406 | { | ||
407 | curl_easy_cleanup (c); | ||
408 | MHD_stop_daemon (d); | ||
409 | return 512; | ||
410 | } | ||
411 | mret = curl_multi_add_handle (multi, c); | ||
412 | if (mret != CURLM_OK) | ||
413 | { | ||
414 | curl_multi_cleanup (multi); | ||
415 | curl_easy_cleanup (c); | ||
416 | MHD_stop_daemon (d); | ||
417 | return 1024; | ||
418 | } | ||
419 | start = time (NULL); | ||
420 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
421 | { | ||
422 | maxsock = MHD_INVALID_SOCKET; | ||
423 | maxposixs = -1; | ||
424 | FD_ZERO (&rs); | ||
425 | FD_ZERO (&ws); | ||
426 | FD_ZERO (&es); | ||
427 | curl_multi_perform (multi, &running); | ||
428 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
429 | if (mret != CURLM_OK) | ||
396 | { | 430 | { |
431 | curl_multi_remove_handle (multi, c); | ||
432 | curl_multi_cleanup (multi); | ||
397 | curl_easy_cleanup (c); | 433 | curl_easy_cleanup (c); |
398 | MHD_stop_daemon (d); | 434 | MHD_stop_daemon (d); |
399 | return 512; | 435 | return 2048; |
400 | } | 436 | } |
401 | mret = curl_multi_add_handle (multi, c); | 437 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
402 | if (mret != CURLM_OK) | ||
403 | { | 438 | { |
439 | curl_multi_remove_handle (multi, c); | ||
404 | curl_multi_cleanup (multi); | 440 | curl_multi_cleanup (multi); |
405 | curl_easy_cleanup (c); | 441 | curl_easy_cleanup (c); |
406 | MHD_stop_daemon (d); | 442 | MHD_stop_daemon (d); |
407 | return 1024; | 443 | return 4096; |
408 | } | 444 | } |
409 | start = time (NULL); | 445 | tv.tv_sec = 0; |
410 | while ((time (NULL) - start < 5) && (multi != NULL)) | 446 | tv.tv_usec = 1000; |
447 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
411 | { | 448 | { |
412 | maxsock = MHD_INVALID_SOCKET; | ||
413 | maxposixs = -1; | ||
414 | FD_ZERO (&rs); | ||
415 | FD_ZERO (&ws); | ||
416 | FD_ZERO (&es); | ||
417 | curl_multi_perform (multi, &running); | ||
418 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
419 | if (mret != CURLM_OK) | ||
420 | { | ||
421 | curl_multi_remove_handle (multi, c); | ||
422 | curl_multi_cleanup (multi); | ||
423 | curl_easy_cleanup (c); | ||
424 | MHD_stop_daemon (d); | ||
425 | return 2048; | ||
426 | } | ||
427 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
428 | { | ||
429 | curl_multi_remove_handle (multi, c); | ||
430 | curl_multi_cleanup (multi); | ||
431 | curl_easy_cleanup (c); | ||
432 | MHD_stop_daemon (d); | ||
433 | return 4096; | ||
434 | } | ||
435 | tv.tv_sec = 0; | ||
436 | tv.tv_usec = 1000; | ||
437 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
438 | { | ||
439 | #ifdef MHD_POSIX_SOCKETS | 449 | #ifdef MHD_POSIX_SOCKETS |
440 | if (EINTR != errno) | 450 | if (EINTR != errno) |
441 | abort (); | 451 | abort (); |
442 | #else | 452 | #else |
443 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 453 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
444 | abort (); | 454 | ws.fd_count) |
445 | Sleep (1000); | 455 | ||(0 != es.fd_count) ) |
456 | abort (); | ||
457 | Sleep (1000); | ||
446 | #endif | 458 | #endif |
447 | } | ||
448 | curl_multi_perform (multi, &running); | ||
449 | if (running == 0) | ||
450 | { | ||
451 | msg = curl_multi_info_read (multi, &running); | ||
452 | if (msg == NULL) | ||
453 | break; | ||
454 | if (msg->msg == CURLMSG_DONE) | ||
455 | { | ||
456 | if (msg->data.result != CURLE_OK) | ||
457 | printf ("%s failed at %s:%d: `%s'\n", | ||
458 | "curl_multi_perform", | ||
459 | __FILE__, | ||
460 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
461 | curl_multi_remove_handle (multi, c); | ||
462 | curl_multi_cleanup (multi); | ||
463 | curl_easy_cleanup (c); | ||
464 | c = NULL; | ||
465 | multi = NULL; | ||
466 | } | ||
467 | } | ||
468 | MHD_run (d); | ||
469 | } | 459 | } |
470 | if (multi != NULL) | 460 | curl_multi_perform (multi, &running); |
461 | if (running == 0) | ||
471 | { | 462 | { |
472 | curl_multi_remove_handle (multi, c); | 463 | msg = curl_multi_info_read (multi, &running); |
473 | curl_easy_cleanup (c); | 464 | if (msg == NULL) |
474 | curl_multi_cleanup (multi); | 465 | break; |
466 | if (msg->msg == CURLMSG_DONE) | ||
467 | { | ||
468 | if (msg->data.result != CURLE_OK) | ||
469 | printf ("%s failed at %s:%d: `%s'\n", | ||
470 | "curl_multi_perform", | ||
471 | __FILE__, | ||
472 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
473 | curl_multi_remove_handle (multi, c); | ||
474 | curl_multi_cleanup (multi); | ||
475 | curl_easy_cleanup (c); | ||
476 | c = NULL; | ||
477 | multi = NULL; | ||
478 | } | ||
475 | } | 479 | } |
480 | MHD_run (d); | ||
481 | } | ||
482 | if (multi != NULL) | ||
483 | { | ||
484 | curl_multi_remove_handle (multi, c); | ||
485 | curl_easy_cleanup (c); | ||
486 | curl_multi_cleanup (multi); | ||
487 | } | ||
476 | MHD_stop_daemon (d); | 488 | MHD_stop_daemon (d); |
477 | if (cbc.pos != strlen (TESTSTR)) | 489 | if (cbc.pos != strlen (TESTSTR)) |
478 | return 8192; | 490 | return 8192; |
@@ -495,7 +507,7 @@ testUnknownPortGet () | |||
495 | 507 | ||
496 | struct sockaddr_in addr; | 508 | struct sockaddr_in addr; |
497 | socklen_t addr_len = sizeof(addr); | 509 | socklen_t addr_len = sizeof(addr); |
498 | memset(&addr, 0, sizeof(addr)); | 510 | memset (&addr, 0, sizeof(addr)); |
499 | addr.sin_family = AF_INET; | 511 | addr.sin_family = AF_INET; |
500 | addr.sin_port = 0; | 512 | addr.sin_port = 0; |
501 | addr.sin_addr.s_addr = INADDR_ANY; | 513 | addr.sin_addr.s_addr = INADDR_ANY; |
@@ -511,29 +523,31 @@ testUnknownPortGet () | |||
511 | return 32768; | 523 | return 32768; |
512 | 524 | ||
513 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 525 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
514 | { | 526 | { |
515 | di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD); | 527 | di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD); |
516 | if (di == NULL) | 528 | if (di == NULL) |
517 | return 65536; | 529 | return 65536; |
518 | 530 | ||
519 | if (0 != getsockname(di->listen_fd, (struct sockaddr *) &addr, &addr_len)) | 531 | if (0 != getsockname (di->listen_fd, (struct sockaddr *) &addr, &addr_len)) |
520 | return 131072; | 532 | return 131072; |
521 | 533 | ||
522 | if (addr.sin_family != AF_INET) | 534 | if (addr.sin_family != AF_INET) |
523 | return 26214; | 535 | return 26214; |
524 | port = (int)ntohs(addr.sin_port); | 536 | port = (int) ntohs (addr.sin_port); |
525 | } | 537 | } |
526 | else | 538 | else |
539 | { | ||
540 | const union MHD_DaemonInfo *dinfo; | ||
541 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
542 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
527 | { | 543 | { |
528 | const union MHD_DaemonInfo *dinfo; | 544 | MHD_stop_daemon (d); return 32; |
529 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
530 | if (NULL == dinfo || 0 == dinfo->port) | ||
531 | { MHD_stop_daemon (d); return 32; } | ||
532 | port = (int)dinfo->port; | ||
533 | } | 545 | } |
546 | port = (int) dinfo->port; | ||
547 | } | ||
534 | 548 | ||
535 | snprintf(buf, sizeof(buf), "http://127.0.0.1:%d/", | 549 | snprintf (buf, sizeof(buf), "http://127.0.0.1:%d/", |
536 | port); | 550 | port); |
537 | 551 | ||
538 | c = curl_easy_init (); | 552 | c = curl_easy_init (); |
539 | curl_easy_setopt (c, CURLOPT_URL, buf); | 553 | curl_easy_setopt (c, CURLOPT_URL, buf); |
@@ -551,14 +565,14 @@ testUnknownPortGet () | |||
551 | crashes on my system! */ | 565 | crashes on my system! */ |
552 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 566 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
553 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 567 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
554 | { | 568 | { |
555 | fprintf (stderr, | 569 | fprintf (stderr, |
556 | "curl_easy_perform failed: `%s'\n", | 570 | "curl_easy_perform failed: `%s'\n", |
557 | curl_easy_strerror (errornum)); | 571 | curl_easy_strerror (errornum)); |
558 | curl_easy_cleanup (c); | 572 | curl_easy_cleanup (c); |
559 | MHD_stop_daemon (d); | 573 | MHD_stop_daemon (d); |
560 | return 524288; | 574 | return 524288; |
561 | } | 575 | } |
562 | curl_easy_cleanup (c); | 576 | curl_easy_cleanup (c); |
563 | MHD_stop_daemon (d); | 577 | MHD_stop_daemon (d); |
564 | if (cbc.pos != strlen (TESTSTR)) | 578 | if (cbc.pos != strlen (TESTSTR)) |
@@ -575,9 +589,9 @@ main (int argc, char *const *argv) | |||
575 | unsigned int errorCount = 0; | 589 | unsigned int errorCount = 0; |
576 | const char *tmp; | 590 | const char *tmp; |
577 | FILE *f; | 591 | FILE *f; |
578 | (void)argc; /* Unused. Silent compiler warning. */ | 592 | (void) argc; /* Unused. Silent compiler warning. */ |
579 | 593 | ||
580 | if (NULL == argv || 0 == argv[0]) | 594 | if ((NULL == argv)||(0 == argv[0])) |
581 | return 99; | 595 | return 99; |
582 | oneone = has_in_name (argv[0], "11"); | 596 | oneone = has_in_name (argv[0], "11"); |
583 | 597 | ||
@@ -594,24 +608,24 @@ main (int argc, char *const *argv) | |||
594 | oneone ? "11" : ""); | 608 | oneone ? "11" : ""); |
595 | f = fopen (sourcefile, "w"); | 609 | f = fopen (sourcefile, "w"); |
596 | if (NULL == f) | 610 | if (NULL == f) |
597 | { | 611 | { |
598 | fprintf (stderr, "failed to write test file\n"); | 612 | fprintf (stderr, "failed to write test file\n"); |
599 | free (sourcefile); | 613 | free (sourcefile); |
600 | return 1; | 614 | return 1; |
601 | } | 615 | } |
602 | if (1 != | 616 | if (1 != |
603 | fwrite (TESTSTR, strlen (TESTSTR), 1, f)) | 617 | fwrite (TESTSTR, strlen (TESTSTR), 1, f)) |
604 | abort (); | 618 | abort (); |
605 | fclose (f); | 619 | fclose (f); |
606 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 620 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
607 | return 2; | 621 | return 2; |
608 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 622 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
609 | { | 623 | { |
610 | errorCount += testInternalGet (); | 624 | errorCount += testInternalGet (); |
611 | errorCount += testMultithreadedGet (); | 625 | errorCount += testMultithreadedGet (); |
612 | errorCount += testMultithreadedPoolGet (); | 626 | errorCount += testMultithreadedPoolGet (); |
613 | errorCount += testUnknownPortGet (); | 627 | errorCount += testUnknownPortGet (); |
614 | } | 628 | } |
615 | errorCount += testExternalGet (); | 629 | errorCount += testExternalGet (); |
616 | if (errorCount != 0) | 630 | if (errorCount != 0) |
617 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 631 | fprintf (stderr, "Error (code: %u)\n", errorCount); |