aboutsummaryrefslogtreecommitdiff
path: root/src/testzzuf/test_put.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testzzuf/test_put.c')
-rw-r--r--src/testzzuf/test_put.c310
1 files changed, 156 insertions, 154 deletions
diff --git a/src/testzzuf/test_put.c b/src/testzzuf/test_put.c
index 5a237ddd..605f4804 100644
--- a/src/testzzuf/test_put.c
+++ b/src/testzzuf/test_put.c
@@ -86,29 +86,29 @@ ahc_echo (void *cls,
86 int *done = cls; 86 int *done = cls;
87 struct MHD_Response *response; 87 struct MHD_Response *response;
88 int ret; 88 int ret;
89 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 89 (void) version; (void) unused; /* Unused. Silent compiler warning. */
90 90
91 if (0 != strcmp ("PUT", method)) 91 if (0 != strcmp ("PUT", method))
92 return MHD_NO; /* unexpected method */ 92 return MHD_NO; /* unexpected method */
93 if ((*done) == 0) 93 if ((*done) == 0)
94 {
95 if (*upload_data_size != 8)
96 return MHD_YES; /* not yet ready */
97 if (0 == memcmp (upload_data, "Hello123", 8))
94 { 98 {
95 if (*upload_data_size != 8) 99 *upload_data_size = 0;
96 return MHD_YES; /* not yet ready */
97 if (0 == memcmp (upload_data, "Hello123", 8))
98 {
99 *upload_data_size = 0;
100 }
101 else
102 {
103 printf ("Invalid upload data `%8s'!\n", upload_data);
104 return MHD_NO;
105 }
106 *done = 1;
107 return MHD_YES;
108 } 100 }
101 else
102 {
103 printf ("Invalid upload data `%8s'!\n", upload_data);
104 return MHD_NO;
105 }
106 *done = 1;
107 return MHD_YES;
108 }
109 response = MHD_create_response_from_buffer (strlen (url), 109 response = MHD_create_response_from_buffer (strlen (url),
110 (void *) url, 110 (void *) url,
111 MHD_RESPMEM_MUST_COPY); 111 MHD_RESPMEM_MUST_COPY);
112 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 112 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
113 MHD_destroy_response (response); 113 MHD_destroy_response (response);
114 return ret; 114 return ret;
@@ -129,37 +129,38 @@ testInternalPut ()
129 cbc.buf = buf; 129 cbc.buf = buf;
130 cbc.size = 2048; 130 cbc.size = 2048;
131 cbc.pos = 0; 131 cbc.pos = 0;
132 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 132 d = MHD_start_daemon (
133 11080, 133 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
134 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 134 11080,
135 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
135 if (d == NULL) 136 if (d == NULL)
136 return 1; 137 return 1;
137 zzuf_socat_start (); 138 zzuf_socat_start ();
138 for (i = 0; i < LOOP_COUNT; i++) 139 for (i = 0; i < LOOP_COUNT; i++)
139 { 140 {
140 fprintf (stderr, "."); 141 fprintf (stderr, ".");
141 c = curl_easy_init (); 142 c = curl_easy_init ();
142 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 143 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
143 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 144 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
144 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 145 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
145 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 146 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
146 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 147 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
147 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 148 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
148 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 149 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
149 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 150 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
150 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 151 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
151 if (oneone) 152 if (oneone)
152 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 153 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
153 else 154 else
154 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 155 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
155 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 156 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
156 /* NOTE: use of CONNECTTIMEOUT without also 157 /* NOTE: use of CONNECTTIMEOUT without also
157 * setting NOSIGNAL results in really weird 158 * setting NOSIGNAL results in really weird
158 * crashes on my system! */ 159 * crashes on my system! */
159 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 160 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
160 curl_easy_perform (c); 161 curl_easy_perform (c);
161 curl_easy_cleanup (c); 162 curl_easy_cleanup (c);
162 } 163 }
163 fprintf (stderr, "\n"); 164 fprintf (stderr, "\n");
164 zzuf_socat_stop (); 165 zzuf_socat_stop ();
165 MHD_stop_daemon (d); 166 MHD_stop_daemon (d);
@@ -180,37 +181,38 @@ testMultithreadedPut ()
180 cbc.buf = buf; 181 cbc.buf = buf;
181 cbc.size = 2048; 182 cbc.size = 2048;
182 cbc.pos = 0; 183 cbc.pos = 0;
183 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 184 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
185 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
184 11080, 186 11080,
185 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 187 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
186 if (d == NULL) 188 if (d == NULL)
187 return 16; 189 return 16;
188 zzuf_socat_start (); 190 zzuf_socat_start ();
189 for (i = 0; i < LOOP_COUNT; i++) 191 for (i = 0; i < LOOP_COUNT; i++)
190 { 192 {
191 fprintf (stderr, "."); 193 fprintf (stderr, ".");
192 c = curl_easy_init (); 194 c = curl_easy_init ();
193 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 195 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
194 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 196 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
195 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 197 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
196 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 198 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
197 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 199 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
198 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 200 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
199 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 201 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 202 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 203 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
202 if (oneone) 204 if (oneone)
203 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 205 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
204 else 206 else
205 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 207 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
206 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 208 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
207 /* NOTE: use of CONNECTTIMEOUT without also 209 /* NOTE: use of CONNECTTIMEOUT without also
208 * setting NOSIGNAL results in really weird 210 * setting NOSIGNAL results in really weird
209 * crashes on my system! */ 211 * crashes on my system! */
210 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 212 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
211 curl_easy_perform (c); 213 curl_easy_perform (c);
212 curl_easy_cleanup (c); 214 curl_easy_cleanup (c);
213 } 215 }
214 fprintf (stderr, "\n"); 216 fprintf (stderr, "\n");
215 zzuf_socat_stop (); 217 zzuf_socat_stop ();
216 MHD_stop_daemon (d); 218 MHD_stop_daemon (d);
@@ -242,99 +244,99 @@ testExternalPut ()
242 cbc.buf = buf; 244 cbc.buf = buf;
243 cbc.size = 2048; 245 cbc.size = 2048;
244 cbc.pos = 0; 246 cbc.pos = 0;
245 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 247 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
246 11080, 248 11080,
247 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 249 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
248 if (d == NULL) 250 if (d == NULL)
249 return 256; 251 return 256;
250 multi = curl_multi_init (); 252 multi = curl_multi_init ();
251 if (multi == NULL) 253 if (multi == NULL)
252 { 254 {
253 MHD_stop_daemon (d); 255 MHD_stop_daemon (d);
254 return 512; 256 return 512;
255 } 257 }
256 zzuf_socat_start (); 258 zzuf_socat_start ();
257 for (i = 0; i < LOOP_COUNT; i++) 259 for (i = 0; i < LOOP_COUNT; i++)
258 { 260 {
259 fprintf (stderr, "."); 261 fprintf (stderr, ".");
260 262
261 c = curl_easy_init (); 263 c = curl_easy_init ();
262 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 264 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
263 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 265 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
264 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 266 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
265 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 267 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
266 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 268 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
267 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 269 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
268 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 270 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
269 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 271 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
270 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 272 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
271 if (oneone) 273 if (oneone)
272 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 274 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
273 else 275 else
274 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 276 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
275 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 277 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
276 /* NOTE: use of CONNECTTIMEOUT without also 278 /* NOTE: use of CONNECTTIMEOUT without also
277 * setting NOSIGNAL results in really weird 279 * setting NOSIGNAL results in really weird
278 * crashes on my system! */ 280 * crashes on my system! */
279 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 281 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
280 282
281 283
282 284
283 mret = curl_multi_add_handle (multi, c); 285 mret = curl_multi_add_handle (multi, c);
286 if (mret != CURLM_OK)
287 {
288 curl_multi_cleanup (multi);
289 curl_easy_cleanup (c);
290 zzuf_socat_stop ();
291 MHD_stop_daemon (d);
292 return 1024;
293 }
294 start = time (NULL);
295 while ((time (NULL) - start < 5) && (c != NULL))
296 {
297 max = 0;
298 FD_ZERO (&rs);
299 FD_ZERO (&ws);
300 FD_ZERO (&es);
301 curl_multi_perform (multi, &running);
302 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
284 if (mret != CURLM_OK) 303 if (mret != CURLM_OK)
285 { 304 {
286 curl_multi_cleanup (multi); 305 curl_multi_remove_handle (multi, c);
287 curl_easy_cleanup (c); 306 curl_multi_cleanup (multi);
288 zzuf_socat_stop (); 307 curl_easy_cleanup (c);
289 MHD_stop_daemon (d); 308 zzuf_socat_stop ();
290 return 1024; 309 MHD_stop_daemon (d);
291 } 310 return 2048;
292 start = time (NULL); 311 }
293 while ((time (NULL) - start < 5) && (c != NULL)) 312 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
294 { 313 {
295 max = 0; 314 curl_multi_remove_handle (multi, c);
296 FD_ZERO (&rs); 315 curl_multi_cleanup (multi);
297 FD_ZERO (&ws); 316 curl_easy_cleanup (c);
298 FD_ZERO (&es); 317 zzuf_socat_stop ();
299 curl_multi_perform (multi, &running); 318 MHD_stop_daemon (d);
300 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 319 return 4096;
301 if (mret != CURLM_OK) 320 }
302 { 321 tv.tv_sec = 0;
303 curl_multi_remove_handle (multi, c); 322 tv.tv_usec = 1000;
304 curl_multi_cleanup (multi); 323 select (max + 1, &rs, &ws, &es, &tv);
305 curl_easy_cleanup (c); 324 curl_multi_perform (multi, &running);
306 zzuf_socat_stop (); 325 if (running == 0)
307 MHD_stop_daemon (d); 326 {
308 return 2048; 327 curl_multi_info_read (multi, &running);
309 } 328 curl_multi_remove_handle (multi, c);
310 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 329 curl_easy_cleanup (c);
311 { 330 c = NULL;
312 curl_multi_remove_handle (multi, c); 331 }
313 curl_multi_cleanup (multi); 332 MHD_run (d);
314 curl_easy_cleanup (c); 333 }
315 zzuf_socat_stop (); 334 if (c != NULL)
316 MHD_stop_daemon (d); 335 {
317 return 4096; 336 curl_multi_remove_handle (multi, c);
318 } 337 curl_easy_cleanup (c);
319 tv.tv_sec = 0;
320 tv.tv_usec = 1000;
321 select (max + 1, &rs, &ws, &es, &tv);
322 curl_multi_perform (multi, &running);
323 if (running == 0)
324 {
325 curl_multi_info_read (multi, &running);
326 curl_multi_remove_handle (multi, c);
327 curl_easy_cleanup (c);
328 c = NULL;
329 }
330 MHD_run (d);
331 }
332 if (c != NULL)
333 {
334 curl_multi_remove_handle (multi, c);
335 curl_easy_cleanup (c);
336 }
337 } 338 }
339 }
338 fprintf (stderr, "\n"); 340 fprintf (stderr, "\n");
339 curl_multi_cleanup (multi); 341 curl_multi_cleanup (multi);
340 zzuf_socat_stop (); 342 zzuf_socat_stop ();
@@ -347,17 +349,17 @@ int
347main (int argc, char *const *argv) 349main (int argc, char *const *argv)
348{ 350{
349 unsigned int errorCount = 0; 351 unsigned int errorCount = 0;
350 (void)argc; /* Unused. Silent compiler warning. */ 352 (void) argc; /* Unused. Silent compiler warning. */
351 353
352 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 354 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
353 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 355 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
354 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 356 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
355 return 2; 357 return 2;
356 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 358 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
357 { 359 {
358 errorCount += testInternalPut (); 360 errorCount += testInternalPut ();
359 errorCount += testMultithreadedPut (); 361 errorCount += testMultithreadedPut ();
360 } 362 }
361 errorCount += testExternalPut (); 363 errorCount += testExternalPut ();
362 if (errorCount != 0) 364 if (errorCount != 0)
363 fprintf (stderr, "Error (code: %u)\n", errorCount); 365 fprintf (stderr, "Error (code: %u)\n", errorCount);