diff options
Diffstat (limited to 'src/testcurl/perf_get.c')
-rw-r--r-- | src/testcurl/perf_get.c | 526 |
1 files changed, 273 insertions, 253 deletions
diff --git a/src/testcurl/perf_get.c b/src/testcurl/perf_get.c index a0af70cd..112046d5 100644 --- a/src/testcurl/perf_get.c +++ b/src/testcurl/perf_get.c | |||
@@ -51,10 +51,10 @@ | |||
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 54 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
55 | #undef CPU_COUNT | 55 | #undef CPU_COUNT |
56 | #endif | 56 | #endif |
57 | #if !defined(CPU_COUNT) | 57 | #if ! defined(CPU_COUNT) |
58 | #define CPU_COUNT 2 | 58 | #define CPU_COUNT 2 |
59 | #endif | 59 | #endif |
60 | 60 | ||
@@ -91,8 +91,8 @@ now () | |||
91 | struct timeval tv; | 91 | struct timeval tv; |
92 | 92 | ||
93 | gettimeofday (&tv, NULL); | 93 | gettimeofday (&tv, NULL); |
94 | return (((unsigned long long) tv.tv_sec * 1000LL) + | 94 | return (((unsigned long long) tv.tv_sec * 1000LL) |
95 | ((unsigned long long) tv.tv_usec / 1000LL)); | 95 | + ((unsigned long long) tv.tv_usec / 1000LL)); |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
@@ -100,7 +100,7 @@ now () | |||
100 | * Start the timer. | 100 | * Start the timer. |
101 | */ | 101 | */ |
102 | static void | 102 | static void |
103 | start_timer() | 103 | start_timer () |
104 | { | 104 | { |
105 | start_time = now (); | 105 | start_time = now (); |
106 | } | 106 | } |
@@ -114,17 +114,17 @@ start_timer() | |||
114 | static void | 114 | static void |
115 | stop (const char *desc) | 115 | stop (const char *desc) |
116 | { | 116 | { |
117 | double rps = ((double) (ROUNDS * 1000)) / ((double) (now() - start_time)); | 117 | double rps = ((double) (ROUNDS * 1000)) / ((double) (now () - start_time)); |
118 | 118 | ||
119 | fprintf (stderr, | 119 | fprintf (stderr, |
120 | "Sequential GETs using %s: %f %s\n", | 120 | "Sequential GETs using %s: %f %s\n", |
121 | desc, | 121 | desc, |
122 | rps, | 122 | rps, |
123 | "requests/s"); | 123 | "requests/s"); |
124 | GAUGER (desc, | 124 | GAUGER (desc, |
125 | "Sequential GETs", | 125 | "Sequential GETs", |
126 | rps, | 126 | rps, |
127 | "requests/s"); | 127 | "requests/s"); |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
@@ -138,8 +138,8 @@ struct CBC | |||
138 | 138 | ||
139 | static size_t | 139 | static size_t |
140 | copyBuffer (void *ptr, | 140 | copyBuffer (void *ptr, |
141 | size_t size, size_t nmemb, | 141 | size_t size, size_t nmemb, |
142 | void *ctx) | 142 | void *ctx) |
143 | { | 143 | { |
144 | struct CBC *cbc = ctx; | 144 | struct CBC *cbc = ctx; |
145 | 145 | ||
@@ -162,16 +162,16 @@ ahc_echo (void *cls, | |||
162 | static int ptr; | 162 | static int ptr; |
163 | const char *me = cls; | 163 | const char *me = cls; |
164 | int ret; | 164 | int ret; |
165 | (void)url;(void)version; /* Unused. Silent compiler warning. */ | 165 | (void) url; (void) version; /* Unused. Silent compiler warning. */ |
166 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 166 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
167 | 167 | ||
168 | if (0 != strcmp (me, method)) | 168 | if (0 != strcmp (me, method)) |
169 | return MHD_NO; /* unexpected method */ | 169 | return MHD_NO; /* unexpected method */ |
170 | if (&ptr != *unused) | 170 | if (&ptr != *unused) |
171 | { | 171 | { |
172 | *unused = &ptr; | 172 | *unused = &ptr; |
173 | return MHD_YES; | 173 | return MHD_YES; |
174 | } | 174 | } |
175 | *unused = NULL; | 175 | *unused = NULL; |
176 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 176 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
177 | if (ret == MHD_NO) | 177 | if (ret == MHD_NO) |
@@ -191,60 +191,64 @@ testInternalGet (int port, int poll_flag) | |||
191 | unsigned int i; | 191 | unsigned int i; |
192 | char url[64]; | 192 | char url[64]; |
193 | 193 | ||
194 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 194 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
195 | port = 0; | 195 | port = 0; |
196 | 196 | ||
197 | cbc.buf = buf; | 197 | cbc.buf = buf; |
198 | cbc.size = 2048; | 198 | cbc.size = 2048; |
199 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 199 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
200 | | poll_flag, | ||
200 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 201 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
201 | if (d == NULL) | 202 | if (d == NULL) |
202 | return 1; | 203 | return 1; |
203 | if (0 == port) | 204 | if (0 == port) |
205 | { | ||
206 | const union MHD_DaemonInfo *dinfo; | ||
207 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
208 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
204 | { | 209 | { |
205 | const union MHD_DaemonInfo *dinfo; | 210 | 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 | } | 211 | } |
212 | port = (int) dinfo->port; | ||
213 | } | ||
211 | snprintf (url, | 214 | snprintf (url, |
212 | sizeof (url), | 215 | sizeof (url), |
213 | "http://127.0.0.1:%d/hello_world", | 216 | "http://127.0.0.1:%d/hello_world", |
214 | port); | 217 | port); |
215 | start_timer (); | 218 | start_timer (); |
216 | for (i=0;i<ROUNDS;i++) | 219 | for (i = 0; i<ROUNDS; i++) |
220 | { | ||
221 | cbc.pos = 0; | ||
222 | c = curl_easy_init (); | ||
223 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
224 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
225 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
226 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
227 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
228 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
229 | if (oneone) | ||
230 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
231 | else | ||
232 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
233 | /* NOTE: use of CONNECTTIMEOUT without also | ||
234 | setting NOSIGNAL results in really weird | ||
235 | crashes on my system!*/ | ||
236 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
237 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
217 | { | 238 | { |
218 | cbc.pos = 0; | 239 | fprintf (stderr, |
219 | c = curl_easy_init (); | 240 | "curl_easy_perform failed: `%s'\n", |
220 | curl_easy_setopt (c, CURLOPT_URL, url); | 241 | curl_easy_strerror (errornum)); |
221 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
222 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
223 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
224 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
225 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
226 | if (oneone) | ||
227 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
228 | else | ||
229 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
230 | /* NOTE: use of CONNECTTIMEOUT without also | ||
231 | setting NOSIGNAL results in really weird | ||
232 | crashes on my system!*/ | ||
233 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
234 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
235 | { | ||
236 | fprintf (stderr, | ||
237 | "curl_easy_perform failed: `%s'\n", | ||
238 | curl_easy_strerror (errornum)); | ||
239 | curl_easy_cleanup (c); | ||
240 | MHD_stop_daemon (d); | ||
241 | return 2; | ||
242 | } | ||
243 | curl_easy_cleanup (c); | 242 | curl_easy_cleanup (c); |
243 | MHD_stop_daemon (d); | ||
244 | return 2; | ||
244 | } | 245 | } |
246 | curl_easy_cleanup (c); | ||
247 | } | ||
245 | stop (poll_flag == MHD_USE_AUTO ? "internal thread with 'auto'" : | 248 | stop (poll_flag == MHD_USE_AUTO ? "internal thread with 'auto'" : |
246 | poll_flag == MHD_USE_POLL ? "internal thread with poll()" : | 249 | poll_flag == MHD_USE_POLL ? "internal thread with poll()" : |
247 | poll_flag == MHD_USE_EPOLL ? "internal thread with epoll" : "internal thread with select()"); | 250 | poll_flag == MHD_USE_EPOLL ? "internal thread with epoll" : |
251 | "internal thread with select()"); | ||
248 | MHD_stop_daemon (d); | 252 | MHD_stop_daemon (d); |
249 | if (cbc.pos != strlen ("/hello_world")) | 253 | if (cbc.pos != strlen ("/hello_world")) |
250 | return 4; | 254 | return 4; |
@@ -265,61 +269,68 @@ testMultithreadedGet (int port, int poll_flag) | |||
265 | unsigned int i; | 269 | unsigned int i; |
266 | char url[64]; | 270 | char url[64]; |
267 | 271 | ||
268 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 272 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
269 | port = 0; | 273 | port = 0; |
270 | 274 | ||
271 | cbc.buf = buf; | 275 | cbc.buf = buf; |
272 | cbc.size = 2048; | 276 | cbc.size = 2048; |
273 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 277 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
278 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | ||
279 | | poll_flag, | ||
274 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 280 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
275 | if (d == NULL) | 281 | if (d == NULL) |
276 | return 16; | 282 | return 16; |
277 | if (0 == port) | 283 | if (0 == port) |
284 | { | ||
285 | const union MHD_DaemonInfo *dinfo; | ||
286 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
287 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
278 | { | 288 | { |
279 | const union MHD_DaemonInfo *dinfo; | 289 | MHD_stop_daemon (d); return 32; |
280 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
281 | if (NULL == dinfo || 0 == dinfo->port) | ||
282 | { MHD_stop_daemon (d); return 32; } | ||
283 | port = (int)dinfo->port; | ||
284 | } | 290 | } |
291 | port = (int) dinfo->port; | ||
292 | } | ||
285 | snprintf (url, | 293 | snprintf (url, |
286 | sizeof (url), | 294 | sizeof (url), |
287 | "http://127.0.0.1:%d/hello_world", | 295 | "http://127.0.0.1:%d/hello_world", |
288 | port); | 296 | port); |
289 | start_timer (); | 297 | start_timer (); |
290 | for (i=0;i<ROUNDS;i++) | 298 | for (i = 0; i<ROUNDS; i++) |
299 | { | ||
300 | cbc.pos = 0; | ||
301 | c = curl_easy_init (); | ||
302 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
303 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
304 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
305 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
306 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
307 | if (oneone) | ||
308 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
309 | else | ||
310 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
311 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
312 | /* NOTE: use of CONNECTTIMEOUT without also | ||
313 | setting NOSIGNAL results in really weird | ||
314 | crashes on my system! */ | ||
315 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
316 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
291 | { | 317 | { |
292 | cbc.pos = 0; | 318 | fprintf (stderr, |
293 | c = curl_easy_init (); | 319 | "curl_easy_perform failed: `%s'\n", |
294 | curl_easy_setopt (c, CURLOPT_URL, url); | 320 | curl_easy_strerror (errornum)); |
295 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
296 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
297 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
298 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
299 | if (oneone) | ||
300 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
301 | else | ||
302 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
303 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
304 | /* NOTE: use of CONNECTTIMEOUT without also | ||
305 | setting NOSIGNAL results in really weird | ||
306 | crashes on my system! */ | ||
307 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
308 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
309 | { | ||
310 | fprintf (stderr, | ||
311 | "curl_easy_perform failed: `%s'\n", | ||
312 | curl_easy_strerror (errornum)); | ||
313 | curl_easy_cleanup (c); | ||
314 | MHD_stop_daemon (d); | ||
315 | return 32; | ||
316 | } | ||
317 | curl_easy_cleanup (c); | 321 | curl_easy_cleanup (c); |
322 | MHD_stop_daemon (d); | ||
323 | return 32; | ||
318 | } | 324 | } |
319 | stop ((poll_flag & MHD_USE_AUTO) ? "internal thread with 'auto' and thread per connection" : | 325 | curl_easy_cleanup (c); |
320 | (poll_flag & MHD_USE_POLL) ? "internal thread with poll() and thread per connection" : | 326 | } |
321 | (poll_flag & MHD_USE_EPOLL) ? "internal thread with epoll and thread per connection" : | 327 | stop ((poll_flag & MHD_USE_AUTO) ? |
322 | "internal thread with select() and thread per connection"); | 328 | "internal thread with 'auto' and thread per connection" : |
329 | (poll_flag & MHD_USE_POLL) ? | ||
330 | "internal thread with poll() and thread per connection" : | ||
331 | (poll_flag & MHD_USE_EPOLL) ? | ||
332 | "internal thread with epoll and thread per connection" : | ||
333 | "internal thread with select() and thread per connection"); | ||
323 | MHD_stop_daemon (d); | 334 | MHD_stop_daemon (d); |
324 | if (cbc.pos != strlen ("/hello_world")) | 335 | if (cbc.pos != strlen ("/hello_world")) |
325 | return 64; | 336 | return 64; |
@@ -339,61 +350,65 @@ testMultithreadedPoolGet (int port, int poll_flag) | |||
339 | unsigned int i; | 350 | unsigned int i; |
340 | char url[64]; | 351 | char url[64]; |
341 | 352 | ||
342 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 353 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
343 | port = 0; | 354 | port = 0; |
344 | 355 | ||
345 | cbc.buf = buf; | 356 | cbc.buf = buf; |
346 | cbc.size = 2048; | 357 | cbc.size = 2048; |
347 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 358 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
359 | | poll_flag, | ||
348 | port, NULL, NULL, &ahc_echo, "GET", | 360 | port, NULL, NULL, &ahc_echo, "GET", |
349 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); | 361 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); |
350 | if (d == NULL) | 362 | if (d == NULL) |
351 | return 16; | 363 | return 16; |
352 | if (0 == port) | 364 | if (0 == port) |
365 | { | ||
366 | const union MHD_DaemonInfo *dinfo; | ||
367 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
368 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
353 | { | 369 | { |
354 | const union MHD_DaemonInfo *dinfo; | 370 | MHD_stop_daemon (d); return 32; |
355 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
356 | if (NULL == dinfo || 0 == dinfo->port) | ||
357 | { MHD_stop_daemon (d); return 32; } | ||
358 | port = (int)dinfo->port; | ||
359 | } | 371 | } |
372 | port = (int) dinfo->port; | ||
373 | } | ||
360 | snprintf (url, | 374 | snprintf (url, |
361 | sizeof (url), | 375 | sizeof (url), |
362 | "http://127.0.0.1:%d/hello_world", | 376 | "http://127.0.0.1:%d/hello_world", |
363 | port); | 377 | port); |
364 | start_timer (); | 378 | start_timer (); |
365 | for (i=0;i<ROUNDS;i++) | 379 | for (i = 0; i<ROUNDS; i++) |
380 | { | ||
381 | cbc.pos = 0; | ||
382 | c = curl_easy_init (); | ||
383 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
384 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
385 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
386 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
387 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
388 | if (oneone) | ||
389 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
390 | else | ||
391 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
392 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
393 | /* NOTE: use of CONNECTTIMEOUT without also | ||
394 | setting NOSIGNAL results in really weird | ||
395 | crashes on my system!*/ | ||
396 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
397 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
366 | { | 398 | { |
367 | cbc.pos = 0; | 399 | fprintf (stderr, |
368 | c = curl_easy_init (); | 400 | "curl_easy_perform failed: `%s'\n", |
369 | curl_easy_setopt (c, CURLOPT_URL, url); | 401 | curl_easy_strerror (errornum)); |
370 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
371 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
372 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
373 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
374 | if (oneone) | ||
375 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
376 | else | ||
377 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
378 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
379 | /* NOTE: use of CONNECTTIMEOUT without also | ||
380 | setting NOSIGNAL results in really weird | ||
381 | crashes on my system!*/ | ||
382 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
383 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
384 | { | ||
385 | fprintf (stderr, | ||
386 | "curl_easy_perform failed: `%s'\n", | ||
387 | curl_easy_strerror (errornum)); | ||
388 | curl_easy_cleanup (c); | ||
389 | MHD_stop_daemon (d); | ||
390 | return 32; | ||
391 | } | ||
392 | curl_easy_cleanup (c); | 402 | curl_easy_cleanup (c); |
403 | MHD_stop_daemon (d); | ||
404 | return 32; | ||
393 | } | 405 | } |
406 | curl_easy_cleanup (c); | ||
407 | } | ||
394 | stop (0 != (poll_flag & MHD_USE_AUTO) ? "internal thread pool with 'auto'" : | 408 | stop (0 != (poll_flag & MHD_USE_AUTO) ? "internal thread pool with 'auto'" : |
395 | 0 != (poll_flag & MHD_USE_POLL) ? "internal thread pool with poll()" : | 409 | 0 != (poll_flag & MHD_USE_POLL) ? "internal thread pool with poll()" : |
396 | 0 != (poll_flag & MHD_USE_EPOLL) ? "internal thread pool with epoll" : "internal thread pool with select()"); | 410 | 0 != (poll_flag & MHD_USE_EPOLL) ? "internal thread pool with epoll" : |
411 | "internal thread pool with select()"); | ||
397 | MHD_stop_daemon (d); | 412 | MHD_stop_daemon (d); |
398 | if (cbc.pos != strlen ("/hello_world")) | 413 | if (cbc.pos != strlen ("/hello_world")) |
399 | return 64; | 414 | return 64; |
@@ -427,7 +442,7 @@ testExternalGet (int port) | |||
427 | unsigned int i; | 442 | unsigned int i; |
428 | char url[64]; | 443 | char url[64]; |
429 | 444 | ||
430 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 445 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
431 | port = 0; | 446 | port = 0; |
432 | 447 | ||
433 | multi = NULL; | 448 | multi = NULL; |
@@ -440,13 +455,15 @@ testExternalGet (int port) | |||
440 | if (NULL == d) | 455 | if (NULL == d) |
441 | return 256; | 456 | return 256; |
442 | if (0 == port) | 457 | if (0 == port) |
458 | { | ||
459 | const union MHD_DaemonInfo *dinfo; | ||
460 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
461 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
443 | { | 462 | { |
444 | const union MHD_DaemonInfo *dinfo; | 463 | MHD_stop_daemon (d); return 32; |
445 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
446 | if (NULL == dinfo || 0 == dinfo->port) | ||
447 | { MHD_stop_daemon (d); return 32; } | ||
448 | port = (int)dinfo->port; | ||
449 | } | 464 | } |
465 | port = (int) dinfo->port; | ||
466 | } | ||
450 | snprintf (url, | 467 | snprintf (url, |
451 | sizeof (url), | 468 | sizeof (url), |
452 | "http://127.0.0.1:%d/hello_world", | 469 | "http://127.0.0.1:%d/hello_world", |
@@ -454,116 +471,119 @@ testExternalGet (int port) | |||
454 | start_timer (); | 471 | start_timer (); |
455 | multi = curl_multi_init (); | 472 | multi = curl_multi_init (); |
456 | if (multi == NULL) | 473 | if (multi == NULL) |
474 | { | ||
475 | MHD_stop_daemon (d); | ||
476 | return 512; | ||
477 | } | ||
478 | for (i = 0; i<ROUNDS; i++) | ||
479 | { | ||
480 | cbc.pos = 0; | ||
481 | c = curl_easy_init (); | ||
482 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
483 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
484 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
485 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
486 | if (oneone) | ||
487 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
488 | else | ||
489 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
490 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
491 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
492 | /* NOTE: use of CONNECTTIMEOUT without also | ||
493 | setting NOSIGNAL results in really weird | ||
494 | crashes on my system! */ | ||
495 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
496 | mret = curl_multi_add_handle (multi, c); | ||
497 | if (mret != CURLM_OK) | ||
457 | { | 498 | { |
499 | curl_multi_cleanup (multi); | ||
500 | curl_easy_cleanup (c); | ||
458 | MHD_stop_daemon (d); | 501 | MHD_stop_daemon (d); |
459 | return 512; | 502 | return 1024; |
460 | } | 503 | } |
461 | for (i=0;i<ROUNDS;i++) | 504 | start = time (NULL); |
505 | while ((time (NULL) - start < 5) && (c != NULL)) | ||
462 | { | 506 | { |
463 | cbc.pos = 0; | 507 | maxsock = MHD_INVALID_SOCKET; |
464 | c = curl_easy_init (); | 508 | maxposixs = -1; |
465 | curl_easy_setopt (c, CURLOPT_URL, url); | 509 | FD_ZERO (&rs); |
466 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 510 | FD_ZERO (&ws); |
467 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 511 | FD_ZERO (&es); |
468 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 512 | curl_multi_perform (multi, &running); |
469 | if (oneone) | 513 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); |
470 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
471 | else | ||
472 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
473 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
474 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
475 | /* NOTE: use of CONNECTTIMEOUT without also | ||
476 | setting NOSIGNAL results in really weird | ||
477 | crashes on my system! */ | ||
478 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
479 | mret = curl_multi_add_handle (multi, c); | ||
480 | if (mret != CURLM_OK) | 514 | if (mret != CURLM_OK) |
481 | { | 515 | { |
482 | curl_multi_cleanup (multi); | 516 | curl_multi_remove_handle (multi, c); |
483 | curl_easy_cleanup (c); | 517 | curl_multi_cleanup (multi); |
484 | MHD_stop_daemon (d); | 518 | curl_easy_cleanup (c); |
485 | return 1024; | 519 | MHD_stop_daemon (d); |
486 | } | 520 | return 2048; |
487 | start = time (NULL); | 521 | } |
488 | while ((time (NULL) - start < 5) && (c != NULL)) | 522 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
489 | { | 523 | { |
490 | maxsock = MHD_INVALID_SOCKET; | 524 | curl_multi_remove_handle (multi, c); |
491 | maxposixs = -1; | 525 | curl_multi_cleanup (multi); |
492 | FD_ZERO (&rs); | 526 | curl_easy_cleanup (c); |
493 | FD_ZERO (&ws); | 527 | MHD_stop_daemon (d); |
494 | FD_ZERO (&es); | 528 | return 4096; |
495 | curl_multi_perform (multi, &running); | 529 | } |
496 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | 530 | tv.tv_sec = 0; |
497 | if (mret != CURLM_OK) | 531 | tv.tv_usec = 1000; |
498 | { | 532 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) |
499 | curl_multi_remove_handle (multi, c); | 533 | { |
500 | curl_multi_cleanup (multi); | ||
501 | curl_easy_cleanup (c); | ||
502 | MHD_stop_daemon (d); | ||
503 | return 2048; | ||
504 | } | ||
505 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
506 | { | ||
507 | curl_multi_remove_handle (multi, c); | ||
508 | curl_multi_cleanup (multi); | ||
509 | curl_easy_cleanup (c); | ||
510 | MHD_stop_daemon (d); | ||
511 | return 4096; | ||
512 | } | ||
513 | tv.tv_sec = 0; | ||
514 | tv.tv_usec = 1000; | ||
515 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
516 | { | ||
517 | #ifdef MHD_POSIX_SOCKETS | 534 | #ifdef MHD_POSIX_SOCKETS |
518 | if (EINTR != errno) | 535 | if (EINTR != errno) |
519 | abort (); | 536 | abort (); |
520 | #else | 537 | #else |
521 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 538 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
522 | abort (); | 539 | ws. |
523 | Sleep (1000); | 540 | fd_count) |
541 | ||(0 != es.fd_count) ) | ||
542 | abort (); | ||
543 | Sleep (1000); | ||
524 | #endif | 544 | #endif |
525 | } | 545 | } |
526 | curl_multi_perform (multi, &running); | 546 | curl_multi_perform (multi, &running); |
527 | if (running == 0) | 547 | if (running == 0) |
528 | { | 548 | { |
529 | msg = curl_multi_info_read (multi, &running); | 549 | msg = curl_multi_info_read (multi, &running); |
530 | if (msg == NULL) | 550 | if (msg == NULL) |
531 | break; | 551 | break; |
532 | if (msg->msg == CURLMSG_DONE) | 552 | if (msg->msg == CURLMSG_DONE) |
533 | { | 553 | { |
534 | if (msg->data.result != CURLE_OK) | 554 | if (msg->data.result != CURLE_OK) |
535 | printf ("%s failed at %s:%d: `%s'\n", | 555 | printf ("%s failed at %s:%d: `%s'\n", |
536 | "curl_multi_perform", | 556 | "curl_multi_perform", |
537 | __FILE__, | 557 | __FILE__, |
538 | __LINE__, curl_easy_strerror (msg->data.result)); | 558 | __LINE__, curl_easy_strerror (msg->data.result)); |
539 | curl_multi_remove_handle (multi, c); | 559 | curl_multi_remove_handle (multi, c); |
540 | curl_easy_cleanup (c); | 560 | curl_easy_cleanup (c); |
541 | c = NULL; | 561 | c = NULL; |
542 | } | 562 | } |
543 | } | 563 | } |
544 | /* two possibilities here; as select sets are | 564 | /* two possibilities here; as select sets are |
545 | tiny, this makes virtually no difference | 565 | tiny, this makes virtually no difference |
546 | in actual runtime right now, even though the | 566 | in actual runtime right now, even though the |
547 | number of select calls is virtually cut in half | 567 | number of select calls is virtually cut in half |
548 | (and 'select' is the most expensive of our system | 568 | (and 'select' is the most expensive of our system |
549 | calls according to 'strace') */ | 569 | calls according to 'strace') */ |
550 | if (0) | 570 | if (0) |
551 | MHD_run (d); | 571 | MHD_run (d); |
552 | else | 572 | else |
553 | MHD_run_from_select (d, &rs, &ws, &es); | 573 | MHD_run_from_select (d, &rs, &ws, &es); |
554 | } | ||
555 | if (NULL != c) | ||
556 | { | ||
557 | curl_multi_remove_handle (multi, c); | ||
558 | curl_easy_cleanup (c); | ||
559 | fprintf (stderr, "Timeout!?\n"); | ||
560 | } | ||
561 | } | 574 | } |
562 | stop ("external select"); | 575 | if (NULL != c) |
563 | if (multi != NULL) | ||
564 | { | 576 | { |
565 | curl_multi_cleanup (multi); | 577 | curl_multi_remove_handle (multi, c); |
578 | curl_easy_cleanup (c); | ||
579 | fprintf (stderr, "Timeout!?\n"); | ||
566 | } | 580 | } |
581 | } | ||
582 | stop ("external select"); | ||
583 | if (multi != NULL) | ||
584 | { | ||
585 | curl_multi_cleanup (multi); | ||
586 | } | ||
567 | MHD_stop_daemon (d); | 587 | MHD_stop_daemon (d); |
568 | if (cbc.pos != strlen ("/hello_world")) | 588 | if (cbc.pos != strlen ("/hello_world")) |
569 | return 8192; | 589 | return 8192; |
@@ -578,9 +598,9 @@ main (int argc, char *const *argv) | |||
578 | { | 598 | { |
579 | unsigned int errorCount = 0; | 599 | unsigned int errorCount = 0; |
580 | int port = 1130; | 600 | int port = 1130; |
581 | (void)argc; /* Unused. Silent compiler warning. */ | 601 | (void) argc; /* Unused. Silent compiler warning. */ |
582 | 602 | ||
583 | if (NULL == argv || 0 == argv[0]) | 603 | if ((NULL == argv)||(0 == argv[0])) |
584 | return 99; | 604 | return 99; |
585 | oneone = has_in_name (argv[0], "11"); | 605 | oneone = has_in_name (argv[0], "11"); |
586 | if (oneone) | 606 | if (oneone) |
@@ -588,29 +608,29 @@ main (int argc, char *const *argv) | |||
588 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 608 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
589 | return 2; | 609 | return 2; |
590 | response = MHD_create_response_from_buffer (strlen ("/hello_world"), | 610 | response = MHD_create_response_from_buffer (strlen ("/hello_world"), |
591 | "/hello_world", | 611 | "/hello_world", |
592 | MHD_RESPMEM_MUST_COPY); | 612 | MHD_RESPMEM_MUST_COPY); |
593 | errorCount += testExternalGet (port++); | 613 | errorCount += testExternalGet (port++); |
594 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 614 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
615 | { | ||
616 | errorCount += testInternalGet (port++, MHD_USE_AUTO); | ||
617 | errorCount += testMultithreadedGet (port++, MHD_USE_AUTO); | ||
618 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO); | ||
619 | errorCount += testInternalGet (port++, 0); | ||
620 | errorCount += testMultithreadedGet (port++, 0); | ||
621 | errorCount += testMultithreadedPoolGet (port++, 0); | ||
622 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL)) | ||
623 | { | ||
624 | errorCount += testInternalGet (port++, MHD_USE_POLL); | ||
625 | errorCount += testMultithreadedGet (port++, MHD_USE_POLL); | ||
626 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_POLL); | ||
627 | } | ||
628 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL)) | ||
595 | { | 629 | { |
596 | errorCount += testInternalGet (port++, MHD_USE_AUTO); | 630 | errorCount += testInternalGet (port++, MHD_USE_EPOLL); |
597 | errorCount += testMultithreadedGet (port++, MHD_USE_AUTO); | 631 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_EPOLL); |
598 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO); | ||
599 | errorCount += testInternalGet (port++, 0); | ||
600 | errorCount += testMultithreadedGet (port++, 0); | ||
601 | errorCount += testMultithreadedPoolGet (port++, 0); | ||
602 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL)) | ||
603 | { | ||
604 | errorCount += testInternalGet(port++, MHD_USE_POLL); | ||
605 | errorCount += testMultithreadedGet(port++, MHD_USE_POLL); | ||
606 | errorCount += testMultithreadedPoolGet(port++, MHD_USE_POLL); | ||
607 | } | ||
608 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL)) | ||
609 | { | ||
610 | errorCount += testInternalGet(port++, MHD_USE_EPOLL); | ||
611 | errorCount += testMultithreadedPoolGet(port++, MHD_USE_EPOLL); | ||
612 | } | ||
613 | } | 632 | } |
633 | } | ||
614 | MHD_destroy_response (response); | 634 | MHD_destroy_response (response); |
615 | if (errorCount != 0) | 635 | if (errorCount != 0) |
616 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 636 | fprintf (stderr, "Error (code: %u)\n", errorCount); |