aboutsummaryrefslogtreecommitdiff
path: root/src/testzzuf/test_post_form.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testzzuf/test_post_form.c')
-rw-r--r--src/testzzuf/test_post_form.c342
1 files changed, 172 insertions, 170 deletions
diff --git a/src/testzzuf/test_post_form.c b/src/testzzuf/test_post_form.c
index cbe55b5d..d7c2fad3 100644
--- a/src/testzzuf/test_post_form.c
+++ b/src/testzzuf/test_post_form.c
@@ -51,12 +51,12 @@ struct CBC
51 51
52static void 52static void
53completed_cb (void *cls, 53completed_cb (void *cls,
54 struct MHD_Connection *connection, 54 struct MHD_Connection *connection,
55 void **con_cls, 55 void **con_cls,
56 enum MHD_RequestTerminationCode toe) 56 enum MHD_RequestTerminationCode toe)
57{ 57{
58 struct MHD_PostProcessor *pp = *con_cls; 58 struct MHD_PostProcessor *pp = *con_cls;
59 (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ 59 (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */
60 60
61 if (NULL != pp) 61 if (NULL != pp)
62 MHD_destroy_post_processor (pp); 62 MHD_destroy_post_processor (pp);
@@ -91,8 +91,8 @@ post_iterator (void *cls,
91 const char *value, uint64_t off, size_t size) 91 const char *value, uint64_t off, size_t size)
92{ 92{
93 int *eok = cls; 93 int *eok = cls;
94 (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ 94 (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
95 (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ 95 (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */
96 96
97 if (key == NULL) 97 if (key == NULL)
98 return MHD_YES; 98 return MHD_YES;
@@ -122,33 +122,33 @@ ahc_echo (void *cls,
122 struct MHD_Response *response; 122 struct MHD_Response *response;
123 struct MHD_PostProcessor *pp; 123 struct MHD_PostProcessor *pp;
124 int ret; 124 int ret;
125 (void)cls;(void)version; /* Unused. Silent compiler warning. */ 125 (void) cls; (void) version; /* Unused. Silent compiler warning. */
126 126
127 if (0 != strcmp ("POST", method)) 127 if (0 != strcmp ("POST", method))
128 { 128 {
129 return MHD_NO; /* unexpected method */ 129 return MHD_NO; /* unexpected method */
130 } 130 }
131 pp = *unused; 131 pp = *unused;
132 if (pp == NULL) 132 if (pp == NULL)
133 { 133 {
134 eok = 0; 134 eok = 0;
135 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 135 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
136 if (pp == NULL) 136 if (pp == NULL)
137 return MHD_NO; 137 return MHD_NO;
138 *unused = pp; 138 *unused = pp;
139 } 139 }
140 MHD_post_process (pp, upload_data, *upload_data_size); 140 MHD_post_process (pp, upload_data, *upload_data_size);
141 if ((eok == 3) && (0 == *upload_data_size)) 141 if ((eok == 3) && (0 == *upload_data_size))
142 { 142 {
143 response = MHD_create_response_from_buffer (strlen (url), 143 response = MHD_create_response_from_buffer (strlen (url),
144 (void *) url, 144 (void *) url,
145 MHD_RESPMEM_MUST_COPY); 145 MHD_RESPMEM_MUST_COPY);
146 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 146 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
147 MHD_destroy_response (response); 147 MHD_destroy_response (response);
148 MHD_destroy_post_processor (pp); 148 MHD_destroy_post_processor (pp);
149 *unused = NULL; 149 *unused = NULL;
150 return ret; 150 return ret;
151 } 151 }
152 *upload_data_size = 0; 152 *upload_data_size = 0;
153 return MHD_YES; 153 return MHD_YES;
154} 154}
@@ -180,37 +180,38 @@ testInternalPost ()
180 cbc.buf = buf; 180 cbc.buf = buf;
181 cbc.size = 2048; 181 cbc.size = 2048;
182 cbc.pos = 0; 182 cbc.pos = 0;
183 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 183 d = MHD_start_daemon (
184 11080, NULL, NULL, &ahc_echo, NULL, 184 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
185 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 185 11080, NULL, NULL, &ahc_echo, NULL,
186 MHD_OPTION_END); 186 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
187 MHD_OPTION_END);
187 if (d == NULL) 188 if (d == NULL)
188 return 1; 189 return 1;
189 zzuf_socat_start (); 190 zzuf_socat_start ();
190 for (i = 0; i < LOOP_COUNT; i++) 191 for (i = 0; i < LOOP_COUNT; i++)
191 { 192 {
192 fprintf (stderr, "."); 193 fprintf (stderr, ".");
193 c = curl_easy_init (); 194 c = curl_easy_init ();
194 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 195 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
195 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 196 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
196 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 197 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
197 pd = make_form (); 198 pd = make_form ();
198 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); 199 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
199 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
200 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
201 if (oneone) 202 if (oneone)
202 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 203 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
203 else 204 else
204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 205 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
205 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 206 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
206 /* NOTE: use of CONNECTTIMEOUT without also 207 /* NOTE: use of CONNECTTIMEOUT without also
207 * setting NOSIGNAL results in really weird 208 * setting NOSIGNAL results in really weird
208 * crashes on my system! */ 209 * crashes on my system! */
209 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 210 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
210 curl_easy_perform (c); 211 curl_easy_perform (c);
211 curl_easy_cleanup (c); 212 curl_easy_cleanup (c);
212 curl_formfree (pd); 213 curl_formfree (pd);
213 } 214 }
214 fprintf (stderr, "\n"); 215 fprintf (stderr, "\n");
215 zzuf_socat_stop (); 216 zzuf_socat_stop ();
216 MHD_stop_daemon (d); 217 MHD_stop_daemon (d);
@@ -231,37 +232,38 @@ testMultithreadedPost ()
231 cbc.buf = buf; 232 cbc.buf = buf;
232 cbc.size = 2048; 233 cbc.size = 2048;
233 cbc.pos = 0; 234 cbc.pos = 0;
234 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 235 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
236 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
235 11080, NULL, NULL, &ahc_echo, NULL, 237 11080, NULL, NULL, &ahc_echo, NULL,
236 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 238 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
237 MHD_OPTION_END); 239 MHD_OPTION_END);
238 if (d == NULL) 240 if (d == NULL)
239 return 16; 241 return 16;
240 zzuf_socat_start (); 242 zzuf_socat_start ();
241 for (i = 0; i < LOOP_COUNT; i++) 243 for (i = 0; i < LOOP_COUNT; i++)
242 { 244 {
243 fprintf (stderr, "."); 245 fprintf (stderr, ".");
244 c = curl_easy_init (); 246 c = curl_easy_init ();
245 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 247 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
246 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 248 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
247 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 249 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
248 pd = make_form (); 250 pd = make_form ();
249 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); 251 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
250 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 252 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
251 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 253 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
252 if (oneone) 254 if (oneone)
253 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 255 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
254 else 256 else
255 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 257 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
256 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 258 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
257 /* NOTE: use of CONNECTTIMEOUT without also 259 /* NOTE: use of CONNECTTIMEOUT without also
258 * setting NOSIGNAL results in really weird 260 * setting NOSIGNAL results in really weird
259 * crashes on my system! */ 261 * crashes on my system! */
260 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 262 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
261 curl_easy_perform (c); 263 curl_easy_perform (c);
262 curl_easy_cleanup (c); 264 curl_easy_cleanup (c);
263 curl_formfree (pd); 265 curl_formfree (pd);
264 } 266 }
265 fprintf (stderr, "\n"); 267 fprintf (stderr, "\n");
266 zzuf_socat_stop (); 268 zzuf_socat_stop ();
267 MHD_stop_daemon (d); 269 MHD_stop_daemon (d);
@@ -292,100 +294,100 @@ testExternalPost ()
292 cbc.buf = buf; 294 cbc.buf = buf;
293 cbc.size = 2048; 295 cbc.size = 2048;
294 cbc.pos = 0; 296 cbc.pos = 0;
295 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 297 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
296 1082, NULL, NULL, &ahc_echo, NULL, 298 1082, NULL, NULL, &ahc_echo, NULL,
297 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 299 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
298 MHD_OPTION_END); 300 MHD_OPTION_END);
299 if (d == NULL) 301 if (d == NULL)
300 return 256; 302 return 256;
301 multi = curl_multi_init (); 303 multi = curl_multi_init ();
302 if (multi == NULL) 304 if (multi == NULL)
305 {
306 MHD_stop_daemon (d);
307 return 512;
308 }
309 zzuf_socat_start ();
310 for (i = 0; i < LOOP_COUNT; i++)
311 {
312 fprintf (stderr, ".");
313
314 c = curl_easy_init ();
315 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world");
316 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
317 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
318 pd = make_form ();
319 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
320 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
321 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
322 if (oneone)
323 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
324 else
325 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
326 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
327 /* NOTE: use of CONNECTTIMEOUT without also
328 * setting NOSIGNAL results in really weird
329 * crashes on my system! */
330 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
331
332 mret = curl_multi_add_handle (multi, c);
333 if (mret != CURLM_OK)
303 { 334 {
335 curl_multi_cleanup (multi);
336 curl_formfree (pd);
337 curl_easy_cleanup (c);
338 zzuf_socat_stop ();
304 MHD_stop_daemon (d); 339 MHD_stop_daemon (d);
305 return 512; 340 return 1024;
306 } 341 }
307 zzuf_socat_start (); 342 start = time (NULL);
308 for (i = 0; i < LOOP_COUNT; i++) 343 while ((time (NULL) - start < 5) && (c != NULL))
309 { 344 {
310 fprintf (stderr, "."); 345 max = 0;
311 346 FD_ZERO (&rs);
312 c = curl_easy_init (); 347 FD_ZERO (&ws);
313 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world"); 348 FD_ZERO (&es);
314 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 349 curl_multi_perform (multi, &running);
315 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 350 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
316 pd = make_form ();
317 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
318 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
319 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
320 if (oneone)
321 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
322 else
323 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
324 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
325 /* NOTE: use of CONNECTTIMEOUT without also
326 * setting NOSIGNAL results in really weird
327 * crashes on my system! */
328 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
329
330 mret = curl_multi_add_handle (multi, c);
331 if (mret != CURLM_OK) 351 if (mret != CURLM_OK)
332 { 352 {
333 curl_multi_cleanup (multi); 353 curl_multi_remove_handle (multi, c);
334 curl_formfree (pd); 354 curl_multi_cleanup (multi);
335 curl_easy_cleanup (c); 355 curl_easy_cleanup (c);
336 zzuf_socat_stop (); 356 zzuf_socat_stop ();
337 MHD_stop_daemon (d); 357 MHD_stop_daemon (d);
338 return 1024; 358 curl_formfree (pd);
339 } 359 return 2048;
340 start = time (NULL); 360 }
341 while ((time (NULL) - start < 5) && (c != NULL)) 361 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
342 { 362 {
343 max = 0; 363 curl_multi_remove_handle (multi, c);
344 FD_ZERO (&rs); 364 curl_multi_cleanup (multi);
345 FD_ZERO (&ws); 365 curl_easy_cleanup (c);
346 FD_ZERO (&es); 366 curl_formfree (pd);
347 curl_multi_perform (multi, &running); 367 zzuf_socat_stop ();
348 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 368 MHD_stop_daemon (d);
349 if (mret != CURLM_OK) 369 return 4096;
350 { 370 }
351 curl_multi_remove_handle (multi, c); 371 tv.tv_sec = 0;
352 curl_multi_cleanup (multi); 372 tv.tv_usec = 1000;
353 curl_easy_cleanup (c); 373 select (max + 1, &rs, &ws, &es, &tv);
354 zzuf_socat_stop (); 374 curl_multi_perform (multi, &running);
355 MHD_stop_daemon (d); 375 if (running == 0)
356 curl_formfree (pd); 376 {
357 return 2048; 377 curl_multi_info_read (multi, &running);
358 } 378 curl_multi_remove_handle (multi, c);
359 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 379 curl_easy_cleanup (c);
360 { 380 c = NULL;
361 curl_multi_remove_handle (multi, c); 381 }
362 curl_multi_cleanup (multi); 382 MHD_run (d);
363 curl_easy_cleanup (c);
364 curl_formfree (pd);
365 zzuf_socat_stop ();
366 MHD_stop_daemon (d);
367 return 4096;
368 }
369 tv.tv_sec = 0;
370 tv.tv_usec = 1000;
371 select (max + 1, &rs, &ws, &es, &tv);
372 curl_multi_perform (multi, &running);
373 if (running == 0)
374 {
375 curl_multi_info_read (multi, &running);
376 curl_multi_remove_handle (multi, c);
377 curl_easy_cleanup (c);
378 c = NULL;
379 }
380 MHD_run (d);
381 }
382 if (c != NULL)
383 {
384 curl_multi_remove_handle (multi, c);
385 curl_easy_cleanup (c);
386 }
387 curl_formfree (pd);
388 } 383 }
384 if (c != NULL)
385 {
386 curl_multi_remove_handle (multi, c);
387 curl_easy_cleanup (c);
388 }
389 curl_formfree (pd);
390 }
389 fprintf (stderr, "\n"); 391 fprintf (stderr, "\n");
390 zzuf_socat_stop (); 392 zzuf_socat_stop ();
391 curl_multi_cleanup (multi); 393 curl_multi_cleanup (multi);
@@ -399,17 +401,17 @@ int
399main (int argc, char *const *argv) 401main (int argc, char *const *argv)
400{ 402{
401 unsigned int errorCount = 0; 403 unsigned int errorCount = 0;
402 (void)argc; /* Unused. Silent compiler warning. */ 404 (void) argc; /* Unused. Silent compiler warning. */
403 405
404 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 406 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
405 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 407 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
406 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 408 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
407 return 2; 409 return 2;
408 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 410 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
409 { 411 {
410 errorCount += testInternalPost (); 412 errorCount += testInternalPost ();
411 errorCount += testMultithreadedPost (); 413 errorCount += testMultithreadedPost ();
412 } 414 }
413 errorCount += testExternalPost (); 415 errorCount += testExternalPost ();
414 if (errorCount != 0) 416 if (errorCount != 0)
415 fprintf (stderr, "Error (code: %u)\n", errorCount); 417 fprintf (stderr, "Error (code: %u)\n", errorCount);