diff options
Diffstat (limited to 'src/testzzuf/daemontest_post.c')
-rw-r--r-- | src/testzzuf/daemontest_post.c | 288 |
1 files changed, 147 insertions, 141 deletions
diff --git a/src/testzzuf/daemontest_post.c b/src/testzzuf/daemontest_post.c index 335377e6..690ab218 100644 --- a/src/testzzuf/daemontest_post.c +++ b/src/testzzuf/daemontest_post.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,20 @@ | |||
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 | |||
51 | |||
38 | #define POST_DATA "name=daniel&project=curl" | 52 | #define POST_DATA "name=daniel&project=curl" |
39 | 53 | ||
40 | static int oneone; | 54 | static int oneone; |
@@ -99,7 +113,6 @@ ahc_echo (void *cls, | |||
99 | 113 | ||
100 | if (0 != strcmp ("POST", method)) | 114 | if (0 != strcmp ("POST", method)) |
101 | { | 115 | { |
102 | printf ("METHOD: %s\n", method); | ||
103 | return MHD_NO; /* unexpected method */ | 116 | return MHD_NO; /* unexpected method */ |
104 | } | 117 | } |
105 | pp = *unused; | 118 | pp = *unused; |
@@ -133,48 +146,45 @@ testInternalPost () | |||
133 | CURL *c; | 146 | CURL *c; |
134 | char buf[2048]; | 147 | char buf[2048]; |
135 | struct CBC cbc; | 148 | struct CBC cbc; |
136 | CURLcode errornum; | 149 | int i; |
137 | 150 | ||
138 | cbc.buf = buf; | 151 | cbc.buf = buf; |
139 | cbc.size = 2048; | 152 | cbc.size = 2048; |
140 | cbc.pos = 0; | 153 | cbc.pos = 0; |
141 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, | 154 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ , |
142 | 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 155 | 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
143 | if (d == NULL) | 156 | if (d == NULL) |
144 | return 1; | 157 | return 1; |
145 | c = curl_easy_init (); | 158 | zzuf_socat_start (); |
146 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); | 159 | for (i = 0; i < LOOP_COUNT; i++) |
147 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
148 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
149 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
150 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
151 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
152 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
153 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
154 | if (oneone) | ||
155 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
156 | else | ||
157 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
158 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
159 | // NOTE: use of CONNECTTIMEOUT without also | ||
160 | // setting NOSIGNAL results in really weird | ||
161 | // crashes on my system! | ||
162 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
163 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
164 | { | 160 | { |
165 | fprintf (stderr, | 161 | fprintf (stderr, "."); |
166 | "curl_easy_perform failed: `%s'\n", | 162 | |
167 | curl_easy_strerror (errornum)); | 163 | c = curl_easy_init (); |
164 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); | ||
165 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
166 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
167 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
168 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
169 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
170 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
171 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | ||
172 | if (oneone) | ||
173 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
174 | else | ||
175 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
176 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | ||
177 | // NOTE: use of CONNECTTIMEOUT without also | ||
178 | // setting NOSIGNAL results in really weird | ||
179 | // crashes on my system! | ||
180 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
181 | curl_easy_perform (c); | ||
168 | curl_easy_cleanup (c); | 182 | curl_easy_cleanup (c); |
169 | MHD_stop_daemon (d); | ||
170 | return 2; | ||
171 | } | 183 | } |
172 | curl_easy_cleanup (c); | 184 | fprintf (stderr, "\n"); |
185 | zzuf_socat_stop (); | ||
173 | MHD_stop_daemon (d); | 186 | MHD_stop_daemon (d); |
174 | if (cbc.pos != strlen ("/hello_world")) | 187 | |
175 | return 4; | ||
176 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
177 | return 8; | ||
178 | return 0; | 188 | return 0; |
179 | } | 189 | } |
180 | 190 | ||
@@ -185,48 +195,46 @@ testMultithreadedPost () | |||
185 | CURL *c; | 195 | CURL *c; |
186 | char buf[2048]; | 196 | char buf[2048]; |
187 | struct CBC cbc; | 197 | struct CBC cbc; |
188 | CURLcode errornum; | 198 | int i; |
189 | 199 | ||
190 | cbc.buf = buf; | 200 | cbc.buf = buf; |
191 | cbc.size = 2048; | 201 | cbc.size = 2048; |
192 | cbc.pos = 0; | 202 | cbc.pos = 0; |
193 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, | 203 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ , |
194 | 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 204 | 11080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
195 | if (d == NULL) | 205 | if (d == NULL) |
196 | return 16; | 206 | return 16; |
197 | c = curl_easy_init (); | 207 | |
198 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); | 208 | zzuf_socat_start (); |
199 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 209 | for (i = 0; i < LOOP_COUNT; i++) |
200 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
201 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
202 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
203 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
204 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
205 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
206 | if (oneone) | ||
207 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
208 | else | ||
209 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
210 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
211 | // NOTE: use of CONNECTTIMEOUT without also | ||
212 | // setting NOSIGNAL results in really weird | ||
213 | // crashes on my system! | ||
214 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
215 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
216 | { | 210 | { |
217 | fprintf (stderr, | 211 | fprintf (stderr, "."); |
218 | "curl_easy_perform failed: `%s'\n", | 212 | |
219 | curl_easy_strerror (errornum)); | 213 | c = curl_easy_init (); |
214 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); | ||
215 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
216 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
217 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
218 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
219 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
220 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
221 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | ||
222 | if (oneone) | ||
223 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
224 | else | ||
225 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
226 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | ||
227 | // NOTE: use of CONNECTTIMEOUT without also | ||
228 | // setting NOSIGNAL results in really weird | ||
229 | // crashes on my system! | ||
230 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
231 | curl_easy_perform (c); | ||
220 | curl_easy_cleanup (c); | 232 | curl_easy_cleanup (c); |
221 | MHD_stop_daemon (d); | ||
222 | return 32; | ||
223 | } | 233 | } |
224 | curl_easy_cleanup (c); | 234 | fprintf (stderr, "\n"); |
235 | zzuf_socat_stop (); | ||
236 | |||
225 | MHD_stop_daemon (d); | 237 | MHD_stop_daemon (d); |
226 | if (cbc.pos != strlen ("/hello_world")) | ||
227 | return 64; | ||
228 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
229 | return 128; | ||
230 | return 0; | 238 | return 0; |
231 | } | 239 | } |
232 | 240 | ||
@@ -245,114 +253,112 @@ testExternalPost () | |||
245 | fd_set es; | 253 | fd_set es; |
246 | int max; | 254 | int max; |
247 | int running; | 255 | int running; |
248 | struct CURLMsg *msg; | ||
249 | time_t start; | 256 | time_t start; |
250 | struct timeval tv; | 257 | struct timeval tv; |
258 | int i; | ||
251 | 259 | ||
252 | multi = NULL; | 260 | multi = NULL; |
253 | cbc.buf = buf; | 261 | cbc.buf = buf; |
254 | cbc.size = 2048; | 262 | cbc.size = 2048; |
255 | cbc.pos = 0; | 263 | cbc.pos = 0; |
256 | d = MHD_start_daemon (MHD_USE_DEBUG, | 264 | d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ , |
257 | 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 265 | 1082, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
258 | if (d == NULL) | 266 | if (d == NULL) |
259 | return 256; | 267 | return 256; |
260 | c = curl_easy_init (); | ||
261 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); | ||
262 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
263 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
264 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
265 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
266 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
267 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
268 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
269 | if (oneone) | ||
270 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
271 | else | ||
272 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
273 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
274 | // NOTE: use of CONNECTTIMEOUT without also | ||
275 | // setting NOSIGNAL results in really weird | ||
276 | // crashes on my system! | ||
277 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
278 | |||
279 | |||
280 | multi = curl_multi_init (); | 268 | multi = curl_multi_init (); |
281 | if (multi == NULL) | 269 | if (multi == NULL) |
282 | { | 270 | { |
283 | curl_easy_cleanup (c); | ||
284 | MHD_stop_daemon (d); | 271 | MHD_stop_daemon (d); |
285 | return 512; | 272 | return 512; |
286 | } | 273 | } |
287 | mret = curl_multi_add_handle (multi, c); | 274 | |
288 | if (mret != CURLM_OK) | 275 | zzuf_socat_start (); |
289 | { | 276 | for (i = 0; i < LOOP_COUNT; i++) |
290 | curl_multi_cleanup (multi); | ||
291 | curl_easy_cleanup (c); | ||
292 | MHD_stop_daemon (d); | ||
293 | return 1024; | ||
294 | } | ||
295 | start = time (NULL); | ||
296 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
297 | { | 277 | { |
298 | max = 0; | 278 | fprintf (stderr, "."); |
299 | FD_ZERO (&rs); | 279 | |
300 | FD_ZERO (&ws); | 280 | |
301 | FD_ZERO (&es); | 281 | c = curl_easy_init (); |
302 | curl_multi_perform (multi, &running); | 282 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); |
303 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 283 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
284 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
285 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
286 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
287 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
288 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
289 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | ||
290 | if (oneone) | ||
291 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
292 | else | ||
293 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
294 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | ||
295 | // NOTE: use of CONNECTTIMEOUT without also | ||
296 | // setting NOSIGNAL results in really weird | ||
297 | // crashes on my system! | ||
298 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
299 | |||
300 | |||
301 | mret = curl_multi_add_handle (multi, c); | ||
304 | if (mret != CURLM_OK) | 302 | if (mret != CURLM_OK) |
305 | { | 303 | { |
306 | curl_multi_remove_handle (multi, c); | ||
307 | curl_multi_cleanup (multi); | ||
308 | curl_easy_cleanup (c); | ||
309 | MHD_stop_daemon (d); | ||
310 | return 2048; | ||
311 | } | ||
312 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
313 | { | ||
314 | curl_multi_remove_handle (multi, c); | ||
315 | curl_multi_cleanup (multi); | 304 | curl_multi_cleanup (multi); |
316 | curl_easy_cleanup (c); | 305 | curl_easy_cleanup (c); |
306 | zzuf_socat_stop (); | ||
317 | MHD_stop_daemon (d); | 307 | MHD_stop_daemon (d); |
318 | return 4096; | 308 | return 1024; |
319 | } | 309 | } |
320 | tv.tv_sec = 0; | 310 | start = time (NULL); |
321 | tv.tv_usec = 1000; | 311 | while ((time (NULL) - start < 5) && (c != NULL)) |
322 | select (max + 1, &rs, &ws, &es, &tv); | ||
323 | curl_multi_perform (multi, &running); | ||
324 | if (running == 0) | ||
325 | { | 312 | { |
326 | msg = curl_multi_info_read (multi, &running); | 313 | max = 0; |
327 | if (msg == NULL) | 314 | FD_ZERO (&rs); |
328 | break; | 315 | FD_ZERO (&ws); |
329 | if (msg->msg == CURLMSG_DONE) | 316 | FD_ZERO (&es); |
317 | curl_multi_perform (multi, &running); | ||
318 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | ||
319 | if (mret != CURLM_OK) | ||
330 | { | 320 | { |
331 | if (msg->data.result != CURLE_OK) | ||
332 | printf ("%s failed at %s:%d: `%s'\n", | ||
333 | "curl_multi_perform", | ||
334 | __FILE__, | ||
335 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
336 | curl_multi_remove_handle (multi, c); | 321 | curl_multi_remove_handle (multi, c); |
337 | curl_multi_cleanup (multi); | 322 | curl_multi_cleanup (multi); |
338 | curl_easy_cleanup (c); | 323 | curl_easy_cleanup (c); |
324 | zzuf_socat_stop (); | ||
325 | MHD_stop_daemon (d); | ||
326 | return 2048; | ||
327 | } | ||
328 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
329 | { | ||
330 | curl_multi_remove_handle (multi, c); | ||
331 | curl_multi_cleanup (multi); | ||
332 | curl_easy_cleanup (c); | ||
333 | zzuf_socat_stop (); | ||
334 | MHD_stop_daemon (d); | ||
335 | return 4096; | ||
336 | } | ||
337 | tv.tv_sec = 0; | ||
338 | tv.tv_usec = 1000; | ||
339 | select (max + 1, &rs, &ws, &es, &tv); | ||
340 | curl_multi_perform (multi, &running); | ||
341 | if (running == 0) | ||
342 | { | ||
343 | curl_multi_info_read (multi, &running); | ||
344 | curl_multi_remove_handle (multi, c); | ||
345 | curl_easy_cleanup (c); | ||
339 | c = NULL; | 346 | c = NULL; |
340 | multi = NULL; | ||
341 | } | 347 | } |
348 | MHD_run (d); | ||
342 | } | 349 | } |
343 | MHD_run (d); | 350 | if (c != NULL) |
344 | } | 351 | { |
345 | if (multi != NULL) | 352 | curl_multi_remove_handle (multi, c); |
346 | { | 353 | curl_easy_cleanup (c); |
347 | curl_multi_remove_handle (multi, c); | 354 | } |
348 | curl_easy_cleanup (c); | 355 | |
349 | curl_multi_cleanup (multi); | ||
350 | } | 356 | } |
357 | fprintf (stderr, "\n"); | ||
358 | curl_multi_cleanup (multi); | ||
359 | zzuf_socat_stop (); | ||
360 | |||
351 | MHD_stop_daemon (d); | 361 | MHD_stop_daemon (d); |
352 | if (cbc.pos != strlen ("/hello_world")) | ||
353 | return 8192; | ||
354 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
355 | return 16384; | ||
356 | return 0; | 362 | return 0; |
357 | } | 363 | } |
358 | 364 | ||