diff options
Diffstat (limited to 'src/testzzuf/test_put_chunked.c')
-rw-r--r-- | src/testzzuf/test_put_chunked.c | 275 |
1 files changed, 138 insertions, 137 deletions
diff --git a/src/testzzuf/test_put_chunked.c b/src/testzzuf/test_put_chunked.c index d016d84e..f66e1ff9 100644 --- a/src/testzzuf/test_put_chunked.c +++ b/src/testzzuf/test_put_chunked.c | |||
@@ -87,34 +87,34 @@ ahc_echo (void *cls, | |||
87 | struct MHD_Response *response; | 87 | struct MHD_Response *response; |
88 | int ret; | 88 | int ret; |
89 | int have; | 89 | int have; |
90 | (void)version;(void)unused; /* Unused. Silent compiler warning. */ | 90 | (void) version; (void) unused; /* Unused. Silent compiler warning. */ |
91 | 91 | ||
92 | if (0 != strcmp ("PUT", method)) | 92 | if (0 != strcmp ("PUT", method)) |
93 | return MHD_NO; /* unexpected method */ | 93 | return MHD_NO; /* unexpected method */ |
94 | if ((*done) < 8) | 94 | if ((*done) < 8) |
95 | { | ||
96 | have = *upload_data_size; | ||
97 | if (have + *done > 8) | ||
95 | { | 98 | { |
96 | have = *upload_data_size; | 99 | return MHD_NO; |
97 | if (have + *done > 8) | 100 | } |
98 | { | 101 | if (0 == memcmp (upload_data, &"Hello123"[*done], have)) |
99 | return MHD_NO; | 102 | { |
100 | } | 103 | *done += have; |
101 | if (0 == memcmp (upload_data, &"Hello123"[*done], have)) | 104 | *upload_data_size = 0; |
102 | { | 105 | } |
103 | *done += have; | 106 | else |
104 | *upload_data_size = 0; | 107 | { |
105 | } | 108 | return MHD_NO; |
106 | else | 109 | } |
107 | { | ||
108 | return MHD_NO; | ||
109 | } | ||
110 | #if 0 | 110 | #if 0 |
111 | fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8); | 111 | fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8); |
112 | #endif | 112 | #endif |
113 | return MHD_YES; | 113 | return MHD_YES; |
114 | } | 114 | } |
115 | response = MHD_create_response_from_buffer (strlen (url), | 115 | response = MHD_create_response_from_buffer (strlen (url), |
116 | (void *) url, | 116 | (void *) url, |
117 | MHD_RESPMEM_MUST_COPY); | 117 | MHD_RESPMEM_MUST_COPY); |
118 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 118 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
119 | MHD_destroy_response (response); | 119 | MHD_destroy_response (response); |
120 | return ret; | 120 | return ret; |
@@ -142,30 +142,30 @@ testInternalPut () | |||
142 | return 1; | 142 | return 1; |
143 | zzuf_socat_start (); | 143 | zzuf_socat_start (); |
144 | for (i = 0; i < LOOP_COUNT; i++) | 144 | for (i = 0; i < LOOP_COUNT; i++) |
145 | { | 145 | { |
146 | fprintf (stderr, "."); | 146 | fprintf (stderr, "."); |
147 | c = curl_easy_init (); | 147 | c = curl_easy_init (); |
148 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11080/hello_world"); | 148 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11080/hello_world"); |
149 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 149 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
150 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 150 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
151 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 151 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
152 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | 152 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); |
153 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | 153 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); |
154 | /* by not giving the file size, we force chunking! */ | 154 | /* by not giving the file size, we force chunking! */ |
155 | /* | 155 | /* |
156 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | 156 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); |
157 | */ | 157 | */ |
158 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 158 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
159 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | 159 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); |
160 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 160 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
161 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | 161 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); |
162 | /* NOTE: use of CONNECTTIMEOUT without also | 162 | /* NOTE: use of CONNECTTIMEOUT without also |
163 | * setting NOSIGNAL results in really weird | 163 | * setting NOSIGNAL results in really weird |
164 | * crashes on my system! */ | 164 | * crashes on my system! */ |
165 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 165 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
166 | curl_easy_perform (c); | 166 | curl_easy_perform (c); |
167 | curl_easy_cleanup (c); | 167 | curl_easy_cleanup (c); |
168 | } | 168 | } |
169 | fprintf (stderr, "\n"); | 169 | fprintf (stderr, "\n"); |
170 | zzuf_socat_stop (); | 170 | zzuf_socat_stop (); |
171 | MHD_stop_daemon (d); | 171 | MHD_stop_daemon (d); |
@@ -186,7 +186,8 @@ testMultithreadedPut () | |||
186 | cbc.buf = buf; | 186 | cbc.buf = buf; |
187 | cbc.size = 2048; | 187 | cbc.size = 2048; |
188 | cbc.pos = 0; | 188 | cbc.pos = 0; |
189 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 189 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
190 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
190 | 11081, | 191 | 11081, |
191 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); | 192 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); |
192 | if (d == NULL) | 193 | if (d == NULL) |
@@ -211,14 +212,14 @@ testMultithreadedPut () | |||
211 | * crashes on my system! */ | 212 | * crashes on my system! */ |
212 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 213 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
213 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 214 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
214 | { | 215 | { |
215 | fprintf (stderr, | 216 | fprintf (stderr, |
216 | "curl_easy_perform failed: `%s'\n", | 217 | "curl_easy_perform failed: `%s'\n", |
217 | curl_easy_strerror (errornum)); | 218 | curl_easy_strerror (errornum)); |
218 | curl_easy_cleanup (c); | 219 | curl_easy_cleanup (c); |
219 | MHD_stop_daemon (d); | 220 | MHD_stop_daemon (d); |
220 | return 32; | 221 | return 32; |
221 | } | 222 | } |
222 | curl_easy_cleanup (c); | 223 | curl_easy_cleanup (c); |
223 | MHD_stop_daemon (d); | 224 | MHD_stop_daemon (d); |
224 | if (cbc.pos != strlen ("/hello_world")) | 225 | if (cbc.pos != strlen ("/hello_world")) |
@@ -262,90 +263,90 @@ testExternalPut () | |||
262 | 263 | ||
263 | multi = curl_multi_init (); | 264 | multi = curl_multi_init (); |
264 | if (multi == NULL) | 265 | if (multi == NULL) |
265 | { | 266 | { |
266 | MHD_stop_daemon (d); | 267 | MHD_stop_daemon (d); |
267 | return 512; | 268 | return 512; |
268 | } | 269 | } |
269 | zzuf_socat_start (); | 270 | zzuf_socat_start (); |
270 | for (i = 0; i < LOOP_COUNT; i++) | 271 | for (i = 0; i < LOOP_COUNT; i++) |
271 | { | 272 | { |
272 | fprintf (stderr, "."); | 273 | fprintf (stderr, "."); |
273 | c = curl_easy_init (); | 274 | c = curl_easy_init (); |
274 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11082/hello_world"); | 275 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11082/hello_world"); |
275 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 276 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
276 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 277 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
277 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 278 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
278 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | 279 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); |
279 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | 280 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); |
280 | /* by not giving the file size, we force chunking! */ | 281 | /* by not giving the file size, we force chunking! */ |
281 | /* | 282 | /* |
282 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | 283 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); |
283 | */ | 284 | */ |
284 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 285 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
285 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | 286 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); |
286 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 287 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
287 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | 288 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); |
288 | /* NOTE: use of CONNECTTIMEOUT without also | 289 | /* NOTE: use of CONNECTTIMEOUT without also |
289 | * setting NOSIGNAL results in really weird | 290 | * setting NOSIGNAL results in really weird |
290 | * crashes on my system! */ | 291 | * crashes on my system! */ |
291 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 292 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
292 | 293 | ||
293 | 294 | ||
294 | mret = curl_multi_add_handle (multi, c); | 295 | mret = curl_multi_add_handle (multi, c); |
296 | if (mret != CURLM_OK) | ||
297 | { | ||
298 | curl_multi_cleanup (multi); | ||
299 | curl_easy_cleanup (c); | ||
300 | zzuf_socat_stop (); | ||
301 | MHD_stop_daemon (d); | ||
302 | return 1024; | ||
303 | } | ||
304 | start = time (NULL); | ||
305 | while ((time (NULL) - start < 5) && (c != NULL)) | ||
306 | { | ||
307 | max = 0; | ||
308 | FD_ZERO (&rs); | ||
309 | FD_ZERO (&ws); | ||
310 | FD_ZERO (&es); | ||
311 | curl_multi_perform (multi, &running); | ||
312 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | ||
295 | if (mret != CURLM_OK) | 313 | if (mret != CURLM_OK) |
296 | { | 314 | { |
297 | curl_multi_cleanup (multi); | 315 | curl_multi_remove_handle (multi, c); |
298 | curl_easy_cleanup (c); | 316 | curl_multi_cleanup (multi); |
299 | zzuf_socat_stop (); | 317 | curl_easy_cleanup (c); |
300 | MHD_stop_daemon (d); | 318 | zzuf_socat_stop (); |
301 | return 1024; | 319 | MHD_stop_daemon (d); |
302 | } | 320 | return 2048; |
303 | start = time (NULL); | 321 | } |
304 | while ((time (NULL) - start < 5) && (c != NULL)) | 322 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) |
305 | { | 323 | { |
306 | max = 0; | 324 | curl_multi_remove_handle (multi, c); |
307 | FD_ZERO (&rs); | 325 | curl_multi_cleanup (multi); |
308 | FD_ZERO (&ws); | 326 | curl_easy_cleanup (c); |
309 | FD_ZERO (&es); | 327 | zzuf_socat_stop (); |
310 | curl_multi_perform (multi, &running); | 328 | MHD_stop_daemon (d); |
311 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 329 | return 4096; |
312 | if (mret != CURLM_OK) | 330 | } |
313 | { | 331 | tv.tv_sec = 0; |
314 | curl_multi_remove_handle (multi, c); | 332 | tv.tv_usec = 1000; |
315 | curl_multi_cleanup (multi); | 333 | select (max + 1, &rs, &ws, &es, &tv); |
316 | curl_easy_cleanup (c); | 334 | curl_multi_perform (multi, &running); |
317 | zzuf_socat_stop (); | 335 | if (running == 0) |
318 | MHD_stop_daemon (d); | 336 | { |
319 | return 2048; | 337 | curl_multi_info_read (multi, &running); |
320 | } | 338 | curl_multi_remove_handle (multi, c); |
321 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | 339 | curl_easy_cleanup (c); |
322 | { | 340 | c = NULL; |
323 | curl_multi_remove_handle (multi, c); | 341 | } |
324 | curl_multi_cleanup (multi); | 342 | MHD_run (d); |
325 | curl_easy_cleanup (c); | 343 | } |
326 | zzuf_socat_stop (); | 344 | if (c != NULL) |
327 | MHD_stop_daemon (d); | 345 | { |
328 | return 4096; | 346 | curl_multi_remove_handle (multi, c); |
329 | } | 347 | curl_easy_cleanup (c); |
330 | tv.tv_sec = 0; | ||
331 | tv.tv_usec = 1000; | ||
332 | select (max + 1, &rs, &ws, &es, &tv); | ||
333 | curl_multi_perform (multi, &running); | ||
334 | if (running == 0) | ||
335 | { | ||
336 | curl_multi_info_read (multi, &running); | ||
337 | curl_multi_remove_handle (multi, c); | ||
338 | curl_easy_cleanup (c); | ||
339 | c = NULL; | ||
340 | } | ||
341 | MHD_run (d); | ||
342 | } | ||
343 | if (c != NULL) | ||
344 | { | ||
345 | curl_multi_remove_handle (multi, c); | ||
346 | curl_easy_cleanup (c); | ||
347 | } | ||
348 | } | 348 | } |
349 | } | ||
349 | fprintf (stderr, "\n"); | 350 | fprintf (stderr, "\n"); |
350 | curl_multi_cleanup (multi); | 351 | curl_multi_cleanup (multi); |
351 | zzuf_socat_stop (); | 352 | zzuf_socat_stop (); |
@@ -359,15 +360,15 @@ int | |||
359 | main (int argc, char *const *argv) | 360 | main (int argc, char *const *argv) |
360 | { | 361 | { |
361 | unsigned int errorCount = 0; | 362 | unsigned int errorCount = 0; |
362 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 363 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
363 | 364 | ||
364 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 365 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
365 | return 2; | 366 | return 2; |
366 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 367 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
367 | { | 368 | { |
368 | errorCount += testInternalPut (); | 369 | errorCount += testInternalPut (); |
369 | errorCount += testMultithreadedPut (); | 370 | errorCount += testMultithreadedPut (); |
370 | } | 371 | } |
371 | errorCount += testExternalPut (); | 372 | errorCount += testExternalPut (); |
372 | if (errorCount != 0) | 373 | if (errorCount != 0) |
373 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 374 | fprintf (stderr, "Error (code: %u)\n", errorCount); |