aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_get_response_cleanup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_get_response_cleanup.c')
-rw-r--r--src/testcurl/test_get_response_cleanup.c259
1 files changed, 134 insertions, 125 deletions
diff --git a/src/testcurl/test_get_response_cleanup.c b/src/testcurl/test_get_response_cleanup.c
index 66653a93..04fe3204 100644
--- a/src/testcurl/test_get_response_cleanup.c
+++ b/src/testcurl/test_get_response_cleanup.c
@@ -53,10 +53,10 @@
53 53
54#include "mhd_has_in_name.h" 54#include "mhd_has_in_name.h"
55 55
56#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 56#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
57#undef CPU_COUNT 57#undef CPU_COUNT
58#endif 58#endif
59#if !defined(CPU_COUNT) 59#if ! defined(CPU_COUNT)
60#define CPU_COUNT 2 60#define CPU_COUNT 2
61#endif 61#endif
62 62
@@ -72,13 +72,13 @@ fork_curl (const char *url)
72{ 72{
73 pid_t ret; 73 pid_t ret;
74 74
75 ret = fork(); 75 ret = fork ();
76 if (ret != 0) 76 if (ret != 0)
77 return ret; 77 return ret;
78 execlp ("curl", "curl", "-s", "-N", "-o", "/dev/null", "-GET", url, NULL); 78 execlp ("curl", "curl", "-s", "-N", "-o", "/dev/null", "-GET", url, NULL);
79 fprintf (stderr, 79 fprintf (stderr,
80 "Failed to exec curl: %s\n", 80 "Failed to exec curl: %s\n",
81 strerror (errno)); 81 strerror (errno));
82 _exit (-1); 82 _exit (-1);
83} 83}
84 84
@@ -88,7 +88,7 @@ kill_curl (pid_t pid)
88{ 88{
89 int status; 89 int status;
90 90
91 //fprintf (stderr, "Killing curl\n"); 91 // fprintf (stderr, "Killing curl\n");
92 kill (pid, SIGTERM); 92 kill (pid, SIGTERM);
93 waitpid (pid, &status, 0); 93 waitpid (pid, &status, 0);
94} 94}
@@ -97,7 +97,7 @@ kill_curl (pid_t pid)
97static ssize_t 97static ssize_t
98push_callback (void *cls, uint64_t pos, char *buf, size_t max) 98push_callback (void *cls, uint64_t pos, char *buf, size_t max)
99{ 99{
100 (void)cls;(void)pos; /* Unused. Silent compiler warning. */ 100 (void) cls; (void) pos; /* Unused. Silent compiler warning. */
101 101
102 if (max == 0) 102 if (max == 0)
103 return 0; 103 return 0;
@@ -111,7 +111,7 @@ push_free_callback (void *cls)
111{ 111{
112 int *ok = cls; 112 int *ok = cls;
113 113
114 //fprintf (stderr, "Cleanup callback called!\n"); 114 // fprintf (stderr, "Cleanup callback called!\n");
115 *ok = 0; 115 *ok = 0;
116} 116}
117 117
@@ -129,23 +129,23 @@ ahc_echo (void *cls,
129 const char *me = cls; 129 const char *me = cls;
130 struct MHD_Response *response; 130 struct MHD_Response *response;
131 int ret; 131 int ret;
132 (void)url;(void)version; /* Unused. Silent compiler warning. */ 132 (void) url; (void) version; /* Unused. Silent compiler warning. */
133 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 133 (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
134 134
135 //fprintf (stderr, "In CB: %s!\n", method); 135 // fprintf (stderr, "In CB: %s!\n", method);
136 if (0 != strcmp (me, method)) 136 if (0 != strcmp (me, method))
137 return MHD_NO; /* unexpected method */ 137 return MHD_NO; /* unexpected method */
138 if (&ptr != *unused) 138 if (&ptr != *unused)
139 { 139 {
140 *unused = &ptr; 140 *unused = &ptr;
141 return MHD_YES; 141 return MHD_YES;
142 } 142 }
143 *unused = NULL; 143 *unused = NULL;
144 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 144 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
145 32 * 1024, 145 32 * 1024,
146 &push_callback, 146 &push_callback,
147 &ok, 147 &ok,
148 &push_free_callback); 148 &push_free_callback);
149 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 149 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
150 MHD_destroy_response (response); 150 MHD_destroy_response (response);
151 if (ret == MHD_NO) 151 if (ret == MHD_NO)
@@ -165,11 +165,11 @@ testInternalGet ()
165 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 165 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
166 port = 0; 166 port = 0;
167 else 167 else
168 { 168 {
169 port = 1180; 169 port = 1180;
170 if (oneone) 170 if (oneone)
171 port += 10; 171 port += 10;
172 } 172 }
173 173
174 ok = 1; 174 ok = 1;
175 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 175 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
@@ -177,21 +177,23 @@ testInternalGet ()
177 if (d == NULL) 177 if (d == NULL)
178 return 1; 178 return 1;
179 if (0 == port) 179 if (0 == port)
180 {
181 const union MHD_DaemonInfo *dinfo;
182 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
183 if ((NULL == dinfo) ||(0 == dinfo->port) )
180 { 184 {
181 const union MHD_DaemonInfo *dinfo; 185 MHD_stop_daemon (d); return 32;
182 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
183 if (NULL == dinfo || 0 == dinfo->port)
184 { MHD_stop_daemon (d); return 32; }
185 port = (int)dinfo->port;
186 } 186 }
187 port = (int) dinfo->port;
188 }
187 snprintf (url, 189 snprintf (url,
188 sizeof (url), 190 sizeof (url),
189 "http://127.0.0.1:%d/", 191 "http://127.0.0.1:%d/",
190 port); 192 port);
191 curl = fork_curl (url); 193 curl = fork_curl (url);
192 (void)sleep (1); 194 (void) sleep (1);
193 kill_curl (curl); 195 kill_curl (curl);
194 (void)sleep (1); 196 (void) sleep (1);
195 /* fprintf (stderr, "Stopping daemon!\n"); */ 197 /* fprintf (stderr, "Stopping daemon!\n"); */
196 MHD_stop_daemon (d); 198 MHD_stop_daemon (d);
197 if (ok != 0) 199 if (ok != 0)
@@ -211,47 +213,50 @@ testMultithreadedGet ()
211 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 213 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
212 port = 0; 214 port = 0;
213 else 215 else
214 { 216 {
215 port = 1181; 217 port = 1181;
216 if (oneone) 218 if (oneone)
217 port += 10; 219 port += 10;
218 } 220 }
219 221
220 ok = 1; 222 ok = 1;
221 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 223 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
224 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
222 port, NULL, NULL, &ahc_echo, "GET", 225 port, NULL, NULL, &ahc_echo, "GET",
223 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 2, 226 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 2,
224 MHD_OPTION_END); 227 MHD_OPTION_END);
225 if (d == NULL) 228 if (d == NULL)
226 return 16; 229 return 16;
227 if (0 == port) 230 if (0 == port)
231 {
232 const union MHD_DaemonInfo *dinfo;
233 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
234 if ((NULL == dinfo) ||(0 == dinfo->port) )
228 { 235 {
229 const union MHD_DaemonInfo *dinfo; 236 MHD_stop_daemon (d); return 32;
230 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
231 if (NULL == dinfo || 0 == dinfo->port)
232 { MHD_stop_daemon (d); return 32; }
233 port = (int)dinfo->port;
234 } 237 }
238 port = (int) dinfo->port;
239 }
235 snprintf (url, 240 snprintf (url,
236 sizeof (url), 241 sizeof (url),
237 "http://127.0.0.1:%d/", 242 "http://127.0.0.1:%d/",
238 port); 243 port);
239 //fprintf (stderr, "Forking cURL!\n"); 244 // fprintf (stderr, "Forking cURL!\n");
240 curl = fork_curl (url); 245 curl = fork_curl (url);
241 (void)sleep (1); 246 (void) sleep (1);
242 kill_curl (curl); 247 kill_curl (curl);
243 (void)sleep (1); 248 (void) sleep (1);
244 curl = fork_curl (url); 249 curl = fork_curl (url);
245 (void)sleep (1); 250 (void) sleep (1);
246 if (ok != 0) 251 if (ok != 0)
247 { 252 {
248 kill_curl (curl); 253 kill_curl (curl);
249 MHD_stop_daemon (d); 254 MHD_stop_daemon (d);
250 return 64; 255 return 64;
251 } 256 }
252 kill_curl (curl); 257 kill_curl (curl);
253 (void)sleep (1); 258 (void) sleep (1);
254 //fprintf (stderr, "Stopping daemon!\n"); 259 // fprintf (stderr, "Stopping daemon!\n");
255 MHD_stop_daemon (d); 260 MHD_stop_daemon (d);
256 if (ok != 0) 261 if (ok != 0)
257 return 32; 262 return 32;
@@ -271,11 +276,11 @@ testMultithreadedPoolGet ()
271 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 276 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
272 port = 0; 277 port = 0;
273 else 278 else
274 { 279 {
275 port = 1182; 280 port = 1182;
276 if (oneone) 281 if (oneone)
277 port += 10; 282 port += 10;
278 } 283 }
279 284
280 ok = 1; 285 ok = 1;
281 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 286 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
@@ -284,22 +289,24 @@ testMultithreadedPoolGet ()
284 if (d == NULL) 289 if (d == NULL)
285 return 64; 290 return 64;
286 if (0 == port) 291 if (0 == port)
292 {
293 const union MHD_DaemonInfo *dinfo;
294 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
295 if ((NULL == dinfo) ||(0 == dinfo->port) )
287 { 296 {
288 const union MHD_DaemonInfo *dinfo; 297 MHD_stop_daemon (d); return 32;
289 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
290 if (NULL == dinfo || 0 == dinfo->port)
291 { MHD_stop_daemon (d); return 32; }
292 port = (int)dinfo->port;
293 } 298 }
299 port = (int) dinfo->port;
300 }
294 snprintf (url, 301 snprintf (url,
295 sizeof (url), 302 sizeof (url),
296 "http://127.0.0.1:%d/", 303 "http://127.0.0.1:%d/",
297 port); 304 port);
298 curl = fork_curl (url); 305 curl = fork_curl (url);
299 (void)sleep (1); 306 (void) sleep (1);
300 kill_curl (curl); 307 kill_curl (curl);
301 (void)sleep (1); 308 (void) sleep (1);
302 //fprintf (stderr, "Stopping daemon!\n"); 309 // fprintf (stderr, "Stopping daemon!\n");
303 MHD_stop_daemon (d); 310 MHD_stop_daemon (d);
304 if (ok != 0) 311 if (ok != 0)
305 return 128; 312 return 128;
@@ -324,11 +331,11 @@ testExternalGet ()
324 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 331 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
325 port = 0; 332 port = 0;
326 else 333 else
327 { 334 {
328 port = 1183; 335 port = 1183;
329 if (oneone) 336 if (oneone)
330 port += 10; 337 port += 10;
331 } 338 }
332 339
333 ok = 1; 340 ok = 1;
334 d = MHD_start_daemon (MHD_USE_ERROR_LOG, 341 d = MHD_start_daemon (MHD_USE_ERROR_LOG,
@@ -336,13 +343,15 @@ testExternalGet ()
336 if (d == NULL) 343 if (d == NULL)
337 return 256; 344 return 256;
338 if (0 == port) 345 if (0 == port)
346 {
347 const union MHD_DaemonInfo *dinfo;
348 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
349 if ((NULL == dinfo) ||(0 == dinfo->port) )
339 { 350 {
340 const union MHD_DaemonInfo *dinfo; 351 MHD_stop_daemon (d); return 32;
341 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
342 if (NULL == dinfo || 0 == dinfo->port)
343 { MHD_stop_daemon (d); return 32; }
344 port = (int)dinfo->port;
345 } 352 }
353 port = (int) dinfo->port;
354 }
346 snprintf (url, 355 snprintf (url,
347 sizeof (url), 356 sizeof (url),
348 "http://127.0.0.1:%d/", 357 "http://127.0.0.1:%d/",
@@ -351,47 +360,47 @@ testExternalGet ()
351 360
352 start = time (NULL); 361 start = time (NULL);
353 while ((time (NULL) - start < 2)) 362 while ((time (NULL) - start < 2))
363 {
364 max = 0;
365 FD_ZERO (&rs);
366 FD_ZERO (&ws);
367 FD_ZERO (&es);
368 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
369 {
370 MHD_stop_daemon (d);
371 return 4096;
372 }
373 tv.tv_sec = 0;
374 tv.tv_usec = 1000;
375 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
354 { 376 {
355 max = 0; 377 if (EINTR != errno)
356 FD_ZERO (&rs); 378 abort ();
357 FD_ZERO (&ws);
358 FD_ZERO (&es);
359 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
360 {
361 MHD_stop_daemon (d);
362 return 4096;
363 }
364 tv.tv_sec = 0;
365 tv.tv_usec = 1000;
366 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
367 {
368 if (EINTR != errno)
369 abort ();
370 }
371 MHD_run (d);
372 } 379 }
380 MHD_run (d);
381 }
373 kill_curl (curl); 382 kill_curl (curl);
374 start = time (NULL); 383 start = time (NULL);
375 while ((time (NULL) - start < 2)) 384 while ((time (NULL) - start < 2))
385 {
386 max = 0;
387 FD_ZERO (&rs);
388 FD_ZERO (&ws);
389 FD_ZERO (&es);
390 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
391 {
392 MHD_stop_daemon (d);
393 return 4096;
394 }
395 tv.tv_sec = 0;
396 tv.tv_usec = 1000;
397 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
376 { 398 {
377 max = 0; 399 if (EINTR != errno)
378 FD_ZERO (&rs); 400 abort ();
379 FD_ZERO (&ws);
380 FD_ZERO (&es);
381 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
382 {
383 MHD_stop_daemon (d);
384 return 4096;
385 }
386 tv.tv_sec = 0;
387 tv.tv_usec = 1000;
388 if (-1 == select (max + 1, &rs, &ws, &es, &tv))
389 {
390 if (EINTR != errno)
391 abort ();
392 }
393 MHD_run (d);
394 } 401 }
402 MHD_run (d);
403 }
395 /* fprintf (stderr, "Stopping daemon!\n"); */ 404 /* fprintf (stderr, "Stopping daemon!\n"); */
396 MHD_stop_daemon (d); 405 MHD_stop_daemon (d);
397 if (ok != 0) 406 if (ok != 0)
@@ -404,28 +413,28 @@ int
404main (int argc, char *const *argv) 413main (int argc, char *const *argv)
405{ 414{
406 unsigned int errorCount = 0; 415 unsigned int errorCount = 0;
407 (void)argc; /* Unused. Silent compiler warning. */ 416 (void) argc; /* Unused. Silent compiler warning. */
408 417
409#ifndef _WIN32 418#ifndef _WIN32
410 /* Solaris has no way to disable SIGPIPE on socket disconnect. */ 419 /* Solaris has no way to disable SIGPIPE on socket disconnect. */
411 if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTOSUPPRESS_SIGPIPE)) 420 if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTOSUPPRESS_SIGPIPE))
412 { 421 {
413 struct sigaction act; 422 struct sigaction act;
414 423
415 act.sa_handler = SIG_IGN; 424 act.sa_handler = SIG_IGN;
416 sigaction(SIGPIPE, &act, NULL); 425 sigaction (SIGPIPE, &act, NULL);
417 } 426 }
418#endif /* _WIN32 */ 427#endif /* _WIN32 */
419 428
420 if (NULL == argv || 0 == argv[0]) 429 if ((NULL == argv)||(0 == argv[0]))
421 return 99; 430 return 99;
422 oneone = has_in_name (argv[0], "11"); 431 oneone = has_in_name (argv[0], "11");
423 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 432 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
424 { 433 {
425 errorCount += testInternalGet (); 434 errorCount += testInternalGet ();
426 errorCount += testMultithreadedGet (); 435 errorCount += testMultithreadedGet ();
427 errorCount += testMultithreadedPoolGet (); 436 errorCount += testMultithreadedPoolGet ();
428 } 437 }
429 errorCount += testExternalGet (); 438 errorCount += testExternalGet ();
430 if (errorCount != 0) 439 if (errorCount != 0)
431 fprintf (stderr, "Error (code: %u)\n", errorCount); 440 fprintf (stderr, "Error (code: %u)\n", errorCount);