aboutsummaryrefslogtreecommitdiff
path: root/src/testzzuf/test_get_chunked.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testzzuf/test_get_chunked.c')
-rw-r--r--src/testzzuf/test_get_chunked.c246
1 files changed, 124 insertions, 122 deletions
diff --git a/src/testzzuf/test_get_chunked.c b/src/testzzuf/test_get_chunked.c
index 2a16202b..facad587 100644
--- a/src/testzzuf/test_get_chunked.c
+++ b/src/testzzuf/test_get_chunked.c
@@ -67,10 +67,10 @@ crc (void *cls, uint64_t pos, char *buf, size_t max)
67 struct MHD_Response **responseptr = cls; 67 struct MHD_Response **responseptr = cls;
68 68
69 if (pos == 128 * 10) 69 if (pos == 128 * 10)
70 { 70 {
71 MHD_add_response_header (*responseptr, "Footer", "working"); 71 MHD_add_response_header (*responseptr, "Footer", "working");
72 return MHD_CONTENT_READER_END_OF_STREAM; 72 return MHD_CONTENT_READER_END_OF_STREAM;
73 } 73 }
74 if (max < 128) 74 if (max < 128)
75 abort (); /* should not happen in this testcase... */ 75 abort (); /* should not happen in this testcase... */
76 memset (buf, 'A' + (pos / 128), 128); 76 memset (buf, 'A' + (pos / 128), 128);
@@ -108,11 +108,11 @@ ahc_echo (void *cls,
108 if (0 != strcmp (me, method)) 108 if (0 != strcmp (me, method))
109 return MHD_NO; /* unexpected method */ 109 return MHD_NO; /* unexpected method */
110 if (&aptr != *ptr) 110 if (&aptr != *ptr)
111 { 111 {
112 /* do never respond on first call */ 112 /* do never respond on first call */
113 *ptr = &aptr; 113 *ptr = &aptr;
114 return MHD_YES; 114 return MHD_YES;
115 } 115 }
116 responseptr = malloc (sizeof (struct MHD_Response *)); 116 responseptr = malloc (sizeof (struct MHD_Response *));
117 if (NULL == responseptr) 117 if (NULL == responseptr)
118 return MHD_NO; 118 return MHD_NO;
@@ -144,29 +144,30 @@ testInternalGet ()
144 cbc.buf = buf; 144 cbc.buf = buf;
145 cbc.size = 2048; 145 cbc.size = 2048;
146 cbc.pos = 0; 146 cbc.pos = 0;
147 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 147 d = MHD_start_daemon (
148 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 148 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
149 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
149 if (d == NULL) 150 if (d == NULL)
150 return 1; 151 return 1;
151 zzuf_socat_start (); 152 zzuf_socat_start ();
152 for (i = 0; i < LOOP_COUNT; i++) 153 for (i = 0; i < LOOP_COUNT; i++)
153 { 154 {
154 fprintf (stderr, "."); 155 fprintf (stderr, ".");
155 c = curl_easy_init (); 156 c = curl_easy_init ();
156 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 157 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
157 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 158 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
158 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 159 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
159 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 160 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
160 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 161 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
161 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 162 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
162 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 163 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
163 /* NOTE: use of CONNECTTIMEOUT without also 164 /* NOTE: use of CONNECTTIMEOUT without also
164 * setting NOSIGNAL results in really weird 165 * setting NOSIGNAL results in really weird
165 * crashes on my system! */ 166 * crashes on my system! */
166 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 167 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
167 curl_easy_perform (c); 168 curl_easy_perform (c);
168 curl_easy_cleanup (c); 169 curl_easy_cleanup (c);
169 } 170 }
170 fprintf (stderr, "\n"); 171 fprintf (stderr, "\n");
171 zzuf_socat_stop (); 172 zzuf_socat_stop ();
172 MHD_stop_daemon (d); 173 MHD_stop_daemon (d);
@@ -185,29 +186,30 @@ testMultithreadedGet ()
185 cbc.buf = buf; 186 cbc.buf = buf;
186 cbc.size = 2048; 187 cbc.size = 2048;
187 cbc.pos = 0; 188 cbc.pos = 0;
188 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 */,
189 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 191 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
190 if (d == NULL) 192 if (d == NULL)
191 return 16; 193 return 16;
192 zzuf_socat_start (); 194 zzuf_socat_start ();
193 for (i = 0; i < LOOP_COUNT; i++) 195 for (i = 0; i < LOOP_COUNT; i++)
194 { 196 {
195 fprintf (stderr, "."); 197 fprintf (stderr, ".");
196 c = curl_easy_init (); 198 c = curl_easy_init ();
197 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 199 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
198 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 200 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
199 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 201 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
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 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
203 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 205 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
204 /* NOTE: use of CONNECTTIMEOUT without also 206 /* NOTE: use of CONNECTTIMEOUT without also
205 * setting NOSIGNAL results in really weird 207 * setting NOSIGNAL results in really weird
206 * crashes on my system! */ 208 * crashes on my system! */
207 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 209 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
208 curl_easy_perform (c); 210 curl_easy_perform (c);
209 curl_easy_cleanup (c); 211 curl_easy_cleanup (c);
210 } 212 }
211 fprintf (stderr, "\n"); 213 fprintf (stderr, "\n");
212 zzuf_socat_stop (); 214 zzuf_socat_stop ();
213 MHD_stop_daemon (d); 215 MHD_stop_daemon (d);
@@ -237,87 +239,87 @@ testExternalGet ()
237 cbc.buf = buf; 239 cbc.buf = buf;
238 cbc.size = 2048; 240 cbc.size = 2048;
239 cbc.pos = 0; 241 cbc.pos = 0;
240 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 242 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
241 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 243 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
242 if (d == NULL) 244 if (d == NULL)
243 return 256; 245 return 256;
244 multi = curl_multi_init (); 246 multi = curl_multi_init ();
245 if (multi == NULL) 247 if (multi == NULL)
248 {
249 MHD_stop_daemon (d);
250 return 512;
251 }
252 zzuf_socat_start ();
253 for (i = 0; i < LOOP_COUNT; i++)
254 {
255 fprintf (stderr, ".");
256 c = curl_easy_init ();
257 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
258 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
259 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
260 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
261 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
262 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
263 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
264 /* NOTE: use of CONNECTTIMEOUT without also
265 * setting NOSIGNAL results in really weird
266 * crashes on my system! */
267 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
268 mret = curl_multi_add_handle (multi, c);
269 if (mret != CURLM_OK)
246 { 270 {
271 curl_multi_cleanup (multi);
272 curl_easy_cleanup (c);
273 zzuf_socat_stop ();
247 MHD_stop_daemon (d); 274 MHD_stop_daemon (d);
248 return 512; 275 return 1024;
249 } 276 }
250 zzuf_socat_start (); 277 start = time (NULL);
251 for (i = 0; i < LOOP_COUNT; i++) 278 while ((time (NULL) - start < 5) && (c != NULL))
252 { 279 {
253 fprintf (stderr, "."); 280 max = 0;
254 c = curl_easy_init (); 281 FD_ZERO (&rs);
255 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 282 FD_ZERO (&ws);
256 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 283 FD_ZERO (&es);
257 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 284 curl_multi_perform (multi, &running);
258 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 285 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
259 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
260 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
261 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
262 /* NOTE: use of CONNECTTIMEOUT without also
263 * setting NOSIGNAL results in really weird
264 * crashes on my system! */
265 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
266 mret = curl_multi_add_handle (multi, c);
267 if (mret != CURLM_OK) 286 if (mret != CURLM_OK)
268 { 287 {
269 curl_multi_cleanup (multi); 288 curl_multi_remove_handle (multi, c);
270 curl_easy_cleanup (c); 289 curl_multi_cleanup (multi);
271 zzuf_socat_stop (); 290 curl_easy_cleanup (c);
272 MHD_stop_daemon (d); 291 zzuf_socat_stop ();
273 return 1024; 292 MHD_stop_daemon (d);
274 } 293 return 2048;
275 start = time (NULL); 294 }
276 while ((time (NULL) - start < 5) && (c != NULL)) 295 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
277 { 296 {
278 max = 0; 297 curl_multi_remove_handle (multi, c);
279 FD_ZERO (&rs); 298 curl_multi_cleanup (multi);
280 FD_ZERO (&ws); 299 curl_easy_cleanup (c);
281 FD_ZERO (&es); 300 zzuf_socat_stop ();
282 curl_multi_perform (multi, &running); 301 MHD_stop_daemon (d);
283 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 302 return 4096;
284 if (mret != CURLM_OK) 303 }
285 { 304 tv.tv_sec = 0;
286 curl_multi_remove_handle (multi, c); 305 tv.tv_usec = 1000;
287 curl_multi_cleanup (multi); 306 select (max + 1, &rs, &ws, &es, &tv);
288 curl_easy_cleanup (c); 307 curl_multi_perform (multi, &running);
289 zzuf_socat_stop (); 308 if (running == 0)
290 MHD_stop_daemon (d); 309 {
291 return 2048; 310 curl_multi_info_read (multi, &running);
292 } 311 curl_multi_remove_handle (multi, c);
293 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 312 curl_easy_cleanup (c);
294 { 313 c = NULL;
295 curl_multi_remove_handle (multi, c); 314 }
296 curl_multi_cleanup (multi); 315 MHD_run (d);
297 curl_easy_cleanup (c);
298 zzuf_socat_stop ();
299 MHD_stop_daemon (d);
300 return 4096;
301 }
302 tv.tv_sec = 0;
303 tv.tv_usec = 1000;
304 select (max + 1, &rs, &ws, &es, &tv);
305 curl_multi_perform (multi, &running);
306 if (running == 0)
307 {
308 curl_multi_info_read (multi, &running);
309 curl_multi_remove_handle (multi, c);
310 curl_easy_cleanup (c);
311 c = NULL;
312 }
313 MHD_run (d);
314 }
315 if (c != NULL)
316 {
317 curl_multi_remove_handle (multi, c);
318 curl_easy_cleanup (c);
319 }
320 } 316 }
317 if (c != NULL)
318 {
319 curl_multi_remove_handle (multi, c);
320 curl_easy_cleanup (c);
321 }
322 }
321 fprintf (stderr, "\n"); 323 fprintf (stderr, "\n");
322 curl_multi_cleanup (multi); 324 curl_multi_cleanup (multi);
323 zzuf_socat_stop (); 325 zzuf_socat_stop ();
@@ -331,15 +333,15 @@ int
331main (int argc, char *const *argv) 333main (int argc, char *const *argv)
332{ 334{
333 unsigned int errorCount = 0; 335 unsigned int errorCount = 0;
334 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 336 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
335 337
336 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 338 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
337 return 2; 339 return 2;
338 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 340 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
339 { 341 {
340 errorCount += testInternalGet (); 342 errorCount += testInternalGet ();
341 errorCount += testMultithreadedGet (); 343 errorCount += testMultithreadedGet ();
342 } 344 }
343 errorCount += testExternalGet (); 345 errorCount += testExternalGet ();
344 if (errorCount != 0) 346 if (errorCount != 0)
345 fprintf (stderr, "Error (code: %u)\n", errorCount); 347 fprintf (stderr, "Error (code: %u)\n", errorCount);