aboutsummaryrefslogtreecommitdiff
path: root/src/testzzuf/test_get.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testzzuf/test_get.c')
-rw-r--r--src/testzzuf/test_get.c262
1 files changed, 132 insertions, 130 deletions
diff --git a/src/testzzuf/test_get.c b/src/testzzuf/test_get.c
index 08954226..cfa70b13 100644
--- a/src/testzzuf/test_get.c
+++ b/src/testzzuf/test_get.c
@@ -72,19 +72,19 @@ ahc_echo (void *cls,
72 const char *me = cls; 72 const char *me = cls;
73 struct MHD_Response *response; 73 struct MHD_Response *response;
74 int ret; 74 int ret;
75 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 75 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
76 76
77 if (0 != strcmp (me, method)) 77 if (0 != strcmp (me, method))
78 return MHD_NO; /* unexpected method */ 78 return MHD_NO; /* unexpected method */
79 if (&ptr != *unused) 79 if (&ptr != *unused)
80 { 80 {
81 *unused = &ptr; 81 *unused = &ptr;
82 return MHD_YES; 82 return MHD_YES;
83 } 83 }
84 *unused = NULL; 84 *unused = NULL;
85 response = MHD_create_response_from_buffer (strlen (url), 85 response = MHD_create_response_from_buffer (strlen (url),
86 (void *) url, 86 (void *) url,
87 MHD_RESPMEM_MUST_COPY); 87 MHD_RESPMEM_MUST_COPY);
88 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 88 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
89 MHD_destroy_response (response); 89 MHD_destroy_response (response);
90 if (ret == MHD_NO) 90 if (ret == MHD_NO)
@@ -105,32 +105,33 @@ testInternalGet ()
105 cbc.buf = buf; 105 cbc.buf = buf;
106 cbc.size = 2048; 106 cbc.size = 2048;
107 cbc.pos = 0; 107 cbc.pos = 0;
108 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 108 d = MHD_start_daemon (
109 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 109 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
110 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
110 if (d == NULL) 111 if (d == NULL)
111 return 1; 112 return 1;
112 zzuf_socat_start (); 113 zzuf_socat_start ();
113 for (i = 0; i < LOOP_COUNT; i++) 114 for (i = 0; i < LOOP_COUNT; i++)
114 { 115 {
115 fprintf (stderr, "."); 116 fprintf (stderr, ".");
116 c = curl_easy_init (); 117 c = curl_easy_init ();
117 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 118 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
118 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 119 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
119 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 120 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
120 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 121 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
121 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 122 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
122 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 123 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
123 if (oneone) 124 if (oneone)
124 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 125 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
125 else 126 else
126 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 127 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
127 /* NOTE: use of CONNECTTIMEOUT without also 128 /* NOTE: use of CONNECTTIMEOUT without also
128 * setting NOSIGNAL results in really weird 129 * setting NOSIGNAL results in really weird
129 * crashes on my system! */ 130 * crashes on my system! */
130 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 131 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
131 curl_easy_perform (c); 132 curl_easy_perform (c);
132 curl_easy_cleanup (c); 133 curl_easy_cleanup (c);
133 } 134 }
134 fprintf (stderr, "\n"); 135 fprintf (stderr, "\n");
135 zzuf_socat_stop (); 136 zzuf_socat_stop ();
136 MHD_stop_daemon (d); 137 MHD_stop_daemon (d);
@@ -149,32 +150,33 @@ testMultithreadedGet ()
149 cbc.buf = buf; 150 cbc.buf = buf;
150 cbc.size = 2048; 151 cbc.size = 2048;
151 cbc.pos = 0; 152 cbc.pos = 0;
152 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 153 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
154 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
153 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 155 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
154 if (d == NULL) 156 if (d == NULL)
155 return 16; 157 return 16;
156 zzuf_socat_start (); 158 zzuf_socat_start ();
157 for (i = 0; i < LOOP_COUNT; i++) 159 for (i = 0; i < LOOP_COUNT; i++)
158 { 160 {
159 fprintf (stderr, "."); 161 fprintf (stderr, ".");
160 c = curl_easy_init (); 162 c = curl_easy_init ();
161 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 163 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
162 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 164 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
163 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 165 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
164 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 166 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
165 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 167 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
166 if (oneone) 168 if (oneone)
167 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 169 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
168 else 170 else
169 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 171 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
170 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 172 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
171 /* NOTE: use of CONNECTTIMEOUT without also 173 /* NOTE: use of CONNECTTIMEOUT without also
172 * setting NOSIGNAL results in really weird 174 * setting NOSIGNAL results in really weird
173 * crashes on my system! */ 175 * crashes on my system! */
174 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 176 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
175 curl_easy_perform (c); 177 curl_easy_perform (c);
176 curl_easy_cleanup (c); 178 curl_easy_cleanup (c);
177 } 179 }
178 fprintf (stderr, "\n"); 180 fprintf (stderr, "\n");
179 zzuf_socat_stop (); 181 zzuf_socat_stop ();
180 MHD_stop_daemon (d); 182 MHD_stop_daemon (d);
@@ -204,90 +206,90 @@ testExternalGet ()
204 cbc.buf = buf; 206 cbc.buf = buf;
205 cbc.size = 2048; 207 cbc.size = 2048;
206 cbc.pos = 0; 208 cbc.pos = 0;
207 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 209 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
208 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 210 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
209 if (d == NULL) 211 if (d == NULL)
210 return 256; 212 return 256;
211 multi = curl_multi_init (); 213 multi = curl_multi_init ();
212 if (multi == NULL) 214 if (multi == NULL)
215 {
216 MHD_stop_daemon (d);
217 return 512;
218 }
219 zzuf_socat_start ();
220 for (i = 0; i < LOOP_COUNT; i++)
221 {
222 fprintf (stderr, ".");
223 c = curl_easy_init ();
224 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
225 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
226 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
227 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
228 if (oneone)
229 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
230 else
231 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
232 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
233 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
234 /* NOTE: use of CONNECTTIMEOUT without also
235 * setting NOSIGNAL results in really weird
236 * crashes on my system! */
237 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
238 mret = curl_multi_add_handle (multi, c);
239 if (mret != CURLM_OK)
213 { 240 {
241 curl_multi_cleanup (multi);
242 curl_easy_cleanup (c);
243 zzuf_socat_stop ();
214 MHD_stop_daemon (d); 244 MHD_stop_daemon (d);
215 return 512; 245 return 1024;
216 } 246 }
217 zzuf_socat_start (); 247 start = time (NULL);
218 for (i = 0; i < LOOP_COUNT; i++) 248 while ((time (NULL) - start < 5) && (c != NULL))
219 { 249 {
220 fprintf (stderr, "."); 250 max = 0;
221 c = curl_easy_init (); 251 FD_ZERO (&rs);
222 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 252 FD_ZERO (&ws);
223 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 253 FD_ZERO (&es);
224 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 254 curl_multi_perform (multi, &running);
225 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 255 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
226 if (oneone)
227 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
228 else
229 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
230 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
231 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
232 /* NOTE: use of CONNECTTIMEOUT without also
233 * setting NOSIGNAL results in really weird
234 * crashes on my system! */
235 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
236 mret = curl_multi_add_handle (multi, c);
237 if (mret != CURLM_OK) 256 if (mret != CURLM_OK)
238 { 257 {
239 curl_multi_cleanup (multi); 258 curl_multi_remove_handle (multi, c);
240 curl_easy_cleanup (c); 259 curl_multi_cleanup (multi);
241 zzuf_socat_stop (); 260 curl_easy_cleanup (c);
242 MHD_stop_daemon (d); 261 zzuf_socat_stop ();
243 return 1024; 262 MHD_stop_daemon (d);
244 } 263 return 2048;
245 start = time (NULL); 264 }
246 while ((time (NULL) - start < 5) && (c != NULL)) 265 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
247 { 266 {
248 max = 0; 267 curl_multi_remove_handle (multi, c);
249 FD_ZERO (&rs); 268 curl_multi_cleanup (multi);
250 FD_ZERO (&ws); 269 curl_easy_cleanup (c);
251 FD_ZERO (&es); 270 zzuf_socat_stop ();
252 curl_multi_perform (multi, &running); 271 MHD_stop_daemon (d);
253 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 272 return 4096;
254 if (mret != CURLM_OK) 273 }
255 { 274 tv.tv_sec = 0;
256 curl_multi_remove_handle (multi, c); 275 tv.tv_usec = 1000;
257 curl_multi_cleanup (multi); 276 select (max + 1, &rs, &ws, &es, &tv);
258 curl_easy_cleanup (c); 277 curl_multi_perform (multi, &running);
259 zzuf_socat_stop (); 278 if (running == 0)
260 MHD_stop_daemon (d); 279 {
261 return 2048; 280 curl_multi_info_read (multi, &running);
262 } 281 curl_multi_remove_handle (multi, c);
263 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 282 curl_easy_cleanup (c);
264 { 283 c = NULL;
265 curl_multi_remove_handle (multi, c); 284 }
266 curl_multi_cleanup (multi); 285 MHD_run (d);
267 curl_easy_cleanup (c);
268 zzuf_socat_stop ();
269 MHD_stop_daemon (d);
270 return 4096;
271 }
272 tv.tv_sec = 0;
273 tv.tv_usec = 1000;
274 select (max + 1, &rs, &ws, &es, &tv);
275 curl_multi_perform (multi, &running);
276 if (running == 0)
277 {
278 curl_multi_info_read (multi, &running);
279 curl_multi_remove_handle (multi, c);
280 curl_easy_cleanup (c);
281 c = NULL;
282 }
283 MHD_run (d);
284 }
285 if (c != NULL)
286 {
287 curl_multi_remove_handle (multi, c);
288 curl_easy_cleanup (c);
289 }
290 } 286 }
287 if (c != NULL)
288 {
289 curl_multi_remove_handle (multi, c);
290 curl_easy_cleanup (c);
291 }
292 }
291 fprintf (stderr, "\n"); 293 fprintf (stderr, "\n");
292 curl_multi_cleanup (multi); 294 curl_multi_cleanup (multi);
293 zzuf_socat_stop (); 295 zzuf_socat_stop ();
@@ -300,17 +302,17 @@ int
300main (int argc, char *const *argv) 302main (int argc, char *const *argv)
301{ 303{
302 unsigned int errorCount = 0; 304 unsigned int errorCount = 0;
303 (void)argc; /* Unused. Silent compiler warning. */ 305 (void) argc; /* Unused. Silent compiler warning. */
304 306
305 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 307 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
306 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 308 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
307 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 309 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
308 return 2; 310 return 2;
309 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 311 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
310 { 312 {
311 errorCount += testInternalGet (); 313 errorCount += testInternalGet ();
312 errorCount += testMultithreadedGet (); 314 errorCount += testMultithreadedGet ();
313 } 315 }
314 errorCount += testExternalGet (); 316 errorCount += testExternalGet ();
315 if (errorCount != 0) 317 if (errorCount != 0)
316 fprintf (stderr, "Error (code: %u)\n", errorCount); 318 fprintf (stderr, "Error (code: %u)\n", errorCount);