diff options
Diffstat (limited to 'src/testzzuf/daemontest_postform.c')
-rw-r--r-- | src/testzzuf/daemontest_postform.c | 292 |
1 files changed, 142 insertions, 150 deletions
diff --git a/src/testzzuf/daemontest_postform.c b/src/testzzuf/daemontest_postform.c index 4142b138..e4f6ec3d 100644 --- a/src/testzzuf/daemontest_postform.c +++ b/src/testzzuf/daemontest_postform.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libmicrohttpd | 2 | This file is part of libmicrohttpd |
3 | (C) 2007 Christian Grothoff | 3 | (C) 2007, 2008 Christian Grothoff |
4 | 4 | ||
5 | libmicrohttpd is free software; you can redistribute it and/or modify | 5 | libmicrohttpd is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -35,6 +35,19 @@ | |||
35 | #include <unistd.h> | 35 | #include <unistd.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | |||
39 | #include "socat.c" | ||
40 | |||
41 | /** | ||
42 | * A larger loop count will run more random tests -- | ||
43 | * which would be good, except that it may take too | ||
44 | * long for most user's patience. So this small | ||
45 | * value is the default. | ||
46 | */ | ||
47 | #define LOOP_COUNT 10 | ||
48 | |||
49 | #define CURL_TIMEOUT 50L | ||
50 | |||
38 | static int oneone; | 51 | static int oneone; |
39 | 52 | ||
40 | struct CBC | 53 | struct CBC |
@@ -72,6 +85,8 @@ post_iterator (void *cls, | |||
72 | { | 85 | { |
73 | int *eok = cls; | 86 | int *eok = cls; |
74 | 87 | ||
88 | if (key == NULL) | ||
89 | return MHD_YES; | ||
75 | #if 0 | 90 | #if 0 |
76 | fprintf (stderr, "PI sees %s-%.*s\n", key, size, value); | 91 | fprintf (stderr, "PI sees %s-%.*s\n", key, size, value); |
77 | #endif | 92 | #endif |
@@ -100,7 +115,6 @@ ahc_echo (void *cls, | |||
100 | 115 | ||
101 | if (0 != strcmp ("POST", method)) | 116 | if (0 != strcmp ("POST", method)) |
102 | { | 117 | { |
103 | printf ("METHOD: %s\n", method); | ||
104 | return MHD_NO; /* unexpected method */ | 118 | return MHD_NO; /* unexpected method */ |
105 | } | 119 | } |
106 | pp = *unused; | 120 | pp = *unused; |
@@ -109,7 +123,7 @@ ahc_echo (void *cls, | |||
109 | eok = 0; | 123 | eok = 0; |
110 | pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); | 124 | pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); |
111 | if (pp == NULL) | 125 | if (pp == NULL) |
112 | abort (); | 126 | return MHD_NO; |
113 | *unused = pp; | 127 | *unused = pp; |
114 | } | 128 | } |
115 | MHD_post_process (pp, upload_data, *upload_data_size); | 129 | MHD_post_process (pp, upload_data, *upload_data_size); |
@@ -149,50 +163,44 @@ testInternalPost () | |||
149 | CURL *c; | 163 | CURL *c; |
150 | char buf[2048]; | 164 | char buf[2048]; |
151 | struct CBC cbc; | 165 | struct CBC cbc; |
152 | CURLcode errornum; | 166 | int i; |
153 | struct curl_httppost *pd; | 167 | struct curl_httppost *pd; |
154 | 168 | ||
155 | cbc.buf = buf; | 169 | cbc.buf = buf; |
156 | cbc.size = 2048; | 170 | cbc.size = 2048; |
157 | cbc.pos = 0; | 171 | cbc.pos = 0; |
158 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, | 172 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ , |
159 | 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 173 | 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
160 | if (d == NULL) | 174 | if (d == NULL) |
161 | return 1; | 175 | return 1; |
162 | c = curl_easy_init (); | 176 | zzuf_socat_start (); |
163 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); | 177 | for (i = 0; i < LOOP_COUNT; i++) |
164 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
165 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
166 | pd = make_form (); | ||
167 | curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); | ||
168 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
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, 15L); | ||
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, 1); | ||
179 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
180 | { | 178 | { |
181 | fprintf (stderr, | 179 | fprintf (stderr, "."); |
182 | "curl_easy_perform failed: `%s'\n", | 180 | c = curl_easy_init (); |
183 | curl_easy_strerror (errornum)); | 181 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); |
182 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
183 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
184 | pd = make_form (); | ||
185 | curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); | ||
186 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
187 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | ||
188 | if (oneone) | ||
189 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
190 | else | ||
191 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
192 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | ||
193 | // NOTE: use of CONNECTTIMEOUT without also | ||
194 | // setting NOSIGNAL results in really weird | ||
195 | // crashes on my system! | ||
196 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
197 | curl_easy_perform (c); | ||
184 | curl_easy_cleanup (c); | 198 | curl_easy_cleanup (c); |
185 | curl_formfree (pd); | 199 | curl_formfree (pd); |
186 | MHD_stop_daemon (d); | ||
187 | return 2; | ||
188 | } | 200 | } |
189 | curl_easy_cleanup (c); | 201 | fprintf (stderr, "\n"); |
190 | curl_formfree (pd); | 202 | zzuf_socat_stop (); |
191 | MHD_stop_daemon (d); | 203 | MHD_stop_daemon (d); |
192 | if (cbc.pos != strlen ("/hello_world")) | ||
193 | return 4; | ||
194 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
195 | return 8; | ||
196 | return 0; | 204 | return 0; |
197 | } | 205 | } |
198 | 206 | ||
@@ -203,50 +211,44 @@ testMultithreadedPost () | |||
203 | CURL *c; | 211 | CURL *c; |
204 | char buf[2048]; | 212 | char buf[2048]; |
205 | struct CBC cbc; | 213 | struct CBC cbc; |
206 | CURLcode errornum; | 214 | int i; |
207 | struct curl_httppost *pd; | 215 | struct curl_httppost *pd; |
208 | 216 | ||
209 | cbc.buf = buf; | 217 | cbc.buf = buf; |
210 | cbc.size = 2048; | 218 | cbc.size = 2048; |
211 | cbc.pos = 0; | 219 | cbc.pos = 0; |
212 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, | 220 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ , |
213 | 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 221 | 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
214 | if (d == NULL) | 222 | if (d == NULL) |
215 | return 16; | 223 | return 16; |
216 | c = curl_easy_init (); | 224 | zzuf_socat_start (); |
217 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); | 225 | for (i = 0; i < LOOP_COUNT; i++) |
218 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
219 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
220 | pd = make_form (); | ||
221 | curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); | ||
222 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
223 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
224 | if (oneone) | ||
225 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
226 | else | ||
227 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
228 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L); | ||
229 | // NOTE: use of CONNECTTIMEOUT without also | ||
230 | // setting NOSIGNAL results in really weird | ||
231 | // crashes on my system! | ||
232 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
233 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
234 | { | 226 | { |
235 | fprintf (stderr, | 227 | fprintf (stderr, "."); |
236 | "curl_easy_perform failed: `%s'\n", | 228 | c = curl_easy_init (); |
237 | curl_easy_strerror (errornum)); | 229 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); |
230 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
231 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
232 | pd = make_form (); | ||
233 | curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); | ||
234 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
235 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | ||
236 | if (oneone) | ||
237 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
238 | else | ||
239 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
240 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | ||
241 | // NOTE: use of CONNECTTIMEOUT without also | ||
242 | // setting NOSIGNAL results in really weird | ||
243 | // crashes on my system! | ||
244 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
245 | curl_easy_perform (c); | ||
238 | curl_easy_cleanup (c); | 246 | curl_easy_cleanup (c); |
239 | curl_formfree (pd); | 247 | curl_formfree (pd); |
240 | MHD_stop_daemon (d); | ||
241 | return 32; | ||
242 | } | 248 | } |
243 | curl_easy_cleanup (c); | 249 | fprintf (stderr, "\n"); |
244 | curl_formfree (pd); | 250 | zzuf_socat_stop (); |
245 | MHD_stop_daemon (d); | 251 | MHD_stop_daemon (d); |
246 | if (cbc.pos != strlen ("/hello_world")) | ||
247 | return 64; | ||
248 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
249 | return 128; | ||
250 | return 0; | 252 | return 0; |
251 | } | 253 | } |
252 | 254 | ||
@@ -265,119 +267,112 @@ testExternalPost () | |||
265 | fd_set es; | 267 | fd_set es; |
266 | int max; | 268 | int max; |
267 | int running; | 269 | int running; |
268 | struct CURLMsg *msg; | ||
269 | time_t start; | 270 | time_t start; |
270 | struct timeval tv; | 271 | struct timeval tv; |
271 | struct curl_httppost *pd; | 272 | struct curl_httppost *pd; |
273 | int i; | ||
272 | 274 | ||
273 | multi = NULL; | 275 | multi = NULL; |
274 | cbc.buf = buf; | 276 | cbc.buf = buf; |
275 | cbc.size = 2048; | 277 | cbc.size = 2048; |
276 | cbc.pos = 0; | 278 | cbc.pos = 0; |
277 | d = MHD_start_daemon (MHD_USE_DEBUG, | 279 | d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ , |
278 | 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 280 | 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
279 | if (d == NULL) | 281 | if (d == NULL) |
280 | return 256; | 282 | return 256; |
281 | c = curl_easy_init (); | ||
282 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); | ||
283 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
284 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
285 | pd = make_form (); | ||
286 | curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); | ||
287 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
288 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
289 | if (oneone) | ||
290 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
291 | else | ||
292 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
293 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
294 | // NOTE: use of CONNECTTIMEOUT without also | ||
295 | // setting NOSIGNAL results in really weird | ||
296 | // crashes on my system! | ||
297 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
298 | |||
299 | |||
300 | multi = curl_multi_init (); | 283 | multi = curl_multi_init (); |
301 | if (multi == NULL) | 284 | if (multi == NULL) |
302 | { | 285 | { |
303 | curl_easy_cleanup (c); | ||
304 | curl_formfree (pd); | ||
305 | MHD_stop_daemon (d); | 286 | MHD_stop_daemon (d); |
306 | return 512; | 287 | return 512; |
307 | } | 288 | } |
308 | mret = curl_multi_add_handle (multi, c); | 289 | zzuf_socat_start (); |
309 | if (mret != CURLM_OK) | 290 | for (i = 0; i < LOOP_COUNT; i++) |
310 | { | 291 | { |
311 | curl_multi_cleanup (multi); | 292 | fprintf (stderr, "."); |
312 | curl_formfree (pd); | 293 | |
313 | curl_easy_cleanup (c); | 294 | c = curl_easy_init (); |
314 | MHD_stop_daemon (d); | 295 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); |
315 | return 1024; | 296 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
316 | } | 297 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
317 | start = time (NULL); | 298 | pd = make_form (); |
318 | while ((time (NULL) - start < 5) && (multi != NULL)) | 299 | curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); |
319 | { | 300 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
320 | max = 0; | 301 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); |
321 | FD_ZERO (&rs); | 302 | if (oneone) |
322 | FD_ZERO (&ws); | 303 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
323 | FD_ZERO (&es); | 304 | else |
324 | curl_multi_perform (multi, &running); | 305 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
325 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 306 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); |
307 | // NOTE: use of CONNECTTIMEOUT without also | ||
308 | // setting NOSIGNAL results in really weird | ||
309 | // crashes on my system! | ||
310 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
311 | |||
312 | |||
313 | mret = curl_multi_add_handle (multi, c); | ||
326 | if (mret != CURLM_OK) | 314 | if (mret != CURLM_OK) |
327 | { | 315 | { |
328 | curl_multi_remove_handle (multi, c); | ||
329 | curl_multi_cleanup (multi); | 316 | curl_multi_cleanup (multi); |
330 | curl_easy_cleanup (c); | ||
331 | MHD_stop_daemon (d); | ||
332 | curl_formfree (pd); | 317 | curl_formfree (pd); |
333 | return 2048; | ||
334 | } | ||
335 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
336 | { | ||
337 | curl_multi_remove_handle (multi, c); | ||
338 | curl_multi_cleanup (multi); | ||
339 | curl_easy_cleanup (c); | 318 | curl_easy_cleanup (c); |
340 | curl_formfree (pd); | 319 | zzuf_socat_stop (); |
341 | MHD_stop_daemon (d); | 320 | MHD_stop_daemon (d); |
342 | return 4096; | 321 | return 1024; |
343 | } | 322 | } |
344 | tv.tv_sec = 0; | 323 | start = time (NULL); |
345 | tv.tv_usec = 1000; | 324 | while ((time (NULL) - start < 5) && (c != NULL)) |
346 | select (max + 1, &rs, &ws, &es, &tv); | ||
347 | curl_multi_perform (multi, &running); | ||
348 | if (running == 0) | ||
349 | { | 325 | { |
350 | msg = curl_multi_info_read (multi, &running); | 326 | max = 0; |
351 | if (msg == NULL) | 327 | FD_ZERO (&rs); |
352 | break; | 328 | FD_ZERO (&ws); |
353 | if (msg->msg == CURLMSG_DONE) | 329 | FD_ZERO (&es); |
330 | curl_multi_perform (multi, &running); | ||
331 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | ||
332 | if (mret != CURLM_OK) | ||
333 | { | ||
334 | curl_multi_remove_handle (multi, c); | ||
335 | curl_multi_cleanup (multi); | ||
336 | curl_easy_cleanup (c); | ||
337 | zzuf_socat_stop (); | ||
338 | MHD_stop_daemon (d); | ||
339 | curl_formfree (pd); | ||
340 | return 2048; | ||
341 | } | ||
342 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
354 | { | 343 | { |
355 | if (msg->data.result != CURLE_OK) | ||
356 | printf ("%s failed at %s:%d: `%s'\n", | ||
357 | "curl_multi_perform", | ||
358 | __FILE__, | ||
359 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
360 | curl_multi_remove_handle (multi, c); | 344 | curl_multi_remove_handle (multi, c); |
361 | curl_multi_cleanup (multi); | 345 | curl_multi_cleanup (multi); |
362 | curl_easy_cleanup (c); | 346 | curl_easy_cleanup (c); |
347 | curl_formfree (pd); | ||
348 | zzuf_socat_stop (); | ||
349 | MHD_stop_daemon (d); | ||
350 | return 4096; | ||
351 | } | ||
352 | tv.tv_sec = 0; | ||
353 | tv.tv_usec = 1000; | ||
354 | select (max + 1, &rs, &ws, &es, &tv); | ||
355 | curl_multi_perform (multi, &running); | ||
356 | if (running == 0) | ||
357 | { | ||
358 | curl_multi_info_read (multi, &running); | ||
359 | curl_multi_remove_handle (multi, c); | ||
360 | curl_easy_cleanup (c); | ||
363 | c = NULL; | 361 | c = NULL; |
364 | multi = NULL; | ||
365 | } | 362 | } |
363 | MHD_run (d); | ||
366 | } | 364 | } |
367 | MHD_run (d); | 365 | if (c != NULL) |
368 | } | 366 | { |
369 | if (multi != NULL) | 367 | curl_multi_remove_handle (multi, c); |
370 | { | 368 | curl_easy_cleanup (c); |
371 | curl_multi_remove_handle (multi, c); | 369 | } |
372 | curl_easy_cleanup (c); | 370 | curl_formfree (pd); |
373 | curl_multi_cleanup (multi); | ||
374 | } | 371 | } |
375 | curl_formfree (pd); | 372 | fprintf (stderr, "\n"); |
373 | zzuf_socat_stop (); | ||
374 | |||
376 | MHD_stop_daemon (d); | 375 | MHD_stop_daemon (d); |
377 | if (cbc.pos != strlen ("/hello_world")) | ||
378 | return 8192; | ||
379 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
380 | return 16384; | ||
381 | return 0; | 376 | return 0; |
382 | } | 377 | } |
383 | 378 | ||
@@ -392,11 +387,8 @@ main (int argc, char *const *argv) | |||
392 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 387 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
393 | return 2; | 388 | return 2; |
394 | errorCount += testInternalPost (); | 389 | errorCount += testInternalPost (); |
395 | if (0) | 390 | errorCount += testMultithreadedPost (); |
396 | { | 391 | errorCount += testExternalPost (); |
397 | errorCount += testMultithreadedPost (); | ||
398 | errorCount += testExternalPost (); | ||
399 | } | ||
400 | if (errorCount != 0) | 392 | if (errorCount != 0) |
401 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 393 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
402 | curl_global_cleanup (); | 394 | curl_global_cleanup (); |