aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_post_loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_post_loop.c')
-rw-r--r--src/testcurl/test_post_loop.c692
1 files changed, 356 insertions, 336 deletions
diff --git a/src/testcurl/test_post_loop.c b/src/testcurl/test_post_loop.c
index 6da54a95..558228a2 100644
--- a/src/testcurl/test_post_loop.c
+++ b/src/testcurl/test_post_loop.c
@@ -38,14 +38,15 @@
38#include <unistd.h> 38#include <unistd.h>
39#endif 39#endif
40 40
41#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 41#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
42#undef CPU_COUNT 42#undef CPU_COUNT
43#endif 43#endif
44#if !defined(CPU_COUNT) 44#if ! defined(CPU_COUNT)
45#define CPU_COUNT 2 45#define CPU_COUNT 2
46#endif 46#endif
47 47
48#define POST_DATA "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n" 48#define POST_DATA \
49 "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n"
49 50
50#define LOOPCOUNT 1000 51#define LOOPCOUNT 1000
51 52
@@ -82,25 +83,25 @@ ahc_echo (void *cls,
82 static int marker; 83 static int marker;
83 struct MHD_Response *response; 84 struct MHD_Response *response;
84 int ret; 85 int ret;
85 (void)cls;(void)url;(void)version; /* Unused. Silent compiler warning. */ 86 (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */
86 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 87 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
87 88
88 if (0 != strcmp ("POST", method)) 89 if (0 != strcmp ("POST", method))
89 { 90 {
90 printf ("METHOD: %s\n", method); 91 printf ("METHOD: %s\n", method);
91 return MHD_NO; /* unexpected method */ 92 return MHD_NO; /* unexpected method */
92 } 93 }
93 if ((*mptr != NULL) && (0 == *upload_data_size)) 94 if ((*mptr != NULL) && (0 == *upload_data_size))
94 { 95 {
95 if (*mptr != &marker) 96 if (*mptr != &marker)
96 abort (); 97 abort ();
97 response = MHD_create_response_from_buffer (2, "OK", 98 response = MHD_create_response_from_buffer (2, "OK",
98 MHD_RESPMEM_PERSISTENT); 99 MHD_RESPMEM_PERSISTENT);
99 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 100 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
100 MHD_destroy_response (response); 101 MHD_destroy_response (response);
101 *mptr = NULL; 102 *mptr = NULL;
102 return ret; 103 return ret;
103 } 104 }
104 if (strlen (POST_DATA) != *upload_data_size) 105 if (strlen (POST_DATA) != *upload_data_size)
105 return MHD_YES; 106 return MHD_YES;
106 *upload_data_size = 0; 107 *upload_data_size = 0;
@@ -124,11 +125,11 @@ testInternalPost ()
124 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 125 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
125 port = 0; 126 port = 0;
126 else 127 else
127 { 128 {
128 port = 1350; 129 port = 1350;
129 if (oneone) 130 if (oneone)
130 port += 10; 131 port += 10;
131 } 132 }
132 133
133 cbc.buf = buf; 134 cbc.buf = buf;
134 cbc.size = 2048; 135 cbc.size = 2048;
@@ -137,58 +138,60 @@ testInternalPost ()
137 if (d == NULL) 138 if (d == NULL)
138 return 1; 139 return 1;
139 if (0 == port) 140 if (0 == port)
141 {
142 const union MHD_DaemonInfo *dinfo;
143 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
144 if ((NULL == dinfo) ||(0 == dinfo->port) )
140 { 145 {
141 const union MHD_DaemonInfo *dinfo; 146 MHD_stop_daemon (d); return 32;
142 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
143 if (NULL == dinfo || 0 == dinfo->port)
144 { MHD_stop_daemon (d); return 32; }
145 port = (int)dinfo->port;
146 } 147 }
148 port = (int) dinfo->port;
149 }
147 for (i = 0; i < LOOPCOUNT; i++) 150 for (i = 0; i < LOOPCOUNT; i++)
151 {
152 if (99 == i % 100)
153 fprintf (stderr, ".");
154 c = curl_easy_init ();
155 cbc.pos = 0;
156 buf[0] = '\0';
157 snprintf (url,
158 sizeof (url),
159 "http://127.0.0.1:%d/hw%d",
160 port,
161 i);
162 curl_easy_setopt (c, CURLOPT_URL, url);
163 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
164 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
165 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
166 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
167 curl_easy_setopt (c, CURLOPT_POST, 1L);
168 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
169 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
170 if (oneone)
171 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
172 else
173 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
174 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
175 /* NOTE: use of CONNECTTIMEOUT without also
176 * setting NOSIGNAL results in really weird
177 * crashes on my system! */
178 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
179 if (CURLE_OK != (errornum = curl_easy_perform (c)))
148 { 180 {
149 if (99 == i % 100) 181 fprintf (stderr,
150 fprintf (stderr, "."); 182 "curl_easy_perform failed: `%s'\n",
151 c = curl_easy_init (); 183 curl_easy_strerror (errornum));
152 cbc.pos = 0;
153 buf[0] = '\0';
154 snprintf (url,
155 sizeof (url),
156 "http://127.0.0.1:%d/hw%d",
157 port,
158 i);
159 curl_easy_setopt (c, CURLOPT_URL, url);
160 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
161 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
162 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
163 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
164 curl_easy_setopt (c, CURLOPT_POST, 1L);
165 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
166 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
167 if (oneone)
168 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
169 else
170 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
171 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
172 /* NOTE: use of CONNECTTIMEOUT without also
173 * setting NOSIGNAL results in really weird
174 * crashes on my system! */
175 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
176 if (CURLE_OK != (errornum = curl_easy_perform (c)))
177 {
178 fprintf (stderr,
179 "curl_easy_perform failed: `%s'\n",
180 curl_easy_strerror (errornum));
181 curl_easy_cleanup (c);
182 MHD_stop_daemon (d);
183 return 2;
184 }
185 curl_easy_cleanup (c); 184 curl_easy_cleanup (c);
186 if ((buf[0] != 'O') || (buf[1] != 'K')) 185 MHD_stop_daemon (d);
187 { 186 return 2;
188 MHD_stop_daemon (d); 187 }
189 return 4; 188 curl_easy_cleanup (c);
190 } 189 if ((buf[0] != 'O') || (buf[1] != 'K'))
190 {
191 MHD_stop_daemon (d);
192 return 4;
191 } 193 }
194 }
192 MHD_stop_daemon (d); 195 MHD_stop_daemon (d);
193 if (LOOPCOUNT >= 99) 196 if (LOOPCOUNT >= 99)
194 fprintf (stderr, "\n"); 197 fprintf (stderr, "\n");
@@ -210,73 +213,76 @@ testMultithreadedPost ()
210 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 213 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
211 port = 0; 214 port = 0;
212 else 215 else
213 { 216 {
214 port = 1351; 217 port = 1351;
215 if (oneone) 218 if (oneone)
216 port += 10; 219 port += 10;
217 } 220 }
218 221
219 cbc.buf = buf; 222 cbc.buf = buf;
220 cbc.size = 2048; 223 cbc.size = 2048;
221 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 224 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
225 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
222 port, NULL, NULL, 226 port, NULL, NULL,
223 &ahc_echo, NULL, 227 &ahc_echo, NULL,
224 MHD_OPTION_END); 228 MHD_OPTION_END);
225 if (d == NULL) 229 if (d == NULL)
226 return 16; 230 return 16;
227 if (0 == port) 231 if (0 == port)
232 {
233 const union MHD_DaemonInfo *dinfo;
234 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
235 if ((NULL == dinfo) ||(0 == dinfo->port) )
228 { 236 {
229 const union MHD_DaemonInfo *dinfo; 237 MHD_stop_daemon (d); return 32;
230 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
231 if (NULL == dinfo || 0 == dinfo->port)
232 { MHD_stop_daemon (d); return 32; }
233 port = (int)dinfo->port;
234 } 238 }
239 port = (int) dinfo->port;
240 }
235 for (i = 0; i < LOOPCOUNT; i++) 241 for (i = 0; i < LOOPCOUNT; i++)
242 {
243 if (99 == i % 100)
244 fprintf (stderr, ".");
245 c = curl_easy_init ();
246 cbc.pos = 0;
247 buf[0] = '\0';
248 snprintf (url,
249 sizeof (url),
250 "http://127.0.0.1:%d/hw%d",
251 port,
252 i);
253 curl_easy_setopt (c, CURLOPT_URL, url);
254 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
255 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
256 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
257 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
258 curl_easy_setopt (c, CURLOPT_POST, 1L);
259 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
260 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
261 if (oneone)
262 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
263 else
264 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
265 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
266 /* NOTE: use of CONNECTTIMEOUT without also
267 * setting NOSIGNAL results in really weird
268 * crashes on my system! */
269 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
270 if (CURLE_OK != (errornum = curl_easy_perform (c)))
236 { 271 {
237 if (99 == i % 100) 272 fprintf (stderr,
238 fprintf (stderr, "."); 273 "curl_easy_perform failed: `%s'\n",
239 c = curl_easy_init (); 274 curl_easy_strerror (errornum));
240 cbc.pos = 0;
241 buf[0] = '\0';
242 snprintf (url,
243 sizeof (url),
244 "http://127.0.0.1:%d/hw%d",
245 port,
246 i);
247 curl_easy_setopt (c, CURLOPT_URL, url);
248 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
249 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
250 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
251 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
252 curl_easy_setopt (c, CURLOPT_POST, 1L);
253 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
254 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
255 if (oneone)
256 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
257 else
258 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
259 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
260 /* NOTE: use of CONNECTTIMEOUT without also
261 * setting NOSIGNAL results in really weird
262 * crashes on my system! */
263 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
264 if (CURLE_OK != (errornum = curl_easy_perform (c)))
265 {
266 fprintf (stderr,
267 "curl_easy_perform failed: `%s'\n",
268 curl_easy_strerror (errornum));
269 curl_easy_cleanup (c);
270 MHD_stop_daemon (d);
271 return 32;
272 }
273 curl_easy_cleanup (c); 275 curl_easy_cleanup (c);
274 if ((buf[0] != 'O') || (buf[1] != 'K')) 276 MHD_stop_daemon (d);
275 { 277 return 32;
276 MHD_stop_daemon (d); 278 }
277 return 64; 279 curl_easy_cleanup (c);
278 } 280 if ((buf[0] != 'O') || (buf[1] != 'K'))
281 {
282 MHD_stop_daemon (d);
283 return 64;
279 } 284 }
285 }
280 MHD_stop_daemon (d); 286 MHD_stop_daemon (d);
281 if (LOOPCOUNT >= 99) 287 if (LOOPCOUNT >= 99)
282 fprintf (stderr, "\n"); 288 fprintf (stderr, "\n");
@@ -298,11 +304,11 @@ testMultithreadedPoolPost ()
298 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 304 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
299 port = 0; 305 port = 0;
300 else 306 else
301 { 307 {
302 port = 1352; 308 port = 1352;
303 if (oneone) 309 if (oneone)
304 port += 10; 310 port += 10;
305 } 311 }
306 312
307 cbc.buf = buf; 313 cbc.buf = buf;
308 cbc.size = 2048; 314 cbc.size = 2048;
@@ -312,58 +318,60 @@ testMultithreadedPoolPost ()
312 if (d == NULL) 318 if (d == NULL)
313 return 16; 319 return 16;
314 if (0 == port) 320 if (0 == port)
321 {
322 const union MHD_DaemonInfo *dinfo;
323 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
324 if ((NULL == dinfo) ||(0 == dinfo->port) )
315 { 325 {
316 const union MHD_DaemonInfo *dinfo; 326 MHD_stop_daemon (d); return 32;
317 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
318 if (NULL == dinfo || 0 == dinfo->port)
319 { MHD_stop_daemon (d); return 32; }
320 port = (int)dinfo->port;
321 } 327 }
328 port = (int) dinfo->port;
329 }
322 for (i = 0; i < LOOPCOUNT; i++) 330 for (i = 0; i < LOOPCOUNT; i++)
331 {
332 if (99 == i % 100)
333 fprintf (stderr, ".");
334 c = curl_easy_init ();
335 cbc.pos = 0;
336 buf[0] = '\0';
337 snprintf (url,
338 sizeof (url),
339 "http://127.0.0.1:%d/hw%d",
340 port,
341 i);
342 curl_easy_setopt (c, CURLOPT_URL, url);
343 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
344 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
345 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
346 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
347 curl_easy_setopt (c, CURLOPT_POST, 1L);
348 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
349 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
350 if (oneone)
351 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
352 else
353 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
354 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
355 /* NOTE: use of CONNECTTIMEOUT without also
356 * setting NOSIGNAL results in really weird
357 * crashes on my system! */
358 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
359 if (CURLE_OK != (errornum = curl_easy_perform (c)))
323 { 360 {
324 if (99 == i % 100) 361 fprintf (stderr,
325 fprintf (stderr, "."); 362 "curl_easy_perform failed: `%s'\n",
326 c = curl_easy_init (); 363 curl_easy_strerror (errornum));
327 cbc.pos = 0;
328 buf[0] = '\0';
329 snprintf (url,
330 sizeof (url),
331 "http://127.0.0.1:%d/hw%d",
332 port,
333 i);
334 curl_easy_setopt (c, CURLOPT_URL, url);
335 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
336 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
337 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
338 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
339 curl_easy_setopt (c, CURLOPT_POST, 1L);
340 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
341 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
342 if (oneone)
343 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
344 else
345 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
346 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
347 /* NOTE: use of CONNECTTIMEOUT without also
348 * setting NOSIGNAL results in really weird
349 * crashes on my system! */
350 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
351 if (CURLE_OK != (errornum = curl_easy_perform (c)))
352 {
353 fprintf (stderr,
354 "curl_easy_perform failed: `%s'\n",
355 curl_easy_strerror (errornum));
356 curl_easy_cleanup (c);
357 MHD_stop_daemon (d);
358 return 32;
359 }
360 curl_easy_cleanup (c); 364 curl_easy_cleanup (c);
361 if ((buf[0] != 'O') || (buf[1] != 'K')) 365 MHD_stop_daemon (d);
362 { 366 return 32;
363 MHD_stop_daemon (d); 367 }
364 return 64; 368 curl_easy_cleanup (c);
365 } 369 if ((buf[0] != 'O') || (buf[1] != 'K'))
370 {
371 MHD_stop_daemon (d);
372 return 64;
366 } 373 }
374 }
367 MHD_stop_daemon (d); 375 MHD_stop_daemon (d);
368 if (LOOPCOUNT >= 99) 376 if (LOOPCOUNT >= 99)
369 fprintf (stderr, "\n"); 377 fprintf (stderr, "\n");
@@ -401,11 +409,11 @@ testExternalPost ()
401 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 409 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
402 port = 0; 410 port = 0;
403 else 411 else
404 { 412 {
405 port = 1353; 413 port = 1353;
406 if (oneone) 414 if (oneone)
407 port += 10; 415 port += 10;
408 } 416 }
409 417
410 multi = NULL; 418 multi = NULL;
411 cbc.buf = buf; 419 cbc.buf = buf;
@@ -416,134 +424,138 @@ testExternalPost ()
416 if (d == NULL) 424 if (d == NULL)
417 return 256; 425 return 256;
418 if (0 == port) 426 if (0 == port)
427 {
428 const union MHD_DaemonInfo *dinfo;
429 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
430 if ((NULL == dinfo) ||(0 == dinfo->port) )
419 { 431 {
420 const union MHD_DaemonInfo *dinfo; 432 MHD_stop_daemon (d); return 32;
421 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
422 if (NULL == dinfo || 0 == dinfo->port)
423 { MHD_stop_daemon (d); return 32; }
424 port = (int)dinfo->port;
425 } 433 }
434 port = (int) dinfo->port;
435 }
426 multi = curl_multi_init (); 436 multi = curl_multi_init ();
427 if (multi == NULL) 437 if (multi == NULL)
438 {
439 MHD_stop_daemon (d);
440 return 512;
441 }
442 for (i = 0; i < LOOPCOUNT; i++)
443 {
444 if (99 == i % 100)
445 fprintf (stderr, ".");
446 c = curl_easy_init ();
447 cbc.pos = 0;
448 buf[0] = '\0';
449 snprintf (url,
450 sizeof (url),
451 "http://127.0.0.1:%d/hw%d",
452 port,
453 i);
454 curl_easy_setopt (c, CURLOPT_URL, url);
455 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
456 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
457 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
458 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
459 curl_easy_setopt (c, CURLOPT_POST, 1L);
460 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
461 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
462 if (oneone)
463 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
464 else
465 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
466 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
467 /* NOTE: use of CONNECTTIMEOUT without also
468 * setting NOSIGNAL results in really weird
469 * crashes on my system! */
470 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
471 mret = curl_multi_add_handle (multi, c);
472 if (mret != CURLM_OK)
428 { 473 {
474 curl_multi_cleanup (multi);
475 curl_easy_cleanup (c);
429 MHD_stop_daemon (d); 476 MHD_stop_daemon (d);
430 return 512; 477 return 1024;
431 } 478 }
432 for (i = 0; i < LOOPCOUNT; i++) 479 start = time (NULL);
480 while ((time (NULL) - start < 5) && (multi != NULL))
433 { 481 {
434 if (99 == i % 100) 482 maxsock = MHD_INVALID_SOCKET;
435 fprintf (stderr, "."); 483 maxposixs = -1;
436 c = curl_easy_init (); 484 FD_ZERO (&rs);
437 cbc.pos = 0; 485 FD_ZERO (&ws);
438 buf[0] = '\0'; 486 FD_ZERO (&es);
439 snprintf (url, 487 while (CURLM_CALL_MULTI_PERFORM ==
440 sizeof (url), 488 curl_multi_perform (multi, &running))
441 "http://127.0.0.1:%d/hw%d", 489 ;
442 port, 490 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
443 i);
444 curl_easy_setopt (c, CURLOPT_URL, url);
445 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
446 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
447 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
448 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
449 curl_easy_setopt (c, CURLOPT_POST, 1L);
450 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
451 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
452 if (oneone)
453 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
454 else
455 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
456 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
457 /* NOTE: use of CONNECTTIMEOUT without also
458 * setting NOSIGNAL results in really weird
459 * crashes on my system! */
460 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
461 mret = curl_multi_add_handle (multi, c);
462 if (mret != CURLM_OK) 491 if (mret != CURLM_OK)
492 {
493 curl_multi_remove_handle (multi, c);
494 curl_multi_cleanup (multi);
495 curl_easy_cleanup (c);
496 MHD_stop_daemon (d);
497 return 2048;
498 }
499 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
500 {
501 curl_multi_remove_handle (multi, c);
502 curl_multi_cleanup (multi);
503 curl_easy_cleanup (c);
504 MHD_stop_daemon (d);
505 return 4096;
506 }
507 if (MHD_NO == MHD_get_timeout (d, &timeout))
508 timeout = 100; /* 100ms == INFTY -- CURL bug... */
509 if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) &&
510 (ctimeout < (long long) timeout) && (ctimeout >= 0))
511 timeout = ctimeout;
512 if ( (c == NULL) || (running == 0) )
513 timeout = 0; /* terminate quickly... */
514 tv.tv_sec = timeout / 1000;
515 tv.tv_usec = (timeout % 1000) * 1000;
516 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
517 {
518 if (EINTR == errno)
519 continue;
520 fprintf (stderr,
521 "select failed: %s\n",
522 strerror (errno));
523 break;
524 }
525 while (CURLM_CALL_MULTI_PERFORM ==
526 curl_multi_perform (multi, &running))
527 ;
528 if (running == 0)
529 {
530 msg = curl_multi_info_read (multi, &running);
531 if (msg == NULL)
532 break;
533 if (msg->msg == CURLMSG_DONE)
463 { 534 {
464 curl_multi_cleanup (multi); 535 if (msg->data.result != CURLE_OK)
465 curl_easy_cleanup (c); 536 printf ("%s failed at %s:%d: `%s'\n",
466 MHD_stop_daemon (d); 537 "curl_multi_perform",
467 return 1024; 538 __FILE__,
468 } 539 __LINE__, curl_easy_strerror (msg->data.result));
469 start = time (NULL);
470 while ((time (NULL) - start < 5) && (multi != NULL))
471 {
472 maxsock = MHD_INVALID_SOCKET;
473 maxposixs = -1;
474 FD_ZERO (&rs);
475 FD_ZERO (&ws);
476 FD_ZERO (&es);
477 while (CURLM_CALL_MULTI_PERFORM ==
478 curl_multi_perform (multi, &running));
479 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
480 if (mret != CURLM_OK)
481 {
482 curl_multi_remove_handle (multi, c);
483 curl_multi_cleanup (multi);
484 curl_easy_cleanup (c);
485 MHD_stop_daemon (d);
486 return 2048;
487 }
488 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
489 {
490 curl_multi_remove_handle (multi, c);
491 curl_multi_cleanup (multi);
492 curl_easy_cleanup (c);
493 MHD_stop_daemon (d);
494 return 4096;
495 }
496 if (MHD_NO == MHD_get_timeout (d, &timeout))
497 timeout = 100; /* 100ms == INFTY -- CURL bug... */
498 if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) &&
499 (ctimeout < (long long)timeout) && (ctimeout >= 0))
500 timeout = ctimeout;
501 if ( (c == NULL) || (running == 0) )
502 timeout = 0; /* terminate quickly... */
503 tv.tv_sec = timeout / 1000;
504 tv.tv_usec = (timeout % 1000) * 1000;
505 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
506 {
507 if (EINTR == errno)
508 continue;
509 fprintf (stderr,
510 "select failed: %s\n",
511 strerror (errno));
512 break;
513 }
514 while (CURLM_CALL_MULTI_PERFORM ==
515 curl_multi_perform (multi, &running));
516 if (running == 0)
517 {
518 msg = curl_multi_info_read (multi, &running);
519 if (msg == NULL)
520 break;
521 if (msg->msg == CURLMSG_DONE)
522 {
523 if (msg->data.result != CURLE_OK)
524 printf ("%s failed at %s:%d: `%s'\n",
525 "curl_multi_perform",
526 __FILE__,
527 __LINE__, curl_easy_strerror (msg->data.result));
528 curl_multi_remove_handle (multi, c);
529 curl_easy_cleanup (c);
530 c = NULL;
531 }
532 }
533 MHD_run (d);
534 }
535 if (c != NULL)
536 {
537 curl_multi_remove_handle (multi, c); 540 curl_multi_remove_handle (multi, c);
538 curl_easy_cleanup (c); 541 curl_easy_cleanup (c);
542 c = NULL;
539 } 543 }
540 if ((buf[0] != 'O') || (buf[1] != 'K')) 544 }
541 { 545 MHD_run (d);
542 curl_multi_cleanup (multi);
543 MHD_stop_daemon (d);
544 return 8192;
545 }
546 } 546 }
547 if (c != NULL)
548 {
549 curl_multi_remove_handle (multi, c);
550 curl_easy_cleanup (c);
551 }
552 if ((buf[0] != 'O') || (buf[1] != 'K'))
553 {
554 curl_multi_cleanup (multi);
555 MHD_stop_daemon (d);
556 return 8192;
557 }
558 }
547 curl_multi_cleanup (multi); 559 curl_multi_cleanup (multi);
548 MHD_stop_daemon (d); 560 MHD_stop_daemon (d);
549 if (LOOPCOUNT >= 99) 561 if (LOOPCOUNT >= 99)
@@ -569,8 +581,8 @@ now ()
569 struct timeval tv; 581 struct timeval tv;
570 582
571 gettimeofday (&tv, NULL); 583 gettimeofday (&tv, NULL);
572 return (((unsigned long long) tv.tv_sec * 1000LL) + 584 return (((unsigned long long) tv.tv_sec * 1000LL)
573 ((unsigned long long) tv.tv_usec / 1000LL)); 585 + ((unsigned long long) tv.tv_usec / 1000LL));
574} 586}
575 587
576 588
@@ -578,56 +590,64 @@ int
578main (int argc, char *const *argv) 590main (int argc, char *const *argv)
579{ 591{
580 unsigned int errorCount = 0; 592 unsigned int errorCount = 0;
581 (void)argc; /* Unused. Silent compiler warning. */ 593 (void) argc; /* Unused. Silent compiler warning. */
582 594
583 if (NULL == argv || 0 == argv[0]) 595 if ((NULL == argv)||(0 == argv[0]))
584 return 99; 596 return 99;
585 oneone = has_in_name (argv[0], "11"); 597 oneone = has_in_name (argv[0], "11");
586 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 598 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
587 return 2; 599 return 2;
588 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 600 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
589 { 601 {
590 start_time = now(); 602 start_time = now ();
591 errorCount += testInternalPost (); 603 errorCount += testInternalPost ();
592 fprintf (stderr, 604 fprintf (stderr,
593 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", 605 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" :
594 "internal select", 606 "%s: Sequential POSTs (http/1.0) %f/s\n",
595 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); 607 "internal select",
596 GAUGER ("internal select", 608 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0));
597 oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", 609 GAUGER ("internal select",
598 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), 610 oneone ? "Sequential POSTs (http/1.1)" :
599 "requests/s"); 611 "Sequential POSTs (http/1.0)",
600 start_time = now(); 612 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0),
601 errorCount += testMultithreadedPost (); 613 "requests/s");
602 fprintf (stderr, 614 start_time = now ();
603 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", 615 errorCount += testMultithreadedPost ();
604 "multithreaded post", 616 fprintf (stderr,
605 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); 617 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" :
606 GAUGER ("Multithreaded select", 618 "%s: Sequential POSTs (http/1.0) %f/s\n",
607 oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", 619 "multithreaded post",
608 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), 620 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0));
609 "requests/s"); 621 GAUGER ("Multithreaded select",
610 start_time = now(); 622 oneone ? "Sequential POSTs (http/1.1)" :
611 errorCount += testMultithreadedPoolPost (); 623 "Sequential POSTs (http/1.0)",
612 fprintf (stderr, 624 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0),
613 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", 625 "requests/s");
614 "thread with pool", 626 start_time = now ();
615 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); 627 errorCount += testMultithreadedPoolPost ();
616 GAUGER ("thread with pool", 628 fprintf (stderr,
617 oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", 629 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" :
618 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), 630 "%s: Sequential POSTs (http/1.0) %f/s\n",
619 "requests/s"); 631 "thread with pool",
620 } 632 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0));
621 start_time = now(); 633 GAUGER ("thread with pool",
634 oneone ? "Sequential POSTs (http/1.1)" :
635 "Sequential POSTs (http/1.0)",
636 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0),
637 "requests/s");
638 }
639 start_time = now ();
622 errorCount += testExternalPost (); 640 errorCount += testExternalPost ();
623 fprintf (stderr, 641 fprintf (stderr,
624 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", 642 oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" :
625 "external select", 643 "%s: Sequential POSTs (http/1.0) %f/s\n",
626 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); 644 "external select",
645 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0));
627 GAUGER ("external select", 646 GAUGER ("external select",
628 oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", 647 oneone ? "Sequential POSTs (http/1.1)" :
629 (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), 648 "Sequential POSTs (http/1.0)",
630 "requests/s"); 649 (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0),
650 "requests/s");
631 if (errorCount != 0) 651 if (errorCount != 0)
632 fprintf (stderr, "Error (code: %u)\n", errorCount); 652 fprintf (stderr, "Error (code: %u)\n", errorCount);
633 curl_global_cleanup (); 653 curl_global_cleanup ();