aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_timeout.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_timeout.c')
-rw-r--r--src/testcurl/test_timeout.c178
1 files changed, 92 insertions, 86 deletions
diff --git a/src/testcurl/test_timeout.c b/src/testcurl/test_timeout.c
index d87bb368..a17b0fb8 100644
--- a/src/testcurl/test_timeout.c
+++ b/src/testcurl/test_timeout.c
@@ -51,37 +51,37 @@ struct CBC
51}; 51};
52 52
53 53
54static void 54static void
55termination_cb (void *cls, 55termination_cb (void *cls,
56 struct MHD_Connection *connection, 56 struct MHD_Connection *connection,
57 void **con_cls, 57 void **con_cls,
58 enum MHD_RequestTerminationCode toe) 58 enum MHD_RequestTerminationCode toe)
59{ 59{
60 int *test = cls; 60 int *test = cls;
61 (void)connection;(void)con_cls; /* Unused. Silent compiler warning. */ 61 (void) connection; (void) con_cls; /* Unused. Silent compiler warning. */
62 62
63 switch (toe) 63 switch (toe)
64 {
65 case MHD_REQUEST_TERMINATED_COMPLETED_OK:
66 if (test == &withoutTimeout)
64 { 67 {
65 case MHD_REQUEST_TERMINATED_COMPLETED_OK : 68 withoutTimeout = 0;
66 if (test == &withoutTimeout)
67 {
68 withoutTimeout = 0;
69 }
70 break;
71 case MHD_REQUEST_TERMINATED_WITH_ERROR :
72 case MHD_REQUEST_TERMINATED_READ_ERROR :
73 break;
74 case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED :
75 if (test == &withTimeout)
76 {
77 withTimeout = 0;
78 }
79 break;
80 case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN:
81 break;
82 case MHD_REQUEST_TERMINATED_CLIENT_ABORT:
83 break;
84 } 69 }
70 break;
71 case MHD_REQUEST_TERMINATED_WITH_ERROR:
72 case MHD_REQUEST_TERMINATED_READ_ERROR:
73 break;
74 case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED:
75 if (test == &withTimeout)
76 {
77 withTimeout = 0;
78 }
79 break;
80 case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN:
81 break;
82 case MHD_REQUEST_TERMINATED_CLIENT_ABORT:
83 break;
84 }
85} 85}
86 86
87 87
@@ -93,7 +93,7 @@ putBuffer (void *stream, size_t size, size_t nmemb, void *ptr)
93 93
94 wrt = size * nmemb; 94 wrt = size * nmemb;
95 if (wrt > 8 - (*pos)) 95 if (wrt > 8 - (*pos))
96 wrt = 8 - (*pos); 96 wrt = 8 - (*pos);
97 memcpy (stream, &("Hello123"[*pos]), wrt); 97 memcpy (stream, &("Hello123"[*pos]), wrt);
98 (*pos) += wrt; 98 (*pos) += wrt;
99 return wrt; 99 return wrt;
@@ -103,7 +103,7 @@ putBuffer (void *stream, size_t size, size_t nmemb, void *ptr)
103static size_t 103static size_t
104putBuffer_fail (void *stream, size_t size, size_t nmemb, void *ptr) 104putBuffer_fail (void *stream, size_t size, size_t nmemb, void *ptr)
105{ 105{
106 (void)stream;(void)size;(void)nmemb;(void)ptr; /* Unused. Silent compiler warning. */ 106 (void) stream; (void) size; (void) nmemb; (void) ptr; /* Unused. Silent compiler warning. */
107 return 0; 107 return 0;
108} 108}
109 109
@@ -133,29 +133,29 @@ ahc_echo (void *cls,
133 int *done = cls; 133 int *done = cls;
134 struct MHD_Response *response; 134 struct MHD_Response *response;
135 int ret; 135 int ret;
136 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 136 (void) version; (void) unused; /* Unused. Silent compiler warning. */
137 137
138 if (0 != strcmp ("PUT", method)) 138 if (0 != strcmp ("PUT", method))
139 return MHD_NO; /* unexpected method */ 139 return MHD_NO; /* unexpected method */
140 if ((*done) == 0) 140 if ((*done) == 0)
141 {
142 if (*upload_data_size != 8)
143 return MHD_YES; /* not yet ready */
144 if (0 == memcmp (upload_data, "Hello123", 8))
145 {
146 *upload_data_size = 0;
147 }
148 else
141 { 149 {
142 if (*upload_data_size != 8) 150 printf ("Invalid upload data `%8s'!\n", upload_data);
143 return MHD_YES; /* not yet ready */ 151 return MHD_NO;
144 if (0 == memcmp (upload_data, "Hello123", 8))
145 {
146 *upload_data_size = 0;
147 }
148 else
149 {
150 printf ("Invalid upload data `%8s'!\n", upload_data);
151 return MHD_NO;
152 }
153 *done = 1;
154 return MHD_YES;
155 } 152 }
153 *done = 1;
154 return MHD_YES;
155 }
156 response = MHD_create_response_from_buffer (strlen (url), 156 response = MHD_create_response_from_buffer (strlen (url),
157 (void *) url, 157 (void *) url,
158 MHD_RESPMEM_MUST_COPY); 158 MHD_RESPMEM_MUST_COPY);
159 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 159 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
160 MHD_destroy_response (response); 160 MHD_destroy_response (response);
161 return ret; 161 return ret;
@@ -177,11 +177,11 @@ testWithoutTimeout ()
177 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 177 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
178 port = 0; 178 port = 0;
179 else 179 else
180 { 180 {
181 port = 1500; 181 port = 1500;
182 if (oneone) 182 if (oneone)
183 port += 5; 183 port += 5;
184 } 184 }
185 185
186 cbc.buf = buf; 186 cbc.buf = buf;
187 cbc.size = 2048; 187 cbc.size = 2048;
@@ -190,21 +190,24 @@ testWithoutTimeout ()
190 port, 190 port,
191 NULL, NULL, &ahc_echo, &done_flag, 191 NULL, NULL, &ahc_echo, &done_flag,
192 MHD_OPTION_CONNECTION_TIMEOUT, 2, 192 MHD_OPTION_CONNECTION_TIMEOUT, 2,
193 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, &withTimeout, 193 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb,
194 &withTimeout,
194 MHD_OPTION_END); 195 MHD_OPTION_END);
195 if (d == NULL) 196 if (d == NULL)
196 return 1; 197 return 1;
197 if (0 == port) 198 if (0 == port)
199 {
200 const union MHD_DaemonInfo *dinfo;
201 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
202 if ((NULL == dinfo) ||(0 == dinfo->port) )
198 { 203 {
199 const union MHD_DaemonInfo *dinfo; 204 MHD_stop_daemon (d); return 32;
200 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
201 if (NULL == dinfo || 0 == dinfo->port)
202 { MHD_stop_daemon (d); return 32; }
203 port = (int)dinfo->port;
204 } 205 }
206 port = (int) dinfo->port;
207 }
205 c = curl_easy_init (); 208 c = curl_easy_init ();
206 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 209 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
207 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 210 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
208 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 211 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
209 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 212 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
210 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 213 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
@@ -223,11 +226,11 @@ testWithoutTimeout ()
223 * crashes on my system! */ 226 * crashes on my system! */
224 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 227 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
225 if (CURLE_OK != (errornum = curl_easy_perform (c))) 228 if (CURLE_OK != (errornum = curl_easy_perform (c)))
226 { 229 {
227 curl_easy_cleanup (c); 230 curl_easy_cleanup (c);
228 MHD_stop_daemon (d); 231 MHD_stop_daemon (d);
229 return 2; 232 return 2;
230 } 233 }
231 curl_easy_cleanup (c); 234 curl_easy_cleanup (c);
232 MHD_stop_daemon (d); 235 MHD_stop_daemon (d);
233 if (cbc.pos != strlen ("/hello_world")) 236 if (cbc.pos != strlen ("/hello_world"))
@@ -251,11 +254,11 @@ testWithTimeout ()
251 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 254 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
252 port = 0; 255 port = 0;
253 else 256 else
254 { 257 {
255 port = 1501; 258 port = 1501;
256 if (oneone) 259 if (oneone)
257 port += 5; 260 port += 5;
258 } 261 }
259 262
260 cbc.buf = buf; 263 cbc.buf = buf;
261 cbc.size = 2048; 264 cbc.size = 2048;
@@ -264,21 +267,24 @@ testWithTimeout ()
264 port, 267 port,
265 NULL, NULL, &ahc_echo, &done_flag, 268 NULL, NULL, &ahc_echo, &done_flag,
266 MHD_OPTION_CONNECTION_TIMEOUT, 2, 269 MHD_OPTION_CONNECTION_TIMEOUT, 2,
267 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, &withoutTimeout, 270 MHD_OPTION_NOTIFY_COMPLETED, &termination_cb,
271 &withoutTimeout,
268 MHD_OPTION_END); 272 MHD_OPTION_END);
269 if (d == NULL) 273 if (d == NULL)
270 return 16; 274 return 16;
271 if (0 == port) 275 if (0 == port)
276 {
277 const union MHD_DaemonInfo *dinfo;
278 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
279 if ((NULL == dinfo) ||(0 == dinfo->port) )
272 { 280 {
273 const union MHD_DaemonInfo *dinfo; 281 MHD_stop_daemon (d); return 32;
274 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
275 if (NULL == dinfo || 0 == dinfo->port)
276 { MHD_stop_daemon (d); return 32; }
277 port = (int)dinfo->port;
278 } 282 }
283 port = (int) dinfo->port;
284 }
279 c = curl_easy_init (); 285 c = curl_easy_init ();
280 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 286 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
281 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 287 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
282 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 288 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
283 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 289 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
284 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer_fail); 290 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer_fail);
@@ -297,16 +303,16 @@ testWithTimeout ()
297 * crashes on my system! */ 303 * crashes on my system! */
298 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 304 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
299 if (CURLE_OK != (errornum = curl_easy_perform (c))) 305 if (CURLE_OK != (errornum = curl_easy_perform (c)))
300 { 306 {
301 curl_easy_cleanup (c); 307 curl_easy_cleanup (c);
302 MHD_stop_daemon (d); 308 MHD_stop_daemon (d);
303 if (errornum == CURLE_GOT_NOTHING) 309 if (errornum == CURLE_GOT_NOTHING)
304 /* mhd had the timeout */ 310 /* mhd had the timeout */
305 return 0; 311 return 0;
306 else 312 else
307 /* curl had the timeout first */ 313 /* curl had the timeout first */
308 return 32; 314 return 32;
309 } 315 }
310 curl_easy_cleanup (c); 316 curl_easy_cleanup (c);
311 MHD_stop_daemon (d); 317 MHD_stop_daemon (d);
312 return 64; 318 return 64;
@@ -317,9 +323,9 @@ int
317main (int argc, char *const *argv) 323main (int argc, char *const *argv)
318{ 324{
319 unsigned int errorCount = 0; 325 unsigned int errorCount = 0;
320 (void)argc; /* Unused. Silent compiler warning. */ 326 (void) argc; /* Unused. Silent compiler warning. */
321 327
322 if (NULL == argv || 0 == argv[0]) 328 if ((NULL == argv)||(0 == argv[0]))
323 return 99; 329 return 99;
324 oneone = has_in_name (argv[0], "11"); 330 oneone = has_in_name (argv[0], "11");
325 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 331 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
@@ -327,9 +333,9 @@ main (int argc, char *const *argv)
327 errorCount += testWithoutTimeout (); 333 errorCount += testWithoutTimeout ();
328 errorCount += testWithTimeout (); 334 errorCount += testWithTimeout ();
329 if (errorCount != 0) 335 if (errorCount != 0)
330 fprintf (stderr, 336 fprintf (stderr,
331 "Error during test execution (code: %u)\n", 337 "Error during test execution (code: %u)\n",
332 errorCount); 338 errorCount);
333 curl_global_cleanup (); 339 curl_global_cleanup ();
334 if ((withTimeout == 0) && (withoutTimeout == 0)) 340 if ((withTimeout == 0) && (withoutTimeout == 0))
335 return 0; 341 return 0;