aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_iplimit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_iplimit.c')
-rw-r--r--src/testcurl/test_iplimit.c338
1 files changed, 171 insertions, 167 deletions
diff --git a/src/testcurl/test_iplimit.c b/src/testcurl/test_iplimit.c
index 35ae6645..82d2923f 100644
--- a/src/testcurl/test_iplimit.c
+++ b/src/testcurl/test_iplimit.c
@@ -45,10 +45,10 @@
45#include <windows.h> 45#include <windows.h>
46#endif 46#endif
47 47
48#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 48#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
49#undef CPU_COUNT 49#undef CPU_COUNT
50#endif 50#endif
51#if !defined(CPU_COUNT) 51#if ! defined(CPU_COUNT)
52#define CPU_COUNT 2 52#define CPU_COUNT 2
53#endif 53#endif
54 54
@@ -86,19 +86,19 @@ ahc_echo (void *cls,
86 const char *me = cls; 86 const char *me = cls;
87 struct MHD_Response *response; 87 struct MHD_Response *response;
88 int ret; 88 int ret;
89 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 89 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
90 90
91 if (0 != strcmp (me, method)) 91 if (0 != strcmp (me, method))
92 return MHD_NO; /* unexpected method */ 92 return MHD_NO; /* unexpected method */
93 if (&ptr != *unused) 93 if (&ptr != *unused)
94 { 94 {
95 *unused = &ptr; 95 *unused = &ptr;
96 return MHD_YES; 96 return MHD_YES;
97 } 97 }
98 *unused = NULL; 98 *unused = NULL;
99 response = MHD_create_response_from_buffer (strlen (url), 99 response = MHD_create_response_from_buffer (strlen (url),
100 (void *) url, 100 (void *) url,
101 MHD_RESPMEM_MUST_COPY); 101 MHD_RESPMEM_MUST_COPY);
102 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 102 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
103 MHD_destroy_response (response); 103 MHD_destroy_response (response);
104 if (ret == MHD_NO) 104 if (ret == MHD_NO)
@@ -119,14 +119,14 @@ testMultithreadedGet ()
119 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 119 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
120 port = 0; 120 port = 0;
121 else 121 else
122 { 122 {
123 port = 1260; 123 port = 1260;
124 if (oneone) 124 if (oneone)
125 port += 5; 125 port += 5;
126 } 126 }
127 127
128 /* Test only valid for HTTP/1.1 (uses persistent connections) */ 128 /* Test only valid for HTTP/1.1 (uses persistent connections) */
129 if (!oneone) 129 if (! oneone)
130 return 0; 130 return 0;
131 131
132 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 132 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
@@ -137,83 +137,85 @@ testMultithreadedGet ()
137 if (d == NULL) 137 if (d == NULL)
138 return 16; 138 return 16;
139 if (0 == port) 139 if (0 == port)
140 {
141 const union MHD_DaemonInfo *dinfo;
142 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
143 if ((NULL == dinfo) ||(0 == dinfo->port) )
140 { 144 {
141 const union MHD_DaemonInfo *dinfo; 145 MHD_stop_daemon (d); return 32;
142 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
143 if (NULL == dinfo || 0 == dinfo->port)
144 { MHD_stop_daemon (d); return 32; }
145 port = (int)dinfo->port;
146 } 146 }
147 port = (int) dinfo->port;
148 }
147 149
148 for (k = 0; k < 3; ++k) 150 for (k = 0; k < 3; ++k)
151 {
152 struct CBC cbc[3];
153 CURL *cenv[3];
154 int i;
155
156 success = 0;
157 failure = 0;
158 for (i = 0; i < 3; ++i)
159 {
160 CURL *c;
161 CURLcode errornum;
162
163 cenv[i] = c = curl_easy_init ();
164 cbc[i].buf = buf;
165 cbc[i].size = 2048;
166 cbc[i].pos = 0;
167
168 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
169 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
170 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
171 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]);
172 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
173 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
174 curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L);
175 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
176 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
177 /* NOTE: use of CONNECTTIMEOUT without also
178 * setting NOSIGNAL results in really weird
179 * crashes on my system! */
180 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
181
182 errornum = curl_easy_perform (c);
183 if (CURLE_OK == errornum)
184 success++;
185 else
186 failure++;
187 }
188
189 /* Cleanup the environments */
190 for (i = 0; i < 3; ++i)
191 curl_easy_cleanup (cenv[i]);
192 if ( (2 != success) ||
193 (1 != failure) )
149 { 194 {
150 struct CBC cbc[3]; 195 fprintf (stderr,
151 CURL *cenv[3]; 196 "Unexpected number of success (%u) or failure (%u)\n",
152 int i; 197 success,
153 198 failure);
154 success = 0; 199 MHD_stop_daemon (d);
155 failure = 0; 200 return 32;
156 for (i = 0; i < 3; ++i) 201 }
157 { 202
158 CURL *c; 203 (void) sleep (2);
159 CURLcode errornum; 204
160 205 for (i = 0; i < 2; ++i)
161 cenv[i] = c = curl_easy_init (); 206 {
162 cbc[i].buf = buf; 207 if (cbc[i].pos != strlen ("/hello_world"))
163 cbc[i].size = 2048;
164 cbc[i].pos = 0;
165
166 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
167 curl_easy_setopt (c, CURLOPT_PORT, (long)port);
168 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
169 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]);
170 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
171 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
172 curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L);
173 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
174 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
175 /* NOTE: use of CONNECTTIMEOUT without also
176 * setting NOSIGNAL results in really weird
177 * crashes on my system! */
178 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
179
180 errornum = curl_easy_perform (c);
181 if (CURLE_OK == errornum)
182 success++;
183 else
184 failure++;
185 }
186
187 /* Cleanup the environments */
188 for (i = 0; i < 3; ++i)
189 curl_easy_cleanup (cenv[i]);
190 if ( (2 != success) ||
191 (1 != failure) )
192 { 208 {
193 fprintf (stderr,
194 "Unexpected number of success (%u) or failure (%u)\n",
195 success,
196 failure);
197 MHD_stop_daemon (d); 209 MHD_stop_daemon (d);
198 return 32; 210 return 64;
211 }
212 if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world")))
213 {
214 MHD_stop_daemon (d);
215 return 128;
199 } 216 }
200
201 (void)sleep(2);
202
203 for (i = 0; i < 2; ++i)
204 {
205 if (cbc[i].pos != strlen ("/hello_world"))
206 {
207 MHD_stop_daemon (d);
208 return 64;
209 }
210 if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world")))
211 {
212 MHD_stop_daemon (d);
213 return 128;
214 }
215 }
216 } 217 }
218 }
217 MHD_stop_daemon (d); 219 MHD_stop_daemon (d);
218 return 0; 220 return 0;
219} 221}
@@ -228,14 +230,14 @@ testMultithreadedPoolGet ()
228 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 230 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
229 port = 0; 231 port = 0;
230 else 232 else
231 { 233 {
232 port = 1261; 234 port = 1261;
233 if (oneone) 235 if (oneone)
234 port += 5; 236 port += 5;
235 } 237 }
236 238
237 /* Test only valid for HTTP/1.1 (uses persistent connections) */ 239 /* Test only valid for HTTP/1.1 (uses persistent connections) */
238 if (!oneone) 240 if (! oneone)
239 return 0; 241 return 0;
240 242
241 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 243 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
@@ -246,90 +248,92 @@ testMultithreadedPoolGet ()
246 if (d == NULL) 248 if (d == NULL)
247 return 16; 249 return 16;
248 if (0 == port) 250 if (0 == port)
251 {
252 const union MHD_DaemonInfo *dinfo;
253 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
254 if ((NULL == dinfo) ||(0 == dinfo->port) )
249 { 255 {
250 const union MHD_DaemonInfo *dinfo; 256 MHD_stop_daemon (d); return 32;
251 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
252 if (NULL == dinfo || 0 == dinfo->port)
253 { MHD_stop_daemon (d); return 32; }
254 port = (int)dinfo->port;
255 } 257 }
258 port = (int) dinfo->port;
259 }
256 260
257 for (k = 0; k < 3; ++k) 261 for (k = 0; k < 3; ++k)
262 {
263 struct CBC cbc[3];
264 CURL *cenv[3];
265 int i;
266
267 for (i = 0; i < 3; ++i)
258 { 268 {
259 struct CBC cbc[3]; 269 CURL *c;
260 CURL *cenv[3]; 270 CURLcode errornum;
261 int i; 271
262 272 cenv[i] = c = curl_easy_init ();
263 for (i = 0; i < 3; ++i) 273 cbc[i].buf = buf;
264 { 274 cbc[i].size = 2048;
265 CURL *c; 275 cbc[i].pos = 0;
266 CURLcode errornum; 276
267 277 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
268 cenv[i] = c = curl_easy_init (); 278 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
269 cbc[i].buf = buf; 279 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
270 cbc[i].size = 2048; 280 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]);
271 cbc[i].pos = 0; 281 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
272 282 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
273 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 283 curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L);
274 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 284 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
275 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 285 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
276 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]); 286 /* NOTE: use of CONNECTTIMEOUT without also
277 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 287 * setting NOSIGNAL results in really weird
278 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); 288 * crashes on my system! */
279 curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L); 289 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
280 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 290
281 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); 291 errornum = curl_easy_perform (c);
282 /* NOTE: use of CONNECTTIMEOUT without also 292 if ( ( (CURLE_OK != errornum) && (i < 2) ) ||
283 * setting NOSIGNAL results in really weird 293 ( (CURLE_OK == errornum) && (i == 2) ) )
284 * crashes on my system! */ 294 {
285 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 295 int j;
286 296
287 errornum = curl_easy_perform (c); 297 /* First 2 should succeed */
288 if ( ( (CURLE_OK != errornum) && (i < 2) ) || 298 if (i < 2)
289 ( (CURLE_OK == errornum) && (i == 2) ) ) 299 fprintf (stderr,
290 { 300 "curl_easy_perform failed: `%s'\n",
291 int j; 301 curl_easy_strerror (errornum));
292 302
293 /* First 2 should succeed */ 303 /* Last request should have failed */
294 if (i < 2) 304 else
295 fprintf (stderr, 305 fprintf (stderr,
296 "curl_easy_perform failed: `%s'\n", 306 "No error on IP address over limit\n");
297 curl_easy_strerror (errornum)); 307
298 308 for (j = 0; j < i; ++j)
299 /* Last request should have failed */ 309 curl_easy_cleanup (cenv[j]);
300 else 310 MHD_stop_daemon (d);
301 fprintf (stderr, 311 return 32;
302 "No error on IP address over limit\n"); 312 }
303 313 }
304 for (j = 0; j < i; ++j) 314
305 curl_easy_cleanup (cenv[j]); 315 /* Cleanup the environments */
306 MHD_stop_daemon (d); 316 for (i = 0; i < 3; ++i)
307 return 32; 317 curl_easy_cleanup (cenv[i]);
308 }
309 }
310
311 /* Cleanup the environments */
312 for (i = 0; i < 3; ++i)
313 curl_easy_cleanup (cenv[i]);
314
315 (void)sleep(2);
316
317 for (i = 0; i < 2; ++i)
318 {
319 if (cbc[i].pos != strlen ("/hello_world"))
320 {
321 MHD_stop_daemon (d);
322 return 64;
323 }
324 if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world")))
325 {
326 MHD_stop_daemon (d);
327 return 128;
328 }
329 }
330 318
319 (void) sleep (2);
331 320
321 for (i = 0; i < 2; ++i)
322 {
323 if (cbc[i].pos != strlen ("/hello_world"))
324 {
325 MHD_stop_daemon (d);
326 return 64;
327 }
328 if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world")))
329 {
330 MHD_stop_daemon (d);
331 return 128;
332 }
332 } 333 }
334
335
336 }
333 MHD_stop_daemon (d); 337 MHD_stop_daemon (d);
334 return 0; 338 return 0;
335} 339}
@@ -338,9 +342,9 @@ int
338main (int argc, char *const *argv) 342main (int argc, char *const *argv)
339{ 343{
340 unsigned int errorCount = 0; 344 unsigned int errorCount = 0;
341 (void)argc; /* Unused. Silent compiler warning. */ 345 (void) argc; /* Unused. Silent compiler warning. */
342 346
343 if (NULL == argv || 0 == argv[0]) 347 if ((NULL == argv)||(0 == argv[0]))
344 return 99; 348 return 99;
345 oneone = has_in_name (argv[0], "11"); 349 oneone = has_in_name (argv[0], "11");
346 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 350 if (0 != curl_global_init (CURL_GLOBAL_WIN32))