aboutsummaryrefslogtreecommitdiff
path: root/src/testzzuf/test_post.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testzzuf/test_post.c')
-rw-r--r--src/testzzuf/test_post.c348
1 files changed, 175 insertions, 173 deletions
diff --git a/src/testzzuf/test_post.c b/src/testzzuf/test_post.c
index 03b8e5a8..90da5e02 100644
--- a/src/testzzuf/test_post.c
+++ b/src/testzzuf/test_post.c
@@ -53,12 +53,12 @@ struct CBC
53 53
54static void 54static void
55completed_cb (void *cls, 55completed_cb (void *cls,
56 struct MHD_Connection *connection, 56 struct MHD_Connection *connection,
57 void **con_cls, 57 void **con_cls,
58 enum MHD_RequestTerminationCode toe) 58 enum MHD_RequestTerminationCode toe)
59{ 59{
60 struct MHD_PostProcessor *pp = *con_cls; 60 struct MHD_PostProcessor *pp = *con_cls;
61 (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ 61 (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */
62 62
63 if (NULL != pp) 63 if (NULL != pp)
64 MHD_destroy_post_processor (pp); 64 MHD_destroy_post_processor (pp);
@@ -94,8 +94,8 @@ post_iterator (void *cls,
94 const char *value, uint64_t off, size_t size) 94 const char *value, uint64_t off, size_t size)
95{ 95{
96 int *eok = cls; 96 int *eok = cls;
97 (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ 97 (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
98 (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ 98 (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */
99 99
100 if ((0 == strcmp (key, "name")) && 100 if ((0 == strcmp (key, "name")) &&
101 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size))) 101 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size)))
@@ -119,31 +119,31 @@ ahc_echo (void *cls,
119 struct MHD_Response *response; 119 struct MHD_Response *response;
120 struct MHD_PostProcessor *pp; 120 struct MHD_PostProcessor *pp;
121 int ret; 121 int ret;
122 (void)cls;(void)version; /* Unused. Silent compiler warning. */ 122 (void) cls; (void) version; /* Unused. Silent compiler warning. */
123 123
124 if (0 != strcmp ("POST", method)) 124 if (0 != strcmp ("POST", method))
125 { 125 {
126 return MHD_NO; /* unexpected method */ 126 return MHD_NO; /* unexpected method */
127 } 127 }
128 pp = *unused; 128 pp = *unused;
129 if (pp == NULL) 129 if (pp == NULL)
130 { 130 {
131 eok = 0; 131 eok = 0;
132 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 132 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
133 *unused = pp; 133 *unused = pp;
134 } 134 }
135 MHD_post_process (pp, upload_data, *upload_data_size); 135 MHD_post_process (pp, upload_data, *upload_data_size);
136 if ((eok == 3) && (0 == *upload_data_size)) 136 if ((eok == 3) && (0 == *upload_data_size))
137 { 137 {
138 response = MHD_create_response_from_buffer (strlen (url), 138 response = MHD_create_response_from_buffer (strlen (url),
139 (void *) url, 139 (void *) url,
140 MHD_RESPMEM_MUST_COPY); 140 MHD_RESPMEM_MUST_COPY);
141 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 141 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
142 MHD_destroy_response (response); 142 MHD_destroy_response (response);
143 MHD_destroy_post_processor (pp); 143 MHD_destroy_post_processor (pp);
144 *unused = NULL; 144 *unused = NULL;
145 return ret; 145 return ret;
146 } 146 }
147 *upload_data_size = 0; 147 *upload_data_size = 0;
148 return MHD_YES; 148 return MHD_YES;
149} 149}
@@ -161,38 +161,39 @@ testInternalPost ()
161 cbc.buf = buf; 161 cbc.buf = buf;
162 cbc.size = 2048; 162 cbc.size = 2048;
163 cbc.pos = 0; 163 cbc.pos = 0;
164 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 164 d = MHD_start_daemon (
165 11080, NULL, NULL, &ahc_echo, NULL, 165 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
166 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 166 11080, NULL, NULL, &ahc_echo, NULL,
167 MHD_OPTION_END); 167 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
168 MHD_OPTION_END);
168 if (d == NULL) 169 if (d == NULL)
169 return 1; 170 return 1;
170 zzuf_socat_start (); 171 zzuf_socat_start ();
171 for (i = 0; i < LOOP_COUNT; i++) 172 for (i = 0; i < LOOP_COUNT; i++)
172 { 173 {
173 fprintf (stderr, "."); 174 fprintf (stderr, ".");
174 175
175 c = curl_easy_init (); 176 c = curl_easy_init ();
176 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 177 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
177 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 178 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
178 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 179 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
179 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 180 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
180 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); 181 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
181 curl_easy_setopt (c, CURLOPT_POST, 1L); 182 curl_easy_setopt (c, CURLOPT_POST, 1L);
182 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 183 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
183 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 184 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
184 if (oneone) 185 if (oneone)
185 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 186 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
186 else 187 else
187 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 188 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
188 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 189 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
189 /* NOTE: use of CONNECTTIMEOUT without also 190 /* NOTE: use of CONNECTTIMEOUT without also
190 * setting NOSIGNAL results in really weird 191 * setting NOSIGNAL results in really weird
191 * crashes on my system! */ 192 * crashes on my system! */
192 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 193 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
193 curl_easy_perform (c); 194 curl_easy_perform (c);
194 curl_easy_cleanup (c); 195 curl_easy_cleanup (c);
195 } 196 }
196 fprintf (stderr, "\n"); 197 fprintf (stderr, "\n");
197 zzuf_socat_stop (); 198 zzuf_socat_stop ();
198 MHD_stop_daemon (d); 199 MHD_stop_daemon (d);
@@ -212,39 +213,40 @@ testMultithreadedPost ()
212 cbc.buf = buf; 213 cbc.buf = buf;
213 cbc.size = 2048; 214 cbc.size = 2048;
214 cbc.pos = 0; 215 cbc.pos = 0;
215 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 216 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
216 11080, NULL, NULL, &ahc_echo, NULL, 217 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
217 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 218 11080, NULL, NULL, &ahc_echo, NULL,
218 MHD_OPTION_END); 219 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
220 MHD_OPTION_END);
219 if (d == NULL) 221 if (d == NULL)
220 return 16; 222 return 16;
221 223
222 zzuf_socat_start (); 224 zzuf_socat_start ();
223 for (i = 0; i < LOOP_COUNT; i++) 225 for (i = 0; i < LOOP_COUNT; i++)
224 { 226 {
225 fprintf (stderr, "."); 227 fprintf (stderr, ".");
226 228
227 c = curl_easy_init (); 229 c = curl_easy_init ();
228 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 230 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
229 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 231 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
230 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 232 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
231 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 233 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
232 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); 234 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
233 curl_easy_setopt (c, CURLOPT_POST, 1L); 235 curl_easy_setopt (c, CURLOPT_POST, 1L);
234 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 236 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
235 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 237 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
236 if (oneone) 238 if (oneone)
237 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 239 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
238 else 240 else
239 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 241 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
240 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 242 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
241 /* NOTE: use of CONNECTTIMEOUT without also 243 /* NOTE: use of CONNECTTIMEOUT without also
242 * setting NOSIGNAL results in really weird 244 * setting NOSIGNAL results in really weird
243 * crashes on my system! */ 245 * crashes on my system! */
244 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 246 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
245 curl_easy_perform (c); 247 curl_easy_perform (c);
246 curl_easy_cleanup (c); 248 curl_easy_cleanup (c);
247 } 249 }
248 fprintf (stderr, "\n"); 250 fprintf (stderr, "\n");
249 zzuf_socat_stop (); 251 zzuf_socat_stop ();
250 252
@@ -275,101 +277,101 @@ testExternalPost ()
275 cbc.buf = buf; 277 cbc.buf = buf;
276 cbc.size = 2048; 278 cbc.size = 2048;
277 cbc.pos = 0; 279 cbc.pos = 0;
278 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 280 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
279 1082, NULL, NULL, &ahc_echo, NULL, 281 1082, NULL, NULL, &ahc_echo, NULL,
280 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 282 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
281 MHD_OPTION_END); 283 MHD_OPTION_END);
282 if (d == NULL) 284 if (d == NULL)
283 return 256; 285 return 256;
284 multi = curl_multi_init (); 286 multi = curl_multi_init ();
285 if (multi == NULL) 287 if (multi == NULL)
286 { 288 {
287 MHD_stop_daemon (d); 289 MHD_stop_daemon (d);
288 return 512; 290 return 512;
289 } 291 }
290 292
291 zzuf_socat_start (); 293 zzuf_socat_start ();
292 for (i = 0; i < LOOP_COUNT; i++) 294 for (i = 0; i < LOOP_COUNT; i++)
295 {
296 fprintf (stderr, ".");
297
298
299 c = curl_easy_init ();
300 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world");
301 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
302 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
303 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
304 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
305 curl_easy_setopt (c, CURLOPT_POST, 1L);
306 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
307 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
308 if (oneone)
309 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
310 else
311 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
312 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
313 /* NOTE: use of CONNECTTIMEOUT without also
314 * setting NOSIGNAL results in really weird
315 * crashes on my system! */
316 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
317
318
319 mret = curl_multi_add_handle (multi, c);
320 if (mret != CURLM_OK)
293 { 321 {
294 fprintf (stderr, "."); 322 curl_multi_cleanup (multi);
295 323 curl_easy_cleanup (c);
296 324 zzuf_socat_stop ();
297 c = curl_easy_init (); 325 MHD_stop_daemon (d);
298 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world"); 326 return 1024;
299 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 327 }
300 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 328 start = time (NULL);
301 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 329 while ((time (NULL) - start < 5) && (c != NULL))
302 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); 330 {
303 curl_easy_setopt (c, CURLOPT_POST, 1L); 331 max = 0;
304 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 332 FD_ZERO (&rs);
305 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 333 FD_ZERO (&ws);
306 if (oneone) 334 FD_ZERO (&es);
307 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 335 curl_multi_perform (multi, &running);
308 else 336 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
309 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
310 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
311 /* NOTE: use of CONNECTTIMEOUT without also
312 * setting NOSIGNAL results in really weird
313 * crashes on my system! */
314 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
315
316
317 mret = curl_multi_add_handle (multi, c);
318 if (mret != CURLM_OK) 337 if (mret != CURLM_OK)
319 { 338 {
320 curl_multi_cleanup (multi); 339 curl_multi_remove_handle (multi, c);
321 curl_easy_cleanup (c); 340 curl_multi_cleanup (multi);
322 zzuf_socat_stop (); 341 curl_easy_cleanup (c);
323 MHD_stop_daemon (d); 342 zzuf_socat_stop ();
324 return 1024; 343 MHD_stop_daemon (d);
325 } 344 return 2048;
326 start = time (NULL); 345 }
327 while ((time (NULL) - start < 5) && (c != NULL)) 346 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
328 { 347 {
329 max = 0; 348 curl_multi_remove_handle (multi, c);
330 FD_ZERO (&rs); 349 curl_multi_cleanup (multi);
331 FD_ZERO (&ws); 350 curl_easy_cleanup (c);
332 FD_ZERO (&es); 351 zzuf_socat_stop ();
333 curl_multi_perform (multi, &running); 352 MHD_stop_daemon (d);
334 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 353 return 4096;
335 if (mret != CURLM_OK) 354 }
336 { 355 tv.tv_sec = 0;
337 curl_multi_remove_handle (multi, c); 356 tv.tv_usec = 1000;
338 curl_multi_cleanup (multi); 357 select (max + 1, &rs, &ws, &es, &tv);
339 curl_easy_cleanup (c); 358 curl_multi_perform (multi, &running);
340 zzuf_socat_stop (); 359 if (running == 0)
341 MHD_stop_daemon (d); 360 {
342 return 2048; 361 curl_multi_info_read (multi, &running);
343 } 362 curl_multi_remove_handle (multi, c);
344 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 363 curl_easy_cleanup (c);
345 { 364 c = NULL;
346 curl_multi_remove_handle (multi, c); 365 }
347 curl_multi_cleanup (multi); 366 MHD_run (d);
348 curl_easy_cleanup (c);
349 zzuf_socat_stop ();
350 MHD_stop_daemon (d);
351 return 4096;
352 }
353 tv.tv_sec = 0;
354 tv.tv_usec = 1000;
355 select (max + 1, &rs, &ws, &es, &tv);
356 curl_multi_perform (multi, &running);
357 if (running == 0)
358 {
359 curl_multi_info_read (multi, &running);
360 curl_multi_remove_handle (multi, c);
361 curl_easy_cleanup (c);
362 c = NULL;
363 }
364 MHD_run (d);
365 }
366 if (c != NULL)
367 {
368 curl_multi_remove_handle (multi, c);
369 curl_easy_cleanup (c);
370 }
371
372 } 367 }
368 if (c != NULL)
369 {
370 curl_multi_remove_handle (multi, c);
371 curl_easy_cleanup (c);
372 }
373
374 }
373 fprintf (stderr, "\n"); 375 fprintf (stderr, "\n");
374 curl_multi_cleanup (multi); 376 curl_multi_cleanup (multi);
375 zzuf_socat_stop (); 377 zzuf_socat_stop ();
@@ -383,17 +385,17 @@ int
383main (int argc, char *const *argv) 385main (int argc, char *const *argv)
384{ 386{
385 unsigned int errorCount = 0; 387 unsigned int errorCount = 0;
386 (void)argc; /* Unused. Silent compiler warning. */ 388 (void) argc; /* Unused. Silent compiler warning. */
387 389
388 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 390 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
389 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 391 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
390 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 392 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
391 return 2; 393 return 2;
392 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 394 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
393 { 395 {
394 errorCount += testInternalPost (); 396 errorCount += testInternalPost ();
395 errorCount += testMultithreadedPost (); 397 errorCount += testMultithreadedPost ();
396 } 398 }
397 errorCount += testExternalPost (); 399 errorCount += testExternalPost ();
398 if (errorCount != 0) 400 if (errorCount != 0)
399 fprintf (stderr, "Error (code: %u)\n", errorCount); 401 fprintf (stderr, "Error (code: %u)\n", errorCount);