diff options
Diffstat (limited to 'src/testcurl/test_large_put.c')
-rw-r--r-- | src/testcurl/test_large_put.c | 522 |
1 files changed, 274 insertions, 248 deletions
diff --git a/src/testcurl/test_large_put.c b/src/testcurl/test_large_put.c index 4495cfd6..0b7256ae 100644 --- a/src/testcurl/test_large_put.c +++ b/src/testcurl/test_large_put.c | |||
@@ -38,10 +38,10 @@ | |||
38 | 38 | ||
39 | #include "test_helpers.h" | 39 | #include "test_helpers.h" |
40 | 40 | ||
41 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 41 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
42 | #undef CPU_COUNT | 42 | #undef CPU_COUNT |
43 | #endif | 43 | #endif |
44 | #if !defined(CPU_COUNT) | 44 | #if ! defined(CPU_COUNT) |
45 | #define CPU_COUNT 2 | 45 | #define CPU_COUNT 2 |
46 | #endif | 46 | #endif |
47 | 47 | ||
@@ -61,34 +61,35 @@ struct CBC | |||
61 | }; | 61 | }; |
62 | 62 | ||
63 | char* | 63 | char* |
64 | alloc_init(size_t buf_size) | 64 | alloc_init (size_t buf_size) |
65 | { | 65 | { |
66 | static const char template[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz"; | 66 | static const char template[] = |
67 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz"; | ||
67 | static const size_t templ_size = sizeof(template) / sizeof(char) - 1; | 68 | static const size_t templ_size = sizeof(template) / sizeof(char) - 1; |
68 | char *buf; | 69 | char *buf; |
69 | char *fill_ptr; | 70 | char *fill_ptr; |
70 | size_t to_fill; | 71 | size_t to_fill; |
71 | 72 | ||
72 | buf = malloc(buf_size); | 73 | buf = malloc (buf_size); |
73 | if (NULL == buf) | 74 | if (NULL == buf) |
74 | return NULL; | 75 | return NULL; |
75 | 76 | ||
76 | fill_ptr = buf; | 77 | fill_ptr = buf; |
77 | to_fill = buf_size; | 78 | to_fill = buf_size; |
78 | while (to_fill > 0) | 79 | while (to_fill > 0) |
79 | { | 80 | { |
80 | const size_t to_copy = to_fill > templ_size ? templ_size : to_fill; | 81 | const size_t to_copy = to_fill > templ_size ? templ_size : to_fill; |
81 | memcpy (fill_ptr, template, to_copy); | 82 | memcpy (fill_ptr, template, to_copy); |
82 | fill_ptr += to_copy; | 83 | fill_ptr += to_copy; |
83 | to_fill -= to_copy; | 84 | to_fill -= to_copy; |
84 | } | 85 | } |
85 | return buf; | 86 | return buf; |
86 | } | 87 | } |
87 | 88 | ||
88 | static size_t | 89 | static size_t |
89 | putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) | 90 | putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) |
90 | { | 91 | { |
91 | size_t *pos = (size_t *)ptr; | 92 | size_t *pos = (size_t *) ptr; |
92 | size_t wrt; | 93 | size_t wrt; |
93 | 94 | ||
94 | wrt = size * nmemb; | 95 | wrt = size * nmemb; |
@@ -127,46 +128,46 @@ ahc_echo (void *cls, | |||
127 | struct MHD_Response *response; | 128 | struct MHD_Response *response; |
128 | int ret; | 129 | int ret; |
129 | static size_t processed; | 130 | static size_t processed; |
130 | (void)version; /* Unused. Silent compiler warning. */ | 131 | (void) version; /* Unused. Silent compiler warning. */ |
131 | 132 | ||
132 | if (0 != strcmp ("PUT", method)) | 133 | if (0 != strcmp ("PUT", method)) |
133 | return MHD_NO; /* unexpected method */ | 134 | return MHD_NO; /* unexpected method */ |
134 | if ((*done) == 0) | 135 | if ((*done) == 0) |
136 | { | ||
137 | size_t *pproc; | ||
138 | if (NULL == *pparam) | ||
139 | { | ||
140 | processed = 0; | ||
141 | *pparam = &processed; /* Safe as long as only one parallel request served. */ | ||
142 | } | ||
143 | pproc = (size_t*) *pparam; | ||
144 | |||
145 | if (0 == *upload_data_size) | ||
146 | return MHD_YES; /* No data to process. */ | ||
147 | |||
148 | if (*pproc + *upload_data_size > PUT_SIZE) | ||
149 | { | ||
150 | fprintf (stderr, "Incoming data larger than expected.\n"); | ||
151 | return MHD_NO; | ||
152 | } | ||
153 | if ( (! incr_read) && (*upload_data_size != PUT_SIZE) ) | ||
154 | return MHD_YES; /* Wait until whole request is received. */ | ||
155 | |||
156 | if (0 != memcmp (upload_data, put_buffer + (*pproc), *upload_data_size)) | ||
135 | { | 157 | { |
136 | size_t *pproc; | 158 | fprintf (stderr, "Incoming data does not match sent data.\n"); |
137 | if (NULL == *pparam) | 159 | return MHD_NO; |
138 | { | ||
139 | processed = 0; | ||
140 | *pparam = &processed; /* Safe as long as only one parallel request served. */ | ||
141 | } | ||
142 | pproc = (size_t*) *pparam; | ||
143 | |||
144 | if (0 == *upload_data_size) | ||
145 | return MHD_YES; /* No data to process. */ | ||
146 | |||
147 | if (*pproc + *upload_data_size > PUT_SIZE) | ||
148 | { | ||
149 | fprintf (stderr, "Incoming data larger than expected.\n"); | ||
150 | return MHD_NO; | ||
151 | } | ||
152 | if ( (!incr_read) && (*upload_data_size != PUT_SIZE) ) | ||
153 | return MHD_YES; /* Wait until whole request is received. */ | ||
154 | |||
155 | if (0 != memcmp(upload_data, put_buffer + (*pproc), *upload_data_size)) | ||
156 | { | ||
157 | fprintf (stderr, "Incoming data does not match sent data.\n"); | ||
158 | return MHD_NO; | ||
159 | } | ||
160 | *pproc += *upload_data_size; | ||
161 | *upload_data_size = 0; /* Current block of data is fully processed. */ | ||
162 | |||
163 | if (PUT_SIZE == *pproc) | ||
164 | *done = 1; /* Whole request is processed. */ | ||
165 | return MHD_YES; | ||
166 | } | 160 | } |
161 | *pproc += *upload_data_size; | ||
162 | *upload_data_size = 0; /* Current block of data is fully processed. */ | ||
163 | |||
164 | if (PUT_SIZE == *pproc) | ||
165 | *done = 1; /* Whole request is processed. */ | ||
166 | return MHD_YES; | ||
167 | } | ||
167 | response = MHD_create_response_from_buffer (strlen (url), | 168 | response = MHD_create_response_from_buffer (strlen (url), |
168 | (void *) url, | 169 | (void *) url, |
169 | MHD_RESPMEM_MUST_COPY); | 170 | MHD_RESPMEM_MUST_COPY); |
170 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 171 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
171 | MHD_destroy_response (response); | 172 | MHD_destroy_response (response); |
172 | return ret; | 173 | return ret; |
@@ -188,35 +189,39 @@ testPutInternalThread (unsigned int add_flag) | |||
188 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 189 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
189 | port = 0; | 190 | port = 0; |
190 | else | 191 | else |
191 | { | 192 | { |
192 | port = 1270; | 193 | port = 1270; |
193 | if (oneone) | 194 | if (oneone) |
194 | port += 10; | 195 | port += 10; |
195 | if (incr_read) | 196 | if (incr_read) |
196 | port += 20; | 197 | port += 20; |
197 | } | 198 | } |
198 | 199 | ||
199 | cbc.buf = buf; | 200 | cbc.buf = buf; |
200 | cbc.size = 2048; | 201 | cbc.size = 2048; |
201 | cbc.pos = 0; | 202 | cbc.pos = 0; |
202 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | add_flag, | 203 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
204 | | add_flag, | ||
203 | port, | 205 | port, |
204 | NULL, NULL, &ahc_echo, &done_flag, | 206 | NULL, NULL, &ahc_echo, &done_flag, |
205 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4 / 3)), | 207 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
206 | MHD_OPTION_END); | 208 | (size_t) (incr_read ? 1024 : (PUT_SIZE * 4 / 3)), |
209 | MHD_OPTION_END); | ||
207 | if (d == NULL) | 210 | if (d == NULL) |
208 | return 1; | 211 | return 1; |
209 | if (0 == port) | 212 | if (0 == port) |
213 | { | ||
214 | const union MHD_DaemonInfo *dinfo; | ||
215 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
216 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
210 | { | 217 | { |
211 | const union MHD_DaemonInfo *dinfo; | 218 | MHD_stop_daemon (d); return 32; |
212 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
213 | if (NULL == dinfo || 0 == dinfo->port) | ||
214 | { MHD_stop_daemon (d); return 32; } | ||
215 | port = (int)dinfo->port; | ||
216 | } | 219 | } |
220 | port = (int) dinfo->port; | ||
221 | } | ||
217 | c = curl_easy_init (); | 222 | c = curl_easy_init (); |
218 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 223 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
219 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 224 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
220 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 225 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
221 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 226 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
222 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 227 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -235,14 +240,14 @@ testPutInternalThread (unsigned int add_flag) | |||
235 | * crashes on my system! */ | 240 | * crashes on my system! */ |
236 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 241 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
237 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 242 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
238 | { | 243 | { |
239 | fprintf (stderr, | 244 | fprintf (stderr, |
240 | "curl_easy_perform failed: `%s'\n", | 245 | "curl_easy_perform failed: `%s'\n", |
241 | curl_easy_strerror (errornum)); | 246 | curl_easy_strerror (errornum)); |
242 | curl_easy_cleanup (c); | 247 | curl_easy_cleanup (c); |
243 | MHD_stop_daemon (d); | 248 | MHD_stop_daemon (d); |
244 | return 2; | 249 | return 2; |
245 | } | 250 | } |
246 | curl_easy_cleanup (c); | 251 | curl_easy_cleanup (c); |
247 | MHD_stop_daemon (d); | 252 | MHD_stop_daemon (d); |
248 | if (cbc.pos != strlen ("/hello_world")) | 253 | if (cbc.pos != strlen ("/hello_world")) |
@@ -267,36 +272,40 @@ testPutThreadPerConn (unsigned int add_flag) | |||
267 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 272 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
268 | port = 0; | 273 | port = 0; |
269 | else | 274 | else |
270 | { | 275 | { |
271 | port = 1271; | 276 | port = 1271; |
272 | if (oneone) | 277 | if (oneone) |
273 | port += 10; | 278 | port += 10; |
274 | if (incr_read) | 279 | if (incr_read) |
275 | port += 20; | 280 | port += 20; |
276 | } | 281 | } |
277 | 282 | ||
278 | cbc.buf = buf; | 283 | cbc.buf = buf; |
279 | cbc.size = 2048; | 284 | cbc.size = 2048; |
280 | cbc.pos = 0; | 285 | cbc.pos = 0; |
281 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | | 286 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
282 | MHD_USE_ERROR_LOG | add_flag, | 287 | | MHD_USE_INTERNAL_POLLING_THREAD |
288 | | MHD_USE_ERROR_LOG | add_flag, | ||
283 | port, | 289 | port, |
284 | NULL, NULL, &ahc_echo, &done_flag, | 290 | NULL, NULL, &ahc_echo, &done_flag, |
285 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4)), | 291 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
286 | MHD_OPTION_END); | 292 | (size_t) (incr_read ? 1024 : (PUT_SIZE * 4)), |
293 | MHD_OPTION_END); | ||
287 | if (d == NULL) | 294 | if (d == NULL) |
288 | return 16; | 295 | return 16; |
289 | if (0 == port) | 296 | if (0 == port) |
297 | { | ||
298 | const union MHD_DaemonInfo *dinfo; | ||
299 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
300 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
290 | { | 301 | { |
291 | const union MHD_DaemonInfo *dinfo; | 302 | MHD_stop_daemon (d); return 32; |
292 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
293 | if (NULL == dinfo || 0 == dinfo->port) | ||
294 | { MHD_stop_daemon (d); return 32; } | ||
295 | port = (int)dinfo->port; | ||
296 | } | 303 | } |
304 | port = (int) dinfo->port; | ||
305 | } | ||
297 | c = curl_easy_init (); | 306 | c = curl_easy_init (); |
298 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 307 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
299 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 308 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
300 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 309 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
301 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 310 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
302 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 311 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -315,21 +324,21 @@ testPutThreadPerConn (unsigned int add_flag) | |||
315 | * crashes on my system! */ | 324 | * crashes on my system! */ |
316 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 325 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
317 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 326 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
318 | { | 327 | { |
319 | fprintf (stderr, | 328 | fprintf (stderr, |
320 | "curl_easy_perform failed: `%s'\n", | 329 | "curl_easy_perform failed: `%s'\n", |
321 | curl_easy_strerror (errornum)); | 330 | curl_easy_strerror (errornum)); |
322 | curl_easy_cleanup (c); | 331 | curl_easy_cleanup (c); |
323 | MHD_stop_daemon (d); | 332 | MHD_stop_daemon (d); |
324 | return 32; | 333 | return 32; |
325 | } | 334 | } |
326 | curl_easy_cleanup (c); | 335 | curl_easy_cleanup (c); |
327 | MHD_stop_daemon (d); | 336 | MHD_stop_daemon (d); |
328 | if (cbc.pos != strlen ("/hello_world")) | 337 | if (cbc.pos != strlen ("/hello_world")) |
329 | { | 338 | { |
330 | fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf); | 339 | fprintf (stderr, "Got invalid response `%.*s'\n", (int) cbc.pos, cbc.buf); |
331 | return 64; | 340 | return 64; |
332 | } | 341 | } |
333 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 342 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
334 | return 128; | 343 | return 128; |
335 | return 0; | 344 | return 0; |
@@ -350,36 +359,40 @@ testPutThreadPool (unsigned int add_flag) | |||
350 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 359 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
351 | port = 0; | 360 | port = 0; |
352 | else | 361 | else |
353 | { | 362 | { |
354 | port = 1272; | 363 | port = 1272; |
355 | if (oneone) | 364 | if (oneone) |
356 | port += 10; | 365 | port += 10; |
357 | if (incr_read) | 366 | if (incr_read) |
358 | port += 20; | 367 | port += 20; |
359 | } | 368 | } |
360 | 369 | ||
361 | cbc.buf = buf; | 370 | cbc.buf = buf; |
362 | cbc.size = 2048; | 371 | cbc.size = 2048; |
363 | cbc.pos = 0; | 372 | cbc.pos = 0; |
364 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | add_flag, | 373 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
374 | | add_flag, | ||
365 | port, | 375 | port, |
366 | NULL, NULL, &ahc_echo, &done_flag, | 376 | NULL, NULL, &ahc_echo, &done_flag, |
367 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, | 377 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, |
368 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4)), | 378 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
369 | MHD_OPTION_END); | 379 | (size_t) (incr_read ? 1024 : (PUT_SIZE * 4)), |
380 | MHD_OPTION_END); | ||
370 | if (d == NULL) | 381 | if (d == NULL) |
371 | return 16; | 382 | return 16; |
372 | if (0 == port) | 383 | if (0 == port) |
384 | { | ||
385 | const union MHD_DaemonInfo *dinfo; | ||
386 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
387 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
373 | { | 388 | { |
374 | const union MHD_DaemonInfo *dinfo; | 389 | MHD_stop_daemon (d); return 32; |
375 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
376 | if (NULL == dinfo || 0 == dinfo->port) | ||
377 | { MHD_stop_daemon (d); return 32; } | ||
378 | port = (int)dinfo->port; | ||
379 | } | 390 | } |
391 | port = (int) dinfo->port; | ||
392 | } | ||
380 | c = curl_easy_init (); | 393 | c = curl_easy_init (); |
381 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 394 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
382 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 395 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
383 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 396 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
384 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 397 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
385 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 398 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -398,21 +411,21 @@ testPutThreadPool (unsigned int add_flag) | |||
398 | * crashes on my system! */ | 411 | * crashes on my system! */ |
399 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 412 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
400 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 413 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
401 | { | 414 | { |
402 | fprintf (stderr, | 415 | fprintf (stderr, |
403 | "curl_easy_perform failed: `%s'\n", | 416 | "curl_easy_perform failed: `%s'\n", |
404 | curl_easy_strerror (errornum)); | 417 | curl_easy_strerror (errornum)); |
405 | curl_easy_cleanup (c); | 418 | curl_easy_cleanup (c); |
406 | MHD_stop_daemon (d); | 419 | MHD_stop_daemon (d); |
407 | return 32; | 420 | return 32; |
408 | } | 421 | } |
409 | curl_easy_cleanup (c); | 422 | curl_easy_cleanup (c); |
410 | MHD_stop_daemon (d); | 423 | MHD_stop_daemon (d); |
411 | if (cbc.pos != strlen ("/hello_world")) | 424 | if (cbc.pos != strlen ("/hello_world")) |
412 | { | 425 | { |
413 | fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf); | 426 | fprintf (stderr, "Got invalid response `%.*s'\n", (int) cbc.pos, cbc.buf); |
414 | return 64; | 427 | return 64; |
415 | } | 428 | } |
416 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 429 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
417 | return 128; | 430 | return 128; |
418 | return 0; | 431 | return 0; |
@@ -447,13 +460,13 @@ testPutExternal (void) | |||
447 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 460 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
448 | port = 0; | 461 | port = 0; |
449 | else | 462 | else |
450 | { | 463 | { |
451 | port = 1273; | 464 | port = 1273; |
452 | if (oneone) | 465 | if (oneone) |
453 | port += 10; | 466 | port += 10; |
454 | if (incr_read) | 467 | if (incr_read) |
455 | port += 20; | 468 | port += 20; |
456 | } | 469 | } |
457 | 470 | ||
458 | cbc.buf = buf; | 471 | cbc.buf = buf; |
459 | cbc.size = 2048; | 472 | cbc.size = 2048; |
@@ -462,21 +475,24 @@ testPutExternal (void) | |||
462 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, | 475 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, |
463 | port, | 476 | port, |
464 | NULL, NULL, &ahc_echo, &done_flag, | 477 | NULL, NULL, &ahc_echo, &done_flag, |
465 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4)), | 478 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
479 | (size_t) (incr_read ? 1024 : (PUT_SIZE * 4)), | ||
466 | MHD_OPTION_END); | 480 | MHD_OPTION_END); |
467 | if (d == NULL) | 481 | if (d == NULL) |
468 | return 256; | 482 | return 256; |
469 | if (0 == port) | 483 | if (0 == port) |
484 | { | ||
485 | const union MHD_DaemonInfo *dinfo; | ||
486 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
487 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
470 | { | 488 | { |
471 | const union MHD_DaemonInfo *dinfo; | 489 | MHD_stop_daemon (d); return 32; |
472 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
473 | if (NULL == dinfo || 0 == dinfo->port) | ||
474 | { MHD_stop_daemon (d); return 32; } | ||
475 | port = (int)dinfo->port; | ||
476 | } | 490 | } |
491 | port = (int) dinfo->port; | ||
492 | } | ||
477 | c = curl_easy_init (); | 493 | c = curl_easy_init (); |
478 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 494 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
479 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 495 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
480 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 496 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
481 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 497 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
482 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 498 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -498,92 +514,94 @@ testPutExternal (void) | |||
498 | 514 | ||
499 | multi = curl_multi_init (); | 515 | multi = curl_multi_init (); |
500 | if (multi == NULL) | 516 | if (multi == NULL) |
517 | { | ||
518 | curl_easy_cleanup (c); | ||
519 | MHD_stop_daemon (d); | ||
520 | return 512; | ||
521 | } | ||
522 | mret = curl_multi_add_handle (multi, c); | ||
523 | if (mret != CURLM_OK) | ||
524 | { | ||
525 | curl_multi_cleanup (multi); | ||
526 | curl_easy_cleanup (c); | ||
527 | MHD_stop_daemon (d); | ||
528 | return 1024; | ||
529 | } | ||
530 | start = time (NULL); | ||
531 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
532 | { | ||
533 | maxsock = MHD_INVALID_SOCKET; | ||
534 | maxposixs = -1; | ||
535 | FD_ZERO (&rs); | ||
536 | FD_ZERO (&ws); | ||
537 | FD_ZERO (&es); | ||
538 | curl_multi_perform (multi, &running); | ||
539 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
540 | if (mret != CURLM_OK) | ||
501 | { | 541 | { |
542 | curl_multi_remove_handle (multi, c); | ||
543 | curl_multi_cleanup (multi); | ||
502 | curl_easy_cleanup (c); | 544 | curl_easy_cleanup (c); |
503 | MHD_stop_daemon (d); | 545 | MHD_stop_daemon (d); |
504 | return 512; | 546 | return 2048; |
505 | } | 547 | } |
506 | mret = curl_multi_add_handle (multi, c); | 548 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
507 | if (mret != CURLM_OK) | ||
508 | { | 549 | { |
550 | curl_multi_remove_handle (multi, c); | ||
509 | curl_multi_cleanup (multi); | 551 | curl_multi_cleanup (multi); |
510 | curl_easy_cleanup (c); | 552 | curl_easy_cleanup (c); |
511 | MHD_stop_daemon (d); | 553 | MHD_stop_daemon (d); |
512 | return 1024; | 554 | return 4096; |
513 | } | 555 | } |
514 | start = time (NULL); | 556 | tv.tv_sec = 0; |
515 | while ((time (NULL) - start < 5) && (multi != NULL)) | 557 | tv.tv_usec = 1000; |
558 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
516 | { | 559 | { |
517 | maxsock = MHD_INVALID_SOCKET; | ||
518 | maxposixs = -1; | ||
519 | FD_ZERO (&rs); | ||
520 | FD_ZERO (&ws); | ||
521 | FD_ZERO (&es); | ||
522 | curl_multi_perform (multi, &running); | ||
523 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
524 | if (mret != CURLM_OK) | ||
525 | { | ||
526 | curl_multi_remove_handle (multi, c); | ||
527 | curl_multi_cleanup (multi); | ||
528 | curl_easy_cleanup (c); | ||
529 | MHD_stop_daemon (d); | ||
530 | return 2048; | ||
531 | } | ||
532 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
533 | { | ||
534 | curl_multi_remove_handle (multi, c); | ||
535 | curl_multi_cleanup (multi); | ||
536 | curl_easy_cleanup (c); | ||
537 | MHD_stop_daemon (d); | ||
538 | return 4096; | ||
539 | } | ||
540 | tv.tv_sec = 0; | ||
541 | tv.tv_usec = 1000; | ||
542 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
543 | { | ||
544 | #ifdef MHD_POSIX_SOCKETS | 560 | #ifdef MHD_POSIX_SOCKETS |
545 | if (EINTR != errno) | 561 | if (EINTR != errno) |
546 | abort (); | 562 | abort (); |
547 | #else | 563 | #else |
548 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 564 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
549 | abort (); | 565 | ws.fd_count) |
550 | Sleep (1000); | 566 | ||(0 != es.fd_count) ) |
567 | abort (); | ||
568 | Sleep (1000); | ||
551 | #endif | 569 | #endif |
552 | } | ||
553 | curl_multi_perform (multi, &running); | ||
554 | if (running == 0) | ||
555 | { | ||
556 | msg = curl_multi_info_read (multi, &running); | ||
557 | if (msg == NULL) | ||
558 | break; | ||
559 | if (msg->msg == CURLMSG_DONE) | ||
560 | { | ||
561 | if (msg->data.result != CURLE_OK) | ||
562 | printf ("%s failed at %s:%d: `%s'\n", | ||
563 | "curl_multi_perform", | ||
564 | __FILE__, | ||
565 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
566 | curl_multi_remove_handle (multi, c); | ||
567 | curl_multi_cleanup (multi); | ||
568 | curl_easy_cleanup (c); | ||
569 | c = NULL; | ||
570 | multi = NULL; | ||
571 | } | ||
572 | } | ||
573 | MHD_run (d); | ||
574 | } | 570 | } |
575 | if (multi != NULL) | 571 | curl_multi_perform (multi, &running); |
572 | if (running == 0) | ||
576 | { | 573 | { |
577 | curl_multi_remove_handle (multi, c); | 574 | msg = curl_multi_info_read (multi, &running); |
578 | curl_easy_cleanup (c); | 575 | if (msg == NULL) |
579 | curl_multi_cleanup (multi); | 576 | break; |
577 | if (msg->msg == CURLMSG_DONE) | ||
578 | { | ||
579 | if (msg->data.result != CURLE_OK) | ||
580 | printf ("%s failed at %s:%d: `%s'\n", | ||
581 | "curl_multi_perform", | ||
582 | __FILE__, | ||
583 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
584 | curl_multi_remove_handle (multi, c); | ||
585 | curl_multi_cleanup (multi); | ||
586 | curl_easy_cleanup (c); | ||
587 | c = NULL; | ||
588 | multi = NULL; | ||
589 | } | ||
580 | } | 590 | } |
591 | MHD_run (d); | ||
592 | } | ||
593 | if (multi != NULL) | ||
594 | { | ||
595 | curl_multi_remove_handle (multi, c); | ||
596 | curl_easy_cleanup (c); | ||
597 | curl_multi_cleanup (multi); | ||
598 | } | ||
581 | MHD_stop_daemon (d); | 599 | MHD_stop_daemon (d); |
582 | if (cbc.pos != strlen ("/hello_world")) | 600 | if (cbc.pos != strlen ("/hello_world")) |
583 | { | 601 | { |
584 | fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf); | 602 | fprintf (stderr, "Got invalid response `%.*s'\n", (int) cbc.pos, cbc.buf); |
585 | return 8192; | 603 | return 8192; |
586 | } | 604 | } |
587 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 605 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
588 | return 16384; | 606 | return 16384; |
589 | return 0; | 607 | return 0; |
@@ -597,59 +615,67 @@ main (int argc, char *const *argv) | |||
597 | unsigned int errorCount = 0; | 615 | unsigned int errorCount = 0; |
598 | unsigned int lastErr; | 616 | unsigned int lastErr; |
599 | 617 | ||
600 | oneone = has_in_name(argv[0], "11"); | 618 | oneone = has_in_name (argv[0], "11"); |
601 | incr_read = has_in_name(argv[0], "_inc"); | 619 | incr_read = has_in_name (argv[0], "_inc"); |
602 | verbose = has_param(argc, argv, "-v"); | 620 | verbose = has_param (argc, argv, "-v"); |
603 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 621 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
604 | return 99; | 622 | return 99; |
605 | put_buffer = alloc_init (PUT_SIZE); | 623 | put_buffer = alloc_init (PUT_SIZE); |
606 | if (NULL == put_buffer) | 624 | if (NULL == put_buffer) |
607 | return 99; | 625 | return 99; |
608 | lastErr = testPutExternal (); | 626 | lastErr = testPutExternal (); |
609 | if (verbose && 0 != lastErr) | 627 | if (verbose &&(0 != lastErr)) |
610 | fprintf (stderr, "Error during testing with external select().\n"); | 628 | fprintf (stderr, "Error during testing with external select().\n"); |
611 | errorCount += lastErr; | 629 | errorCount += lastErr; |
612 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 630 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
631 | { | ||
632 | lastErr = testPutInternalThread (0); | ||
633 | if (verbose &&(0 != lastErr) ) | ||
634 | fprintf (stderr, | ||
635 | "Error during testing with internal thread with select().\n"); | ||
636 | errorCount += lastErr; | ||
637 | lastErr = testPutThreadPerConn (0); | ||
638 | if (verbose &&(0 != lastErr) ) | ||
639 | fprintf (stderr, | ||
640 | "Error during testing with internal thread per connection with select().\n"); | ||
641 | errorCount += lastErr; | ||
642 | lastErr = testPutThreadPool (0); | ||
643 | if (verbose &&(0 != lastErr) ) | ||
644 | fprintf (stderr, | ||
645 | "Error during testing with thread pool per connection with select().\n"); | ||
646 | errorCount += lastErr; | ||
647 | if (MHD_is_feature_supported (MHD_FEATURE_POLL)) | ||
613 | { | 648 | { |
614 | lastErr = testPutInternalThread (0); | 649 | lastErr = testPutInternalThread (MHD_USE_POLL); |
615 | if (verbose && 0 != lastErr) | 650 | if (verbose &&(0 != lastErr) ) |
616 | fprintf (stderr, "Error during testing with internal thread with select().\n"); | 651 | fprintf (stderr, |
652 | "Error during testing with internal thread with poll().\n"); | ||
617 | errorCount += lastErr; | 653 | errorCount += lastErr; |
618 | lastErr = testPutThreadPerConn (0); | 654 | lastErr = testPutThreadPerConn (MHD_USE_POLL); |
619 | if (verbose && 0 != lastErr) | 655 | if (verbose &&(0 != lastErr) ) |
620 | fprintf (stderr, "Error during testing with internal thread per connection with select().\n"); | 656 | fprintf (stderr, |
657 | "Error during testing with internal thread per connection with poll().\n"); | ||
658 | errorCount += lastErr; | ||
659 | lastErr = testPutThreadPool (MHD_USE_POLL); | ||
660 | if (verbose &&(0 != lastErr) ) | ||
661 | fprintf (stderr, | ||
662 | "Error during testing with thread pool per connection with poll().\n"); | ||
663 | errorCount += lastErr; | ||
664 | } | ||
665 | if (MHD_is_feature_supported (MHD_FEATURE_EPOLL)) | ||
666 | { | ||
667 | lastErr = testPutInternalThread (MHD_USE_EPOLL); | ||
668 | if (verbose &&(0 != lastErr) ) | ||
669 | fprintf (stderr, | ||
670 | "Error during testing with internal thread with epoll.\n"); | ||
621 | errorCount += lastErr; | 671 | errorCount += lastErr; |
622 | lastErr = testPutThreadPool (0); | 672 | lastErr = testPutThreadPool (MHD_USE_EPOLL); |
623 | if (verbose && 0 != lastErr) | 673 | if (verbose &&(0 != lastErr) ) |
624 | fprintf (stderr, "Error during testing with thread pool per connection with select().\n"); | 674 | fprintf (stderr, |
675 | "Error during testing with thread pool per connection with epoll.\n"); | ||
625 | errorCount += lastErr; | 676 | errorCount += lastErr; |
626 | if (MHD_is_feature_supported(MHD_FEATURE_POLL)) | ||
627 | { | ||
628 | lastErr = testPutInternalThread (MHD_USE_POLL); | ||
629 | if (verbose && 0 != lastErr) | ||
630 | fprintf (stderr, "Error during testing with internal thread with poll().\n"); | ||
631 | errorCount += lastErr; | ||
632 | lastErr = testPutThreadPerConn (MHD_USE_POLL); | ||
633 | if (verbose && 0 != lastErr) | ||
634 | fprintf (stderr, "Error during testing with internal thread per connection with poll().\n"); | ||
635 | errorCount += lastErr; | ||
636 | lastErr = testPutThreadPool (MHD_USE_POLL); | ||
637 | if (verbose && 0 != lastErr) | ||
638 | fprintf (stderr, "Error during testing with thread pool per connection with poll().\n"); | ||
639 | errorCount += lastErr; | ||
640 | } | ||
641 | if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) | ||
642 | { | ||
643 | lastErr = testPutInternalThread (MHD_USE_EPOLL); | ||
644 | if (verbose && 0 != lastErr) | ||
645 | fprintf (stderr, "Error during testing with internal thread with epoll.\n"); | ||
646 | errorCount += lastErr; | ||
647 | lastErr = testPutThreadPool (MHD_USE_EPOLL); | ||
648 | if (verbose && 0 != lastErr) | ||
649 | fprintf (stderr, "Error during testing with thread pool per connection with epoll.\n"); | ||
650 | errorCount += lastErr; | ||
651 | } | ||
652 | } | 677 | } |
678 | } | ||
653 | free (put_buffer); | 679 | free (put_buffer); |
654 | if (errorCount != 0) | 680 | if (errorCount != 0) |
655 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 681 | fprintf (stderr, "Error (code: %u)\n", errorCount); |