diff options
Diffstat (limited to 'src/testzzuf/daemontest_put_chunked.c')
-rw-r--r-- | src/testzzuf/daemontest_put_chunked.c | 222 |
1 files changed, 109 insertions, 113 deletions
diff --git a/src/testzzuf/daemontest_put_chunked.c b/src/testzzuf/daemontest_put_chunked.c index 0cc3eb8f..a78db8d3 100644 --- a/src/testzzuf/daemontest_put_chunked.c +++ b/src/testzzuf/daemontest_put_chunked.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 |
@@ -36,6 +36,18 @@ | |||
36 | #include <unistd.h> | 36 | #include <unistd.h> |
37 | #endif | 37 | #endif |
38 | 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 | |||
39 | struct CBC | 51 | struct CBC |
40 | { | 52 | { |
41 | char *buf; | 53 | char *buf; |
@@ -92,7 +104,6 @@ ahc_echo (void *cls, | |||
92 | have = *upload_data_size; | 104 | have = *upload_data_size; |
93 | if (have + *done > 8) | 105 | if (have + *done > 8) |
94 | { | 106 | { |
95 | printf ("Invalid upload data `%8s'!\n", upload_data); | ||
96 | return MHD_NO; | 107 | return MHD_NO; |
97 | } | 108 | } |
98 | if (0 == memcmp (upload_data, &"Hello123"[*done], have)) | 109 | if (0 == memcmp (upload_data, &"Hello123"[*done], have)) |
@@ -102,7 +113,6 @@ ahc_echo (void *cls, | |||
102 | } | 113 | } |
103 | else | 114 | else |
104 | { | 115 | { |
105 | printf ("Invalid upload data `%8s'!\n", upload_data); | ||
106 | return MHD_NO; | 116 | return MHD_NO; |
107 | } | 117 | } |
108 | #if 0 | 118 | #if 0 |
@@ -127,7 +137,7 @@ testInternalPut () | |||
127 | struct CBC cbc; | 137 | struct CBC cbc; |
128 | unsigned int pos = 0; | 138 | unsigned int pos = 0; |
129 | int done_flag = 0; | 139 | int done_flag = 0; |
130 | CURLcode errornum; | 140 | int i; |
131 | 141 | ||
132 | cbc.buf = buf; | 142 | cbc.buf = buf; |
133 | cbc.size = 2048; | 143 | cbc.size = 2048; |
@@ -137,40 +147,35 @@ testInternalPut () | |||
137 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); | 147 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); |
138 | if (d == NULL) | 148 | if (d == NULL) |
139 | return 1; | 149 | return 1; |
140 | c = curl_easy_init (); | 150 | zzuf_socat_start (); |
141 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11080/hello_world"); | 151 | for (i = 0; i < LOOP_COUNT; i++) |
142 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
143 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
144 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | ||
145 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | ||
146 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | ||
147 | /* | ||
148 | // by not giving the file size, we force chunking! | ||
149 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | ||
150 | */ | ||
151 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
152 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
153 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
154 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
155 | // NOTE: use of CONNECTTIMEOUT without also | ||
156 | // setting NOSIGNAL results in really weird | ||
157 | // crashes on my system! | ||
158 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
159 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
160 | { | 152 | { |
161 | fprintf (stderr, | 153 | fprintf (stderr, "."); |
162 | "curl_easy_perform failed: `%s'\n", | 154 | c = curl_easy_init (); |
163 | curl_easy_strerror (errornum)); | 155 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11080/hello_world"); |
156 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
157 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
158 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | ||
159 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | ||
160 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | ||
161 | /* | ||
162 | // by not giving the file size, we force chunking! | ||
163 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | ||
164 | */ | ||
165 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
166 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | ||
167 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
168 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | ||
169 | // NOTE: use of CONNECTTIMEOUT without also | ||
170 | // setting NOSIGNAL results in really weird | ||
171 | // crashes on my system! | ||
172 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
173 | curl_easy_perform (c); | ||
164 | curl_easy_cleanup (c); | 174 | curl_easy_cleanup (c); |
165 | MHD_stop_daemon (d); | ||
166 | return 2; | ||
167 | } | 175 | } |
168 | curl_easy_cleanup (c); | 176 | fprintf (stderr, "\n"); |
177 | zzuf_socat_stop (); | ||
169 | MHD_stop_daemon (d); | 178 | MHD_stop_daemon (d); |
170 | if (cbc.pos != strlen ("/hello_world")) | ||
171 | return 4; | ||
172 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
173 | return 8; | ||
174 | return 0; | 179 | return 0; |
175 | } | 180 | } |
176 | 181 | ||
@@ -246,11 +251,11 @@ testExternalPut () | |||
246 | fd_set es; | 251 | fd_set es; |
247 | int max; | 252 | int max; |
248 | int running; | 253 | int running; |
249 | struct CURLMsg *msg; | ||
250 | time_t start; | 254 | time_t start; |
251 | struct timeval tv; | 255 | struct timeval tv; |
252 | unsigned int pos = 0; | 256 | unsigned int pos = 0; |
253 | int done_flag = 0; | 257 | int done_flag = 0; |
258 | int i; | ||
254 | 259 | ||
255 | multi = NULL; | 260 | multi = NULL; |
256 | cbc.buf = buf; | 261 | cbc.buf = buf; |
@@ -261,103 +266,97 @@ testExternalPut () | |||
261 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); | 266 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); |
262 | if (d == NULL) | 267 | if (d == NULL) |
263 | return 256; | 268 | return 256; |
264 | c = curl_easy_init (); | ||
265 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11082/hello_world"); | ||
266 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
267 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
268 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | ||
269 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | ||
270 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | ||
271 | /* | ||
272 | // by not giving the file size, we force chunking! | ||
273 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | ||
274 | */ | ||
275 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
276 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
277 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
278 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
279 | // NOTE: use of CONNECTTIMEOUT without also | ||
280 | // setting NOSIGNAL results in really weird | ||
281 | // crashes on my system! | ||
282 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
283 | |||
284 | 269 | ||
285 | multi = curl_multi_init (); | 270 | multi = curl_multi_init (); |
286 | if (multi == NULL) | 271 | if (multi == NULL) |
287 | { | 272 | { |
288 | curl_easy_cleanup (c); | ||
289 | MHD_stop_daemon (d); | 273 | MHD_stop_daemon (d); |
290 | return 512; | 274 | return 512; |
291 | } | 275 | } |
292 | mret = curl_multi_add_handle (multi, c); | 276 | zzuf_socat_start (); |
293 | if (mret != CURLM_OK) | 277 | for (i = 0; i < LOOP_COUNT; i++) |
294 | { | 278 | { |
295 | curl_multi_cleanup (multi); | 279 | fprintf (stderr, "."); |
296 | curl_easy_cleanup (c); | 280 | c = curl_easy_init (); |
297 | MHD_stop_daemon (d); | 281 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11082/hello_world"); |
298 | return 1024; | 282 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
299 | } | 283 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
300 | start = time (NULL); | 284 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
301 | while ((time (NULL) - start < 5) && (multi != NULL)) | 285 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); |
302 | { | 286 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); |
303 | max = 0; | 287 | /* |
304 | FD_ZERO (&rs); | 288 | // by not giving the file size, we force chunking! |
305 | FD_ZERO (&ws); | 289 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); |
306 | FD_ZERO (&es); | 290 | */ |
307 | curl_multi_perform (multi, &running); | 291 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
308 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 292 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); |
293 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
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); | ||
309 | if (mret != CURLM_OK) | 302 | if (mret != CURLM_OK) |
310 | { | 303 | { |
311 | curl_multi_remove_handle (multi, c); | ||
312 | curl_multi_cleanup (multi); | ||
313 | curl_easy_cleanup (c); | ||
314 | MHD_stop_daemon (d); | ||
315 | return 2048; | ||
316 | } | ||
317 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
318 | { | ||
319 | curl_multi_remove_handle (multi, c); | ||
320 | curl_multi_cleanup (multi); | 304 | curl_multi_cleanup (multi); |
321 | curl_easy_cleanup (c); | 305 | curl_easy_cleanup (c); |
306 | zzuf_socat_stop (); | ||
322 | MHD_stop_daemon (d); | 307 | MHD_stop_daemon (d); |
323 | return 4096; | 308 | return 1024; |
324 | } | 309 | } |
325 | tv.tv_sec = 0; | 310 | start = time (NULL); |
326 | tv.tv_usec = 1000; | 311 | while ((time (NULL) - start < 5) && (c != NULL)) |
327 | select (max + 1, &rs, &ws, &es, &tv); | ||
328 | curl_multi_perform (multi, &running); | ||
329 | if (running == 0) | ||
330 | { | 312 | { |
331 | msg = curl_multi_info_read (multi, &running); | 313 | max = 0; |
332 | if (msg == NULL) | 314 | FD_ZERO (&rs); |
333 | break; | 315 | FD_ZERO (&ws); |
334 | 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) | ||
320 | { | ||
321 | curl_multi_remove_handle (multi, c); | ||
322 | curl_multi_cleanup (multi); | ||
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)) | ||
335 | { | 329 | { |
336 | if (msg->data.result != CURLE_OK) | ||
337 | printf ("%s failed at %s:%d: `%s'\n", | ||
338 | "curl_multi_perform", | ||
339 | __FILE__, | ||
340 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
341 | curl_multi_remove_handle (multi, c); | 330 | curl_multi_remove_handle (multi, c); |
342 | curl_multi_cleanup (multi); | 331 | curl_multi_cleanup (multi); |
343 | curl_easy_cleanup (c); | 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); | ||
344 | c = NULL; | 346 | c = NULL; |
345 | multi = NULL; | ||
346 | } | 347 | } |
348 | MHD_run (d); | ||
349 | } | ||
350 | if (c != NULL) | ||
351 | { | ||
352 | curl_multi_remove_handle (multi, c); | ||
353 | curl_easy_cleanup (c); | ||
347 | } | 354 | } |
348 | MHD_run (d); | ||
349 | } | ||
350 | if (multi != NULL) | ||
351 | { | ||
352 | curl_multi_remove_handle (multi, c); | ||
353 | curl_easy_cleanup (c); | ||
354 | curl_multi_cleanup (multi); | ||
355 | } | 355 | } |
356 | fprintf (stderr, "\n"); | ||
357 | curl_multi_cleanup (multi); | ||
358 | zzuf_socat_stop (); | ||
356 | MHD_stop_daemon (d); | 359 | MHD_stop_daemon (d); |
357 | if (cbc.pos != strlen ("/hello_world")) | ||
358 | return 8192; | ||
359 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
360 | return 16384; | ||
361 | return 0; | 360 | return 0; |
362 | } | 361 | } |
363 | 362 | ||
@@ -371,11 +370,8 @@ main (int argc, char *const *argv) | |||
371 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 370 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
372 | return 2; | 371 | return 2; |
373 | errorCount += testInternalPut (); | 372 | errorCount += testInternalPut (); |
374 | if (0) | 373 | errorCount += testMultithreadedPut (); |
375 | { | 374 | errorCount += testExternalPut (); |
376 | errorCount += testMultithreadedPut (); | ||
377 | errorCount += testExternalPut (); | ||
378 | } | ||
379 | if (errorCount != 0) | 375 | if (errorCount != 0) |
380 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 376 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
381 | curl_global_cleanup (); | 377 | curl_global_cleanup (); |