aboutsummaryrefslogtreecommitdiff
path: root/src/testzzuf
diff options
context:
space:
mode:
Diffstat (limited to 'src/testzzuf')
-rw-r--r--src/testzzuf/socat.c50
-rw-r--r--src/testzzuf/test_get.c262
-rw-r--r--src/testzzuf/test_get_chunked.c246
-rw-r--r--src/testzzuf/test_long_header.c164
-rw-r--r--src/testzzuf/test_post.c348
-rw-r--r--src/testzzuf/test_post_form.c342
-rw-r--r--src/testzzuf/test_put.c310
-rw-r--r--src/testzzuf/test_put_chunked.c275
-rw-r--r--src/testzzuf/test_put_large.c324
9 files changed, 1168 insertions, 1153 deletions
diff --git a/src/testzzuf/socat.c b/src/testzzuf/socat.c
index 72089a6d..07cbf464 100644
--- a/src/testzzuf/socat.c
+++ b/src/testzzuf/socat.c
@@ -67,27 +67,27 @@ zzuf_socat_start ()
67 }; 67 };
68 zzuf_pid = fork (); 68 zzuf_pid = fork ();
69 if (zzuf_pid == -1) 69 if (zzuf_pid == -1)
70 { 70 {
71 fprintf (stderr, "fork failed: %s\n", strerror (errno)); 71 fprintf (stderr, "fork failed: %s\n", strerror (errno));
72 exit (1); 72 exit (1);
73 } 73 }
74 if (zzuf_pid != 0) 74 if (zzuf_pid != 0)
75 {
76 (void) sleep (1); /* allow zzuf and socat to start */
77 status = 0;
78 if (0 < waitpid (zzuf_pid, &status, WNOHANG))
75 { 79 {
76 (void)sleep (1); /* allow zzuf and socat to start */ 80 if (WIFEXITED (status))
77 status = 0; 81 fprintf (stderr,
78 if (0 < waitpid (zzuf_pid, &status, WNOHANG)) 82 "zzuf died with status code %d!\n",
79 { 83 WEXITSTATUS (status));
80 if (WIFEXITED (status)) 84 if (WIFSIGNALED (status))
81 fprintf (stderr, 85 fprintf (stderr,
82 "zzuf died with status code %d!\n", 86 "zzuf died from signal %d!\n", WTERMSIG (status));
83 WEXITSTATUS (status)); 87 exit (1);
84 if (WIFSIGNALED (status))
85 fprintf (stderr,
86 "zzuf died from signal %d!\n", WTERMSIG (status));
87 exit (1);
88 }
89 return;
90 } 88 }
89 return;
90 }
91 setpgid (0, 0); 91 setpgid (0, 0);
92 execvp ("zzuf", args); 92 execvp ("zzuf", args);
93 fprintf (stderr, "execution of `zzuf' failed: %s\n", strerror (errno)); 93 fprintf (stderr, "execution of `zzuf' failed: %s\n", strerror (errno));
@@ -100,13 +100,13 @@ zzuf_socat_stop ()
100{ 100{
101 int status; 101 int status;
102 if (zzuf_pid != 0) 102 if (zzuf_pid != 0)
103 { 103 {
104 if (0 != killpg (zzuf_pid, SIGINT)) 104 if (0 != killpg (zzuf_pid, SIGINT))
105 fprintf (stderr, "Failed to killpg: %s\n", strerror (errno)); 105 fprintf (stderr, "Failed to killpg: %s\n", strerror (errno));
106 kill (zzuf_pid, SIGINT); 106 kill (zzuf_pid, SIGINT);
107 waitpid (zzuf_pid, &status, 0); 107 waitpid (zzuf_pid, &status, 0);
108 (void)sleep (1); /* allow socat to also die in peace */ 108 (void) sleep (1); /* allow socat to also die in peace */
109 } 109 }
110} 110}
111 111
112/* end of socat.c */ 112/* end of socat.c */
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);
diff --git a/src/testzzuf/test_get_chunked.c b/src/testzzuf/test_get_chunked.c
index 2a16202b..facad587 100644
--- a/src/testzzuf/test_get_chunked.c
+++ b/src/testzzuf/test_get_chunked.c
@@ -67,10 +67,10 @@ crc (void *cls, uint64_t pos, char *buf, size_t max)
67 struct MHD_Response **responseptr = cls; 67 struct MHD_Response **responseptr = cls;
68 68
69 if (pos == 128 * 10) 69 if (pos == 128 * 10)
70 { 70 {
71 MHD_add_response_header (*responseptr, "Footer", "working"); 71 MHD_add_response_header (*responseptr, "Footer", "working");
72 return MHD_CONTENT_READER_END_OF_STREAM; 72 return MHD_CONTENT_READER_END_OF_STREAM;
73 } 73 }
74 if (max < 128) 74 if (max < 128)
75 abort (); /* should not happen in this testcase... */ 75 abort (); /* should not happen in this testcase... */
76 memset (buf, 'A' + (pos / 128), 128); 76 memset (buf, 'A' + (pos / 128), 128);
@@ -108,11 +108,11 @@ ahc_echo (void *cls,
108 if (0 != strcmp (me, method)) 108 if (0 != strcmp (me, method))
109 return MHD_NO; /* unexpected method */ 109 return MHD_NO; /* unexpected method */
110 if (&aptr != *ptr) 110 if (&aptr != *ptr)
111 { 111 {
112 /* do never respond on first call */ 112 /* do never respond on first call */
113 *ptr = &aptr; 113 *ptr = &aptr;
114 return MHD_YES; 114 return MHD_YES;
115 } 115 }
116 responseptr = malloc (sizeof (struct MHD_Response *)); 116 responseptr = malloc (sizeof (struct MHD_Response *));
117 if (NULL == responseptr) 117 if (NULL == responseptr)
118 return MHD_NO; 118 return MHD_NO;
@@ -144,29 +144,30 @@ testInternalGet ()
144 cbc.buf = buf; 144 cbc.buf = buf;
145 cbc.size = 2048; 145 cbc.size = 2048;
146 cbc.pos = 0; 146 cbc.pos = 0;
147 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 147 d = MHD_start_daemon (
148 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 148 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
149 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
149 if (d == NULL) 150 if (d == NULL)
150 return 1; 151 return 1;
151 zzuf_socat_start (); 152 zzuf_socat_start ();
152 for (i = 0; i < LOOP_COUNT; i++) 153 for (i = 0; i < LOOP_COUNT; i++)
153 { 154 {
154 fprintf (stderr, "."); 155 fprintf (stderr, ".");
155 c = curl_easy_init (); 156 c = curl_easy_init ();
156 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 157 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
157 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 158 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
158 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 159 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
159 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 160 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
160 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 161 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
161 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 162 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
162 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 163 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
163 /* NOTE: use of CONNECTTIMEOUT without also 164 /* NOTE: use of CONNECTTIMEOUT without also
164 * setting NOSIGNAL results in really weird 165 * setting NOSIGNAL results in really weird
165 * crashes on my system! */ 166 * crashes on my system! */
166 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 167 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
167 curl_easy_perform (c); 168 curl_easy_perform (c);
168 curl_easy_cleanup (c); 169 curl_easy_cleanup (c);
169 } 170 }
170 fprintf (stderr, "\n"); 171 fprintf (stderr, "\n");
171 zzuf_socat_stop (); 172 zzuf_socat_stop ();
172 MHD_stop_daemon (d); 173 MHD_stop_daemon (d);
@@ -185,29 +186,30 @@ testMultithreadedGet ()
185 cbc.buf = buf; 186 cbc.buf = buf;
186 cbc.size = 2048; 187 cbc.size = 2048;
187 cbc.pos = 0; 188 cbc.pos = 0;
188 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 189 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
190 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
189 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 191 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
190 if (d == NULL) 192 if (d == NULL)
191 return 16; 193 return 16;
192 zzuf_socat_start (); 194 zzuf_socat_start ();
193 for (i = 0; i < LOOP_COUNT; i++) 195 for (i = 0; i < LOOP_COUNT; i++)
194 { 196 {
195 fprintf (stderr, "."); 197 fprintf (stderr, ".");
196 c = curl_easy_init (); 198 c = curl_easy_init ();
197 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 199 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
198 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 200 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
199 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 201 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 202 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 203 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
202 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
203 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 205 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
204 /* NOTE: use of CONNECTTIMEOUT without also 206 /* NOTE: use of CONNECTTIMEOUT without also
205 * setting NOSIGNAL results in really weird 207 * setting NOSIGNAL results in really weird
206 * crashes on my system! */ 208 * crashes on my system! */
207 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 209 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
208 curl_easy_perform (c); 210 curl_easy_perform (c);
209 curl_easy_cleanup (c); 211 curl_easy_cleanup (c);
210 } 212 }
211 fprintf (stderr, "\n"); 213 fprintf (stderr, "\n");
212 zzuf_socat_stop (); 214 zzuf_socat_stop ();
213 MHD_stop_daemon (d); 215 MHD_stop_daemon (d);
@@ -237,87 +239,87 @@ testExternalGet ()
237 cbc.buf = buf; 239 cbc.buf = buf;
238 cbc.size = 2048; 240 cbc.size = 2048;
239 cbc.pos = 0; 241 cbc.pos = 0;
240 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 242 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
241 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 243 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
242 if (d == NULL) 244 if (d == NULL)
243 return 256; 245 return 256;
244 multi = curl_multi_init (); 246 multi = curl_multi_init ();
245 if (multi == NULL) 247 if (multi == NULL)
248 {
249 MHD_stop_daemon (d);
250 return 512;
251 }
252 zzuf_socat_start ();
253 for (i = 0; i < LOOP_COUNT; i++)
254 {
255 fprintf (stderr, ".");
256 c = curl_easy_init ();
257 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
258 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
259 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
260 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
261 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
262 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
263 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
264 /* NOTE: use of CONNECTTIMEOUT without also
265 * setting NOSIGNAL results in really weird
266 * crashes on my system! */
267 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
268 mret = curl_multi_add_handle (multi, c);
269 if (mret != CURLM_OK)
246 { 270 {
271 curl_multi_cleanup (multi);
272 curl_easy_cleanup (c);
273 zzuf_socat_stop ();
247 MHD_stop_daemon (d); 274 MHD_stop_daemon (d);
248 return 512; 275 return 1024;
249 } 276 }
250 zzuf_socat_start (); 277 start = time (NULL);
251 for (i = 0; i < LOOP_COUNT; i++) 278 while ((time (NULL) - start < 5) && (c != NULL))
252 { 279 {
253 fprintf (stderr, "."); 280 max = 0;
254 c = curl_easy_init (); 281 FD_ZERO (&rs);
255 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 282 FD_ZERO (&ws);
256 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 283 FD_ZERO (&es);
257 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 284 curl_multi_perform (multi, &running);
258 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 285 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
259 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
260 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
261 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
262 /* NOTE: use of CONNECTTIMEOUT without also
263 * setting NOSIGNAL results in really weird
264 * crashes on my system! */
265 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
266 mret = curl_multi_add_handle (multi, c);
267 if (mret != CURLM_OK) 286 if (mret != CURLM_OK)
268 { 287 {
269 curl_multi_cleanup (multi); 288 curl_multi_remove_handle (multi, c);
270 curl_easy_cleanup (c); 289 curl_multi_cleanup (multi);
271 zzuf_socat_stop (); 290 curl_easy_cleanup (c);
272 MHD_stop_daemon (d); 291 zzuf_socat_stop ();
273 return 1024; 292 MHD_stop_daemon (d);
274 } 293 return 2048;
275 start = time (NULL); 294 }
276 while ((time (NULL) - start < 5) && (c != NULL)) 295 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
277 { 296 {
278 max = 0; 297 curl_multi_remove_handle (multi, c);
279 FD_ZERO (&rs); 298 curl_multi_cleanup (multi);
280 FD_ZERO (&ws); 299 curl_easy_cleanup (c);
281 FD_ZERO (&es); 300 zzuf_socat_stop ();
282 curl_multi_perform (multi, &running); 301 MHD_stop_daemon (d);
283 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 302 return 4096;
284 if (mret != CURLM_OK) 303 }
285 { 304 tv.tv_sec = 0;
286 curl_multi_remove_handle (multi, c); 305 tv.tv_usec = 1000;
287 curl_multi_cleanup (multi); 306 select (max + 1, &rs, &ws, &es, &tv);
288 curl_easy_cleanup (c); 307 curl_multi_perform (multi, &running);
289 zzuf_socat_stop (); 308 if (running == 0)
290 MHD_stop_daemon (d); 309 {
291 return 2048; 310 curl_multi_info_read (multi, &running);
292 } 311 curl_multi_remove_handle (multi, c);
293 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 312 curl_easy_cleanup (c);
294 { 313 c = NULL;
295 curl_multi_remove_handle (multi, c); 314 }
296 curl_multi_cleanup (multi); 315 MHD_run (d);
297 curl_easy_cleanup (c);
298 zzuf_socat_stop ();
299 MHD_stop_daemon (d);
300 return 4096;
301 }
302 tv.tv_sec = 0;
303 tv.tv_usec = 1000;
304 select (max + 1, &rs, &ws, &es, &tv);
305 curl_multi_perform (multi, &running);
306 if (running == 0)
307 {
308 curl_multi_info_read (multi, &running);
309 curl_multi_remove_handle (multi, c);
310 curl_easy_cleanup (c);
311 c = NULL;
312 }
313 MHD_run (d);
314 }
315 if (c != NULL)
316 {
317 curl_multi_remove_handle (multi, c);
318 curl_easy_cleanup (c);
319 }
320 } 316 }
317 if (c != NULL)
318 {
319 curl_multi_remove_handle (multi, c);
320 curl_easy_cleanup (c);
321 }
322 }
321 fprintf (stderr, "\n"); 323 fprintf (stderr, "\n");
322 curl_multi_cleanup (multi); 324 curl_multi_cleanup (multi);
323 zzuf_socat_stop (); 325 zzuf_socat_stop ();
@@ -331,15 +333,15 @@ int
331main (int argc, char *const *argv) 333main (int argc, char *const *argv)
332{ 334{
333 unsigned int errorCount = 0; 335 unsigned int errorCount = 0;
334 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 336 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
335 337
336 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 338 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
337 return 2; 339 return 2;
338 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 340 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
339 { 341 {
340 errorCount += testInternalGet (); 342 errorCount += testInternalGet ();
341 errorCount += testMultithreadedGet (); 343 errorCount += testMultithreadedGet ();
342 } 344 }
343 errorCount += testExternalGet (); 345 errorCount += testExternalGet ();
344 if (errorCount != 0) 346 if (errorCount != 0)
345 fprintf (stderr, "Error (code: %u)\n", errorCount); 347 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_long_header.c b/src/testzzuf/test_long_header.c
index 12a396bb..5ffaf272 100644
--- a/src/testzzuf/test_long_header.c
+++ b/src/testzzuf/test_long_header.c
@@ -43,14 +43,14 @@
43 * half of this value, so the actual value does not have 43 * half of this value, so the actual value does not have
44 * to be big at all... 44 * to be big at all...
45 */ 45 */
46#define VERY_LONG (1024*10) 46#define VERY_LONG (1024 * 10)
47 47
48static int oneone; 48static int oneone;
49 49
50static int 50static int
51apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) 51apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen)
52{ 52{
53 (void)cls;(void)addr;(void)addrlen; /* Unused. Silent compiler warning. */ 53 (void) cls; (void) addr; (void) addrlen; /* Unused. Silent compiler warning. */
54 return MHD_YES; 54 return MHD_YES;
55} 55}
56 56
@@ -64,7 +64,7 @@ struct CBC
64static size_t 64static size_t
65copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) 65copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
66{ 66{
67 (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ 67 (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */
68 return size * nmemb; 68 return size * nmemb;
69} 69}
70 70
@@ -80,14 +80,14 @@ ahc_echo (void *cls,
80 const char *me = cls; 80 const char *me = cls;
81 struct MHD_Response *response; 81 struct MHD_Response *response;
82 int ret; 82 int ret;
83 (void)version;(void)upload_data; /* Unused. Silent compiler warning. */ 83 (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
84 (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 84 (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
85 85
86 if (0 != strcmp (me, method)) 86 if (0 != strcmp (me, method))
87 return MHD_NO; /* unexpected method */ 87 return MHD_NO; /* unexpected method */
88 response = MHD_create_response_from_buffer (strlen (url), 88 response = MHD_create_response_from_buffer (strlen (url),
89 (void *) url, 89 (void *) url,
90 MHD_RESPMEM_MUST_COPY); 90 MHD_RESPMEM_MUST_COPY);
91 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 91 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
92 MHD_destroy_response (response); 92 MHD_destroy_response (response);
93 return ret; 93 return ret;
@@ -107,46 +107,47 @@ testLongUrlGet ()
107 cbc.buf = buf; 107 cbc.buf = buf;
108 cbc.size = 2048; 108 cbc.size = 2048;
109 cbc.pos = 0; 109 cbc.pos = 0;
110 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 110 d = MHD_start_daemon (
111 11080, 111 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
112 &apc_all, 112 11080,
113 NULL, 113 &apc_all,
114 &ahc_echo, 114 NULL,
115 "GET", 115 &ahc_echo,
116 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 116 "GET",
117 (size_t) (VERY_LONG / 2), MHD_OPTION_END); 117 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
118 (size_t) (VERY_LONG / 2), MHD_OPTION_END);
118 119
119 if (d == NULL) 120 if (d == NULL)
120 return 1; 121 return 1;
121 zzuf_socat_start (); 122 zzuf_socat_start ();
122 for (i = 0; i < LOOP_COUNT; i++) 123 for (i = 0; i < LOOP_COUNT; i++)
123 { 124 {
124 fprintf (stderr, "."); 125 fprintf (stderr, ".");
125 126
126 c = curl_easy_init (); 127 c = curl_easy_init ();
127 url = malloc (VERY_LONG); 128 url = malloc (VERY_LONG);
128 memset (url, 'a', VERY_LONG); 129 memset (url, 'a', VERY_LONG);
129 url[VERY_LONG - 1] = '\0'; 130 url[VERY_LONG - 1] = '\0';
130 memcpy (url, "http://127.0.0.1:11081/", 131 memcpy (url, "http://127.0.0.1:11081/",
131 strlen ("http://127.0.0.1:11081/")); 132 strlen ("http://127.0.0.1:11081/"));
132 curl_easy_setopt (c, CURLOPT_URL, url); 133 curl_easy_setopt (c, CURLOPT_URL, url);
133 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 134 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
134 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 135 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
135 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 136 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
136 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 137 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
137 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 138 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
138 if (oneone) 139 if (oneone)
139 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 140 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
140 else 141 else
141 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 142 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
142 /* NOTE: use of CONNECTTIMEOUT without also 143 /* NOTE: use of CONNECTTIMEOUT without also
143 * setting NOSIGNAL results in really weird 144 * setting NOSIGNAL results in really weird
144 * crashes on my system! */ 145 * crashes on my system! */
145 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 146 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
146 curl_easy_perform (c); 147 curl_easy_perform (c);
147 curl_easy_cleanup (c); 148 curl_easy_cleanup (c);
148 free (url); 149 free (url);
149 } 150 }
150 fprintf (stderr, "\n"); 151 fprintf (stderr, "\n");
151 zzuf_socat_stop (); 152 zzuf_socat_stop ();
152 153
@@ -169,49 +170,50 @@ testLongHeaderGet ()
169 cbc.buf = buf; 170 cbc.buf = buf;
170 cbc.size = 2048; 171 cbc.size = 2048;
171 cbc.pos = 0; 172 cbc.pos = 0;
172 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 173 d = MHD_start_daemon (
173 11080, 174 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
174 &apc_all, 175 11080,
175 NULL, 176 &apc_all,
176 &ahc_echo, 177 NULL,
177 "GET", 178 &ahc_echo,
178 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 179 "GET",
179 (size_t) (VERY_LONG / 2), MHD_OPTION_END); 180 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
181 (size_t) (VERY_LONG / 2), MHD_OPTION_END);
180 if (d == NULL) 182 if (d == NULL)
181 return 16; 183 return 16;
182 zzuf_socat_start (); 184 zzuf_socat_start ();
183 for (i = 0; i < LOOP_COUNT; i++) 185 for (i = 0; i < LOOP_COUNT; i++)
184 { 186 {
185 fprintf (stderr, "."); 187 fprintf (stderr, ".");
186 c = curl_easy_init (); 188 c = curl_easy_init ();
187 url = malloc (VERY_LONG); 189 url = malloc (VERY_LONG);
188 memset (url, 'a', VERY_LONG); 190 memset (url, 'a', VERY_LONG);
189 url[VERY_LONG - 1] = '\0'; 191 url[VERY_LONG - 1] = '\0';
190 url[VERY_LONG / 2] = ':'; 192 url[VERY_LONG / 2] = ':';
191 url[VERY_LONG / 2 + 1] = ' '; 193 url[VERY_LONG / 2 + 1] = ' ';
192 header = curl_slist_append (header, url); 194 header = curl_slist_append (header, url);
193 195
194 curl_easy_setopt (c, CURLOPT_HTTPHEADER, header); 196 curl_easy_setopt (c, CURLOPT_HTTPHEADER, header);
195 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 197 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
196 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 198 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
197 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 199 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
198 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
199 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
200 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 202 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
201 if (oneone) 203 if (oneone)
202 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
203 else 205 else
204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 206 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
205 /* NOTE: use of CONNECTTIMEOUT without also 207 /* NOTE: use of CONNECTTIMEOUT without also
206 * setting NOSIGNAL results in really weird 208 * setting NOSIGNAL results in really weird
207 * crashes on my system! */ 209 * crashes on my system! */
208 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 210 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
209 curl_easy_perform (c); 211 curl_easy_perform (c);
210 curl_slist_free_all (header); 212 curl_slist_free_all (header);
211 header = NULL; 213 header = NULL;
212 curl_easy_cleanup (c); 214 curl_easy_cleanup (c);
213 free (url); 215 free (url);
214 } 216 }
215 fprintf (stderr, "\n"); 217 fprintf (stderr, "\n");
216 zzuf_socat_stop (); 218 zzuf_socat_stop ();
217 219
diff --git a/src/testzzuf/test_post.c b/src/testzzuf/test_post.c
index 03b8e5a8..90da5e02 100644
--- a/src/testzzuf/test_post.c
+++ b/src/testzzuf/test_post.c
@@ -53,12 +53,12 @@ struct CBC
53 53
54static void 54static void
55completed_cb (void *cls, 55completed_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 struct MHD_PostProcessor *pp = *con_cls; 60 struct MHD_PostProcessor *pp = *con_cls;
61 (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ 61 (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */
62 62
63 if (NULL != pp) 63 if (NULL != pp)
64 MHD_destroy_post_processor (pp); 64 MHD_destroy_post_processor (pp);
@@ -94,8 +94,8 @@ post_iterator (void *cls,
94 const char *value, uint64_t off, size_t size) 94 const char *value, uint64_t off, size_t size)
95{ 95{
96 int *eok = cls; 96 int *eok = cls;
97 (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ 97 (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
98 (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ 98 (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */
99 99
100 if ((0 == strcmp (key, "name")) && 100 if ((0 == strcmp (key, "name")) &&
101 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size))) 101 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size)))
@@ -119,31 +119,31 @@ ahc_echo (void *cls,
119 struct MHD_Response *response; 119 struct MHD_Response *response;
120 struct MHD_PostProcessor *pp; 120 struct MHD_PostProcessor *pp;
121 int ret; 121 int ret;
122 (void)cls;(void)version; /* Unused. Silent compiler warning. */ 122 (void) cls; (void) version; /* Unused. Silent compiler warning. */
123 123
124 if (0 != strcmp ("POST", method)) 124 if (0 != strcmp ("POST", method))
125 { 125 {
126 return MHD_NO; /* unexpected method */ 126 return MHD_NO; /* unexpected method */
127 } 127 }
128 pp = *unused; 128 pp = *unused;
129 if (pp == NULL) 129 if (pp == NULL)
130 { 130 {
131 eok = 0; 131 eok = 0;
132 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 132 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
133 *unused = pp; 133 *unused = pp;
134 } 134 }
135 MHD_post_process (pp, upload_data, *upload_data_size); 135 MHD_post_process (pp, upload_data, *upload_data_size);
136 if ((eok == 3) && (0 == *upload_data_size)) 136 if ((eok == 3) && (0 == *upload_data_size))
137 { 137 {
138 response = MHD_create_response_from_buffer (strlen (url), 138 response = MHD_create_response_from_buffer (strlen (url),
139 (void *) url, 139 (void *) url,
140 MHD_RESPMEM_MUST_COPY); 140 MHD_RESPMEM_MUST_COPY);
141 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 141 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
142 MHD_destroy_response (response); 142 MHD_destroy_response (response);
143 MHD_destroy_post_processor (pp); 143 MHD_destroy_post_processor (pp);
144 *unused = NULL; 144 *unused = NULL;
145 return ret; 145 return ret;
146 } 146 }
147 *upload_data_size = 0; 147 *upload_data_size = 0;
148 return MHD_YES; 148 return MHD_YES;
149} 149}
@@ -161,38 +161,39 @@ testInternalPost ()
161 cbc.buf = buf; 161 cbc.buf = buf;
162 cbc.size = 2048; 162 cbc.size = 2048;
163 cbc.pos = 0; 163 cbc.pos = 0;
164 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 164 d = MHD_start_daemon (
165 11080, NULL, NULL, &ahc_echo, NULL, 165 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
166 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 166 11080, NULL, NULL, &ahc_echo, NULL,
167 MHD_OPTION_END); 167 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
168 MHD_OPTION_END);
168 if (d == NULL) 169 if (d == NULL)
169 return 1; 170 return 1;
170 zzuf_socat_start (); 171 zzuf_socat_start ();
171 for (i = 0; i < LOOP_COUNT; i++) 172 for (i = 0; i < LOOP_COUNT; i++)
172 { 173 {
173 fprintf (stderr, "."); 174 fprintf (stderr, ".");
174 175
175 c = curl_easy_init (); 176 c = curl_easy_init ();
176 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 177 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
177 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 178 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
178 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 179 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
179 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 180 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
180 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); 181 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
181 curl_easy_setopt (c, CURLOPT_POST, 1L); 182 curl_easy_setopt (c, CURLOPT_POST, 1L);
182 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 183 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
183 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 184 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
184 if (oneone) 185 if (oneone)
185 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 186 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
186 else 187 else
187 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 188 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
188 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 189 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
189 /* NOTE: use of CONNECTTIMEOUT without also 190 /* NOTE: use of CONNECTTIMEOUT without also
190 * setting NOSIGNAL results in really weird 191 * setting NOSIGNAL results in really weird
191 * crashes on my system! */ 192 * crashes on my system! */
192 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 193 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
193 curl_easy_perform (c); 194 curl_easy_perform (c);
194 curl_easy_cleanup (c); 195 curl_easy_cleanup (c);
195 } 196 }
196 fprintf (stderr, "\n"); 197 fprintf (stderr, "\n");
197 zzuf_socat_stop (); 198 zzuf_socat_stop ();
198 MHD_stop_daemon (d); 199 MHD_stop_daemon (d);
@@ -212,39 +213,40 @@ testMultithreadedPost ()
212 cbc.buf = buf; 213 cbc.buf = buf;
213 cbc.size = 2048; 214 cbc.size = 2048;
214 cbc.pos = 0; 215 cbc.pos = 0;
215 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 216 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
216 11080, NULL, NULL, &ahc_echo, NULL, 217 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
217 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 218 11080, NULL, NULL, &ahc_echo, NULL,
218 MHD_OPTION_END); 219 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
220 MHD_OPTION_END);
219 if (d == NULL) 221 if (d == NULL)
220 return 16; 222 return 16;
221 223
222 zzuf_socat_start (); 224 zzuf_socat_start ();
223 for (i = 0; i < LOOP_COUNT; i++) 225 for (i = 0; i < LOOP_COUNT; i++)
224 { 226 {
225 fprintf (stderr, "."); 227 fprintf (stderr, ".");
226 228
227 c = curl_easy_init (); 229 c = curl_easy_init ();
228 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 230 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
229 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 231 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
230 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 232 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
231 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 233 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
232 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); 234 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
233 curl_easy_setopt (c, CURLOPT_POST, 1L); 235 curl_easy_setopt (c, CURLOPT_POST, 1L);
234 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 236 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
235 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 237 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
236 if (oneone) 238 if (oneone)
237 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 239 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
238 else 240 else
239 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 241 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
240 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 242 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
241 /* NOTE: use of CONNECTTIMEOUT without also 243 /* NOTE: use of CONNECTTIMEOUT without also
242 * setting NOSIGNAL results in really weird 244 * setting NOSIGNAL results in really weird
243 * crashes on my system! */ 245 * crashes on my system! */
244 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 246 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
245 curl_easy_perform (c); 247 curl_easy_perform (c);
246 curl_easy_cleanup (c); 248 curl_easy_cleanup (c);
247 } 249 }
248 fprintf (stderr, "\n"); 250 fprintf (stderr, "\n");
249 zzuf_socat_stop (); 251 zzuf_socat_stop ();
250 252
@@ -275,101 +277,101 @@ testExternalPost ()
275 cbc.buf = buf; 277 cbc.buf = buf;
276 cbc.size = 2048; 278 cbc.size = 2048;
277 cbc.pos = 0; 279 cbc.pos = 0;
278 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 280 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
279 1082, NULL, NULL, &ahc_echo, NULL, 281 1082, NULL, NULL, &ahc_echo, NULL,
280 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 282 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
281 MHD_OPTION_END); 283 MHD_OPTION_END);
282 if (d == NULL) 284 if (d == NULL)
283 return 256; 285 return 256;
284 multi = curl_multi_init (); 286 multi = curl_multi_init ();
285 if (multi == NULL) 287 if (multi == NULL)
286 { 288 {
287 MHD_stop_daemon (d); 289 MHD_stop_daemon (d);
288 return 512; 290 return 512;
289 } 291 }
290 292
291 zzuf_socat_start (); 293 zzuf_socat_start ();
292 for (i = 0; i < LOOP_COUNT; i++) 294 for (i = 0; i < LOOP_COUNT; i++)
295 {
296 fprintf (stderr, ".");
297
298
299 c = curl_easy_init ();
300 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world");
301 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
302 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
303 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
304 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
305 curl_easy_setopt (c, CURLOPT_POST, 1L);
306 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
307 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
308 if (oneone)
309 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
310 else
311 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
312 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
313 /* NOTE: use of CONNECTTIMEOUT without also
314 * setting NOSIGNAL results in really weird
315 * crashes on my system! */
316 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
317
318
319 mret = curl_multi_add_handle (multi, c);
320 if (mret != CURLM_OK)
293 { 321 {
294 fprintf (stderr, "."); 322 curl_multi_cleanup (multi);
295 323 curl_easy_cleanup (c);
296 324 zzuf_socat_stop ();
297 c = curl_easy_init (); 325 MHD_stop_daemon (d);
298 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world"); 326 return 1024;
299 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 327 }
300 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 328 start = time (NULL);
301 curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); 329 while ((time (NULL) - start < 5) && (c != NULL))
302 curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); 330 {
303 curl_easy_setopt (c, CURLOPT_POST, 1L); 331 max = 0;
304 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 332 FD_ZERO (&rs);
305 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 333 FD_ZERO (&ws);
306 if (oneone) 334 FD_ZERO (&es);
307 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 335 curl_multi_perform (multi, &running);
308 else 336 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
309 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
310 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
311 /* NOTE: use of CONNECTTIMEOUT without also
312 * setting NOSIGNAL results in really weird
313 * crashes on my system! */
314 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
315
316
317 mret = curl_multi_add_handle (multi, c);
318 if (mret != CURLM_OK) 337 if (mret != CURLM_OK)
319 { 338 {
320 curl_multi_cleanup (multi); 339 curl_multi_remove_handle (multi, c);
321 curl_easy_cleanup (c); 340 curl_multi_cleanup (multi);
322 zzuf_socat_stop (); 341 curl_easy_cleanup (c);
323 MHD_stop_daemon (d); 342 zzuf_socat_stop ();
324 return 1024; 343 MHD_stop_daemon (d);
325 } 344 return 2048;
326 start = time (NULL); 345 }
327 while ((time (NULL) - start < 5) && (c != NULL)) 346 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
328 { 347 {
329 max = 0; 348 curl_multi_remove_handle (multi, c);
330 FD_ZERO (&rs); 349 curl_multi_cleanup (multi);
331 FD_ZERO (&ws); 350 curl_easy_cleanup (c);
332 FD_ZERO (&es); 351 zzuf_socat_stop ();
333 curl_multi_perform (multi, &running); 352 MHD_stop_daemon (d);
334 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 353 return 4096;
335 if (mret != CURLM_OK) 354 }
336 { 355 tv.tv_sec = 0;
337 curl_multi_remove_handle (multi, c); 356 tv.tv_usec = 1000;
338 curl_multi_cleanup (multi); 357 select (max + 1, &rs, &ws, &es, &tv);
339 curl_easy_cleanup (c); 358 curl_multi_perform (multi, &running);
340 zzuf_socat_stop (); 359 if (running == 0)
341 MHD_stop_daemon (d); 360 {
342 return 2048; 361 curl_multi_info_read (multi, &running);
343 } 362 curl_multi_remove_handle (multi, c);
344 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 363 curl_easy_cleanup (c);
345 { 364 c = NULL;
346 curl_multi_remove_handle (multi, c); 365 }
347 curl_multi_cleanup (multi); 366 MHD_run (d);
348 curl_easy_cleanup (c);
349 zzuf_socat_stop ();
350 MHD_stop_daemon (d);
351 return 4096;
352 }
353 tv.tv_sec = 0;
354 tv.tv_usec = 1000;
355 select (max + 1, &rs, &ws, &es, &tv);
356 curl_multi_perform (multi, &running);
357 if (running == 0)
358 {
359 curl_multi_info_read (multi, &running);
360 curl_multi_remove_handle (multi, c);
361 curl_easy_cleanup (c);
362 c = NULL;
363 }
364 MHD_run (d);
365 }
366 if (c != NULL)
367 {
368 curl_multi_remove_handle (multi, c);
369 curl_easy_cleanup (c);
370 }
371
372 } 367 }
368 if (c != NULL)
369 {
370 curl_multi_remove_handle (multi, c);
371 curl_easy_cleanup (c);
372 }
373
374 }
373 fprintf (stderr, "\n"); 375 fprintf (stderr, "\n");
374 curl_multi_cleanup (multi); 376 curl_multi_cleanup (multi);
375 zzuf_socat_stop (); 377 zzuf_socat_stop ();
@@ -383,17 +385,17 @@ int
383main (int argc, char *const *argv) 385main (int argc, char *const *argv)
384{ 386{
385 unsigned int errorCount = 0; 387 unsigned int errorCount = 0;
386 (void)argc; /* Unused. Silent compiler warning. */ 388 (void) argc; /* Unused. Silent compiler warning. */
387 389
388 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 390 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
389 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 391 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
390 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 392 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
391 return 2; 393 return 2;
392 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 394 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
393 { 395 {
394 errorCount += testInternalPost (); 396 errorCount += testInternalPost ();
395 errorCount += testMultithreadedPost (); 397 errorCount += testMultithreadedPost ();
396 } 398 }
397 errorCount += testExternalPost (); 399 errorCount += testExternalPost ();
398 if (errorCount != 0) 400 if (errorCount != 0)
399 fprintf (stderr, "Error (code: %u)\n", errorCount); 401 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_post_form.c b/src/testzzuf/test_post_form.c
index cbe55b5d..d7c2fad3 100644
--- a/src/testzzuf/test_post_form.c
+++ b/src/testzzuf/test_post_form.c
@@ -51,12 +51,12 @@ struct CBC
51 51
52static void 52static void
53completed_cb (void *cls, 53completed_cb (void *cls,
54 struct MHD_Connection *connection, 54 struct MHD_Connection *connection,
55 void **con_cls, 55 void **con_cls,
56 enum MHD_RequestTerminationCode toe) 56 enum MHD_RequestTerminationCode toe)
57{ 57{
58 struct MHD_PostProcessor *pp = *con_cls; 58 struct MHD_PostProcessor *pp = *con_cls;
59 (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ 59 (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */
60 60
61 if (NULL != pp) 61 if (NULL != pp)
62 MHD_destroy_post_processor (pp); 62 MHD_destroy_post_processor (pp);
@@ -91,8 +91,8 @@ post_iterator (void *cls,
91 const char *value, uint64_t off, size_t size) 91 const char *value, uint64_t off, size_t size)
92{ 92{
93 int *eok = cls; 93 int *eok = cls;
94 (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ 94 (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */
95 (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ 95 (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */
96 96
97 if (key == NULL) 97 if (key == NULL)
98 return MHD_YES; 98 return MHD_YES;
@@ -122,33 +122,33 @@ ahc_echo (void *cls,
122 struct MHD_Response *response; 122 struct MHD_Response *response;
123 struct MHD_PostProcessor *pp; 123 struct MHD_PostProcessor *pp;
124 int ret; 124 int ret;
125 (void)cls;(void)version; /* Unused. Silent compiler warning. */ 125 (void) cls; (void) version; /* Unused. Silent compiler warning. */
126 126
127 if (0 != strcmp ("POST", method)) 127 if (0 != strcmp ("POST", method))
128 { 128 {
129 return MHD_NO; /* unexpected method */ 129 return MHD_NO; /* unexpected method */
130 } 130 }
131 pp = *unused; 131 pp = *unused;
132 if (pp == NULL) 132 if (pp == NULL)
133 { 133 {
134 eok = 0; 134 eok = 0;
135 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 135 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
136 if (pp == NULL) 136 if (pp == NULL)
137 return MHD_NO; 137 return MHD_NO;
138 *unused = pp; 138 *unused = pp;
139 } 139 }
140 MHD_post_process (pp, upload_data, *upload_data_size); 140 MHD_post_process (pp, upload_data, *upload_data_size);
141 if ((eok == 3) && (0 == *upload_data_size)) 141 if ((eok == 3) && (0 == *upload_data_size))
142 { 142 {
143 response = MHD_create_response_from_buffer (strlen (url), 143 response = MHD_create_response_from_buffer (strlen (url),
144 (void *) url, 144 (void *) url,
145 MHD_RESPMEM_MUST_COPY); 145 MHD_RESPMEM_MUST_COPY);
146 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 146 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
147 MHD_destroy_response (response); 147 MHD_destroy_response (response);
148 MHD_destroy_post_processor (pp); 148 MHD_destroy_post_processor (pp);
149 *unused = NULL; 149 *unused = NULL;
150 return ret; 150 return ret;
151 } 151 }
152 *upload_data_size = 0; 152 *upload_data_size = 0;
153 return MHD_YES; 153 return MHD_YES;
154} 154}
@@ -180,37 +180,38 @@ testInternalPost ()
180 cbc.buf = buf; 180 cbc.buf = buf;
181 cbc.size = 2048; 181 cbc.size = 2048;
182 cbc.pos = 0; 182 cbc.pos = 0;
183 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 183 d = MHD_start_daemon (
184 11080, NULL, NULL, &ahc_echo, NULL, 184 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
185 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 185 11080, NULL, NULL, &ahc_echo, NULL,
186 MHD_OPTION_END); 186 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
187 MHD_OPTION_END);
187 if (d == NULL) 188 if (d == NULL)
188 return 1; 189 return 1;
189 zzuf_socat_start (); 190 zzuf_socat_start ();
190 for (i = 0; i < LOOP_COUNT; i++) 191 for (i = 0; i < LOOP_COUNT; i++)
191 { 192 {
192 fprintf (stderr, "."); 193 fprintf (stderr, ".");
193 c = curl_easy_init (); 194 c = curl_easy_init ();
194 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 195 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
195 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 196 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
196 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 197 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
197 pd = make_form (); 198 pd = make_form ();
198 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); 199 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
199 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
200 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
201 if (oneone) 202 if (oneone)
202 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 203 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
203 else 204 else
204 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 205 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
205 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 206 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
206 /* NOTE: use of CONNECTTIMEOUT without also 207 /* NOTE: use of CONNECTTIMEOUT without also
207 * setting NOSIGNAL results in really weird 208 * setting NOSIGNAL results in really weird
208 * crashes on my system! */ 209 * crashes on my system! */
209 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 210 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
210 curl_easy_perform (c); 211 curl_easy_perform (c);
211 curl_easy_cleanup (c); 212 curl_easy_cleanup (c);
212 curl_formfree (pd); 213 curl_formfree (pd);
213 } 214 }
214 fprintf (stderr, "\n"); 215 fprintf (stderr, "\n");
215 zzuf_socat_stop (); 216 zzuf_socat_stop ();
216 MHD_stop_daemon (d); 217 MHD_stop_daemon (d);
@@ -231,37 +232,38 @@ testMultithreadedPost ()
231 cbc.buf = buf; 232 cbc.buf = buf;
232 cbc.size = 2048; 233 cbc.size = 2048;
233 cbc.pos = 0; 234 cbc.pos = 0;
234 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 235 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
236 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
235 11080, NULL, NULL, &ahc_echo, NULL, 237 11080, NULL, NULL, &ahc_echo, NULL,
236 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 238 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
237 MHD_OPTION_END); 239 MHD_OPTION_END);
238 if (d == NULL) 240 if (d == NULL)
239 return 16; 241 return 16;
240 zzuf_socat_start (); 242 zzuf_socat_start ();
241 for (i = 0; i < LOOP_COUNT; i++) 243 for (i = 0; i < LOOP_COUNT; i++)
242 { 244 {
243 fprintf (stderr, "."); 245 fprintf (stderr, ".");
244 c = curl_easy_init (); 246 c = curl_easy_init ();
245 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 247 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
246 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 248 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
247 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 249 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
248 pd = make_form (); 250 pd = make_form ();
249 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd); 251 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
250 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 252 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
251 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 253 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
252 if (oneone) 254 if (oneone)
253 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 255 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
254 else 256 else
255 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 257 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
256 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 258 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
257 /* NOTE: use of CONNECTTIMEOUT without also 259 /* NOTE: use of CONNECTTIMEOUT without also
258 * setting NOSIGNAL results in really weird 260 * setting NOSIGNAL results in really weird
259 * crashes on my system! */ 261 * crashes on my system! */
260 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 262 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
261 curl_easy_perform (c); 263 curl_easy_perform (c);
262 curl_easy_cleanup (c); 264 curl_easy_cleanup (c);
263 curl_formfree (pd); 265 curl_formfree (pd);
264 } 266 }
265 fprintf (stderr, "\n"); 267 fprintf (stderr, "\n");
266 zzuf_socat_stop (); 268 zzuf_socat_stop ();
267 MHD_stop_daemon (d); 269 MHD_stop_daemon (d);
@@ -292,100 +294,100 @@ testExternalPost ()
292 cbc.buf = buf; 294 cbc.buf = buf;
293 cbc.size = 2048; 295 cbc.size = 2048;
294 cbc.pos = 0; 296 cbc.pos = 0;
295 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 297 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
296 1082, NULL, NULL, &ahc_echo, NULL, 298 1082, NULL, NULL, &ahc_echo, NULL,
297 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, 299 MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
298 MHD_OPTION_END); 300 MHD_OPTION_END);
299 if (d == NULL) 301 if (d == NULL)
300 return 256; 302 return 256;
301 multi = curl_multi_init (); 303 multi = curl_multi_init ();
302 if (multi == NULL) 304 if (multi == NULL)
305 {
306 MHD_stop_daemon (d);
307 return 512;
308 }
309 zzuf_socat_start ();
310 for (i = 0; i < LOOP_COUNT; i++)
311 {
312 fprintf (stderr, ".");
313
314 c = curl_easy_init ();
315 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world");
316 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
317 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
318 pd = make_form ();
319 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
320 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
321 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
322 if (oneone)
323 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
324 else
325 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
326 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
327 /* NOTE: use of CONNECTTIMEOUT without also
328 * setting NOSIGNAL results in really weird
329 * crashes on my system! */
330 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
331
332 mret = curl_multi_add_handle (multi, c);
333 if (mret != CURLM_OK)
303 { 334 {
335 curl_multi_cleanup (multi);
336 curl_formfree (pd);
337 curl_easy_cleanup (c);
338 zzuf_socat_stop ();
304 MHD_stop_daemon (d); 339 MHD_stop_daemon (d);
305 return 512; 340 return 1024;
306 } 341 }
307 zzuf_socat_start (); 342 start = time (NULL);
308 for (i = 0; i < LOOP_COUNT; i++) 343 while ((time (NULL) - start < 5) && (c != NULL))
309 { 344 {
310 fprintf (stderr, "."); 345 max = 0;
311 346 FD_ZERO (&rs);
312 c = curl_easy_init (); 347 FD_ZERO (&ws);
313 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world"); 348 FD_ZERO (&es);
314 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 349 curl_multi_perform (multi, &running);
315 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 350 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
316 pd = make_form ();
317 curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
318 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
319 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
320 if (oneone)
321 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
322 else
323 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
324 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
325 /* NOTE: use of CONNECTTIMEOUT without also
326 * setting NOSIGNAL results in really weird
327 * crashes on my system! */
328 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
329
330 mret = curl_multi_add_handle (multi, c);
331 if (mret != CURLM_OK) 351 if (mret != CURLM_OK)
332 { 352 {
333 curl_multi_cleanup (multi); 353 curl_multi_remove_handle (multi, c);
334 curl_formfree (pd); 354 curl_multi_cleanup (multi);
335 curl_easy_cleanup (c); 355 curl_easy_cleanup (c);
336 zzuf_socat_stop (); 356 zzuf_socat_stop ();
337 MHD_stop_daemon (d); 357 MHD_stop_daemon (d);
338 return 1024; 358 curl_formfree (pd);
339 } 359 return 2048;
340 start = time (NULL); 360 }
341 while ((time (NULL) - start < 5) && (c != NULL)) 361 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
342 { 362 {
343 max = 0; 363 curl_multi_remove_handle (multi, c);
344 FD_ZERO (&rs); 364 curl_multi_cleanup (multi);
345 FD_ZERO (&ws); 365 curl_easy_cleanup (c);
346 FD_ZERO (&es); 366 curl_formfree (pd);
347 curl_multi_perform (multi, &running); 367 zzuf_socat_stop ();
348 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 368 MHD_stop_daemon (d);
349 if (mret != CURLM_OK) 369 return 4096;
350 { 370 }
351 curl_multi_remove_handle (multi, c); 371 tv.tv_sec = 0;
352 curl_multi_cleanup (multi); 372 tv.tv_usec = 1000;
353 curl_easy_cleanup (c); 373 select (max + 1, &rs, &ws, &es, &tv);
354 zzuf_socat_stop (); 374 curl_multi_perform (multi, &running);
355 MHD_stop_daemon (d); 375 if (running == 0)
356 curl_formfree (pd); 376 {
357 return 2048; 377 curl_multi_info_read (multi, &running);
358 } 378 curl_multi_remove_handle (multi, c);
359 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 379 curl_easy_cleanup (c);
360 { 380 c = NULL;
361 curl_multi_remove_handle (multi, c); 381 }
362 curl_multi_cleanup (multi); 382 MHD_run (d);
363 curl_easy_cleanup (c);
364 curl_formfree (pd);
365 zzuf_socat_stop ();
366 MHD_stop_daemon (d);
367 return 4096;
368 }
369 tv.tv_sec = 0;
370 tv.tv_usec = 1000;
371 select (max + 1, &rs, &ws, &es, &tv);
372 curl_multi_perform (multi, &running);
373 if (running == 0)
374 {
375 curl_multi_info_read (multi, &running);
376 curl_multi_remove_handle (multi, c);
377 curl_easy_cleanup (c);
378 c = NULL;
379 }
380 MHD_run (d);
381 }
382 if (c != NULL)
383 {
384 curl_multi_remove_handle (multi, c);
385 curl_easy_cleanup (c);
386 }
387 curl_formfree (pd);
388 } 383 }
384 if (c != NULL)
385 {
386 curl_multi_remove_handle (multi, c);
387 curl_easy_cleanup (c);
388 }
389 curl_formfree (pd);
390 }
389 fprintf (stderr, "\n"); 391 fprintf (stderr, "\n");
390 zzuf_socat_stop (); 392 zzuf_socat_stop ();
391 curl_multi_cleanup (multi); 393 curl_multi_cleanup (multi);
@@ -399,17 +401,17 @@ int
399main (int argc, char *const *argv) 401main (int argc, char *const *argv)
400{ 402{
401 unsigned int errorCount = 0; 403 unsigned int errorCount = 0;
402 (void)argc; /* Unused. Silent compiler warning. */ 404 (void) argc; /* Unused. Silent compiler warning. */
403 405
404 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 406 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
405 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 407 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
406 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 408 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
407 return 2; 409 return 2;
408 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 410 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
409 { 411 {
410 errorCount += testInternalPost (); 412 errorCount += testInternalPost ();
411 errorCount += testMultithreadedPost (); 413 errorCount += testMultithreadedPost ();
412 } 414 }
413 errorCount += testExternalPost (); 415 errorCount += testExternalPost ();
414 if (errorCount != 0) 416 if (errorCount != 0)
415 fprintf (stderr, "Error (code: %u)\n", errorCount); 417 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_put.c b/src/testzzuf/test_put.c
index 5a237ddd..605f4804 100644
--- a/src/testzzuf/test_put.c
+++ b/src/testzzuf/test_put.c
@@ -86,29 +86,29 @@ ahc_echo (void *cls,
86 int *done = cls; 86 int *done = cls;
87 struct MHD_Response *response; 87 struct MHD_Response *response;
88 int ret; 88 int ret;
89 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 89 (void) version; (void) unused; /* Unused. Silent compiler warning. */
90 90
91 if (0 != strcmp ("PUT", method)) 91 if (0 != strcmp ("PUT", method))
92 return MHD_NO; /* unexpected method */ 92 return MHD_NO; /* unexpected method */
93 if ((*done) == 0) 93 if ((*done) == 0)
94 {
95 if (*upload_data_size != 8)
96 return MHD_YES; /* not yet ready */
97 if (0 == memcmp (upload_data, "Hello123", 8))
94 { 98 {
95 if (*upload_data_size != 8) 99 *upload_data_size = 0;
96 return MHD_YES; /* not yet ready */
97 if (0 == memcmp (upload_data, "Hello123", 8))
98 {
99 *upload_data_size = 0;
100 }
101 else
102 {
103 printf ("Invalid upload data `%8s'!\n", upload_data);
104 return MHD_NO;
105 }
106 *done = 1;
107 return MHD_YES;
108 } 100 }
101 else
102 {
103 printf ("Invalid upload data `%8s'!\n", upload_data);
104 return MHD_NO;
105 }
106 *done = 1;
107 return MHD_YES;
108 }
109 response = MHD_create_response_from_buffer (strlen (url), 109 response = MHD_create_response_from_buffer (strlen (url),
110 (void *) url, 110 (void *) url,
111 MHD_RESPMEM_MUST_COPY); 111 MHD_RESPMEM_MUST_COPY);
112 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 112 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
113 MHD_destroy_response (response); 113 MHD_destroy_response (response);
114 return ret; 114 return ret;
@@ -129,37 +129,38 @@ testInternalPut ()
129 cbc.buf = buf; 129 cbc.buf = buf;
130 cbc.size = 2048; 130 cbc.size = 2048;
131 cbc.pos = 0; 131 cbc.pos = 0;
132 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 132 d = MHD_start_daemon (
133 11080, 133 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
134 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 134 11080,
135 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
135 if (d == NULL) 136 if (d == NULL)
136 return 1; 137 return 1;
137 zzuf_socat_start (); 138 zzuf_socat_start ();
138 for (i = 0; i < LOOP_COUNT; i++) 139 for (i = 0; i < LOOP_COUNT; i++)
139 { 140 {
140 fprintf (stderr, "."); 141 fprintf (stderr, ".");
141 c = curl_easy_init (); 142 c = curl_easy_init ();
142 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 143 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
143 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 144 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
144 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 145 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
145 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 146 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
146 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 147 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
147 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 148 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
148 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 149 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
149 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 150 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
150 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 151 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
151 if (oneone) 152 if (oneone)
152 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 153 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
153 else 154 else
154 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 155 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
155 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 156 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
156 /* NOTE: use of CONNECTTIMEOUT without also 157 /* NOTE: use of CONNECTTIMEOUT without also
157 * setting NOSIGNAL results in really weird 158 * setting NOSIGNAL results in really weird
158 * crashes on my system! */ 159 * crashes on my system! */
159 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 160 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
160 curl_easy_perform (c); 161 curl_easy_perform (c);
161 curl_easy_cleanup (c); 162 curl_easy_cleanup (c);
162 } 163 }
163 fprintf (stderr, "\n"); 164 fprintf (stderr, "\n");
164 zzuf_socat_stop (); 165 zzuf_socat_stop ();
165 MHD_stop_daemon (d); 166 MHD_stop_daemon (d);
@@ -180,37 +181,38 @@ testMultithreadedPut ()
180 cbc.buf = buf; 181 cbc.buf = buf;
181 cbc.size = 2048; 182 cbc.size = 2048;
182 cbc.pos = 0; 183 cbc.pos = 0;
183 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 184 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
185 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
184 11080, 186 11080,
185 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 187 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
186 if (d == NULL) 188 if (d == NULL)
187 return 16; 189 return 16;
188 zzuf_socat_start (); 190 zzuf_socat_start ();
189 for (i = 0; i < LOOP_COUNT; i++) 191 for (i = 0; i < LOOP_COUNT; i++)
190 { 192 {
191 fprintf (stderr, "."); 193 fprintf (stderr, ".");
192 c = curl_easy_init (); 194 c = curl_easy_init ();
193 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 195 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
194 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 196 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
195 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 197 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
196 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 198 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
197 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 199 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
198 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 200 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
199 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 201 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
200 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 202 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
201 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 203 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
202 if (oneone) 204 if (oneone)
203 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 205 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
204 else 206 else
205 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 207 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
206 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 208 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
207 /* NOTE: use of CONNECTTIMEOUT without also 209 /* NOTE: use of CONNECTTIMEOUT without also
208 * setting NOSIGNAL results in really weird 210 * setting NOSIGNAL results in really weird
209 * crashes on my system! */ 211 * crashes on my system! */
210 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 212 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
211 curl_easy_perform (c); 213 curl_easy_perform (c);
212 curl_easy_cleanup (c); 214 curl_easy_cleanup (c);
213 } 215 }
214 fprintf (stderr, "\n"); 216 fprintf (stderr, "\n");
215 zzuf_socat_stop (); 217 zzuf_socat_stop ();
216 MHD_stop_daemon (d); 218 MHD_stop_daemon (d);
@@ -242,99 +244,99 @@ testExternalPut ()
242 cbc.buf = buf; 244 cbc.buf = buf;
243 cbc.size = 2048; 245 cbc.size = 2048;
244 cbc.pos = 0; 246 cbc.pos = 0;
245 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */ , 247 d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_ERROR_LOG */,
246 11080, 248 11080,
247 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 249 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
248 if (d == NULL) 250 if (d == NULL)
249 return 256; 251 return 256;
250 multi = curl_multi_init (); 252 multi = curl_multi_init ();
251 if (multi == NULL) 253 if (multi == NULL)
252 { 254 {
253 MHD_stop_daemon (d); 255 MHD_stop_daemon (d);
254 return 512; 256 return 512;
255 } 257 }
256 zzuf_socat_start (); 258 zzuf_socat_start ();
257 for (i = 0; i < LOOP_COUNT; i++) 259 for (i = 0; i < LOOP_COUNT; i++)
258 { 260 {
259 fprintf (stderr, "."); 261 fprintf (stderr, ".");
260 262
261 c = curl_easy_init (); 263 c = curl_easy_init ();
262 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 264 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
263 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 265 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
264 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 266 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
265 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 267 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
266 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 268 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
267 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 269 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
268 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 270 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
269 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 271 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
270 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 272 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
271 if (oneone) 273 if (oneone)
272 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 274 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
273 else 275 else
274 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 276 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
275 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 277 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
276 /* NOTE: use of CONNECTTIMEOUT without also 278 /* NOTE: use of CONNECTTIMEOUT without also
277 * setting NOSIGNAL results in really weird 279 * setting NOSIGNAL results in really weird
278 * crashes on my system! */ 280 * crashes on my system! */
279 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 281 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
280 282
281 283
282 284
283 mret = curl_multi_add_handle (multi, c); 285 mret = curl_multi_add_handle (multi, c);
286 if (mret != CURLM_OK)
287 {
288 curl_multi_cleanup (multi);
289 curl_easy_cleanup (c);
290 zzuf_socat_stop ();
291 MHD_stop_daemon (d);
292 return 1024;
293 }
294 start = time (NULL);
295 while ((time (NULL) - start < 5) && (c != NULL))
296 {
297 max = 0;
298 FD_ZERO (&rs);
299 FD_ZERO (&ws);
300 FD_ZERO (&es);
301 curl_multi_perform (multi, &running);
302 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
284 if (mret != CURLM_OK) 303 if (mret != CURLM_OK)
285 { 304 {
286 curl_multi_cleanup (multi); 305 curl_multi_remove_handle (multi, c);
287 curl_easy_cleanup (c); 306 curl_multi_cleanup (multi);
288 zzuf_socat_stop (); 307 curl_easy_cleanup (c);
289 MHD_stop_daemon (d); 308 zzuf_socat_stop ();
290 return 1024; 309 MHD_stop_daemon (d);
291 } 310 return 2048;
292 start = time (NULL); 311 }
293 while ((time (NULL) - start < 5) && (c != NULL)) 312 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
294 { 313 {
295 max = 0; 314 curl_multi_remove_handle (multi, c);
296 FD_ZERO (&rs); 315 curl_multi_cleanup (multi);
297 FD_ZERO (&ws); 316 curl_easy_cleanup (c);
298 FD_ZERO (&es); 317 zzuf_socat_stop ();
299 curl_multi_perform (multi, &running); 318 MHD_stop_daemon (d);
300 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 319 return 4096;
301 if (mret != CURLM_OK) 320 }
302 { 321 tv.tv_sec = 0;
303 curl_multi_remove_handle (multi, c); 322 tv.tv_usec = 1000;
304 curl_multi_cleanup (multi); 323 select (max + 1, &rs, &ws, &es, &tv);
305 curl_easy_cleanup (c); 324 curl_multi_perform (multi, &running);
306 zzuf_socat_stop (); 325 if (running == 0)
307 MHD_stop_daemon (d); 326 {
308 return 2048; 327 curl_multi_info_read (multi, &running);
309 } 328 curl_multi_remove_handle (multi, c);
310 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 329 curl_easy_cleanup (c);
311 { 330 c = NULL;
312 curl_multi_remove_handle (multi, c); 331 }
313 curl_multi_cleanup (multi); 332 MHD_run (d);
314 curl_easy_cleanup (c); 333 }
315 zzuf_socat_stop (); 334 if (c != NULL)
316 MHD_stop_daemon (d); 335 {
317 return 4096; 336 curl_multi_remove_handle (multi, c);
318 } 337 curl_easy_cleanup (c);
319 tv.tv_sec = 0;
320 tv.tv_usec = 1000;
321 select (max + 1, &rs, &ws, &es, &tv);
322 curl_multi_perform (multi, &running);
323 if (running == 0)
324 {
325 curl_multi_info_read (multi, &running);
326 curl_multi_remove_handle (multi, c);
327 curl_easy_cleanup (c);
328 c = NULL;
329 }
330 MHD_run (d);
331 }
332 if (c != NULL)
333 {
334 curl_multi_remove_handle (multi, c);
335 curl_easy_cleanup (c);
336 }
337 } 338 }
339 }
338 fprintf (stderr, "\n"); 340 fprintf (stderr, "\n");
339 curl_multi_cleanup (multi); 341 curl_multi_cleanup (multi);
340 zzuf_socat_stop (); 342 zzuf_socat_stop ();
@@ -347,17 +349,17 @@ int
347main (int argc, char *const *argv) 349main (int argc, char *const *argv)
348{ 350{
349 unsigned int errorCount = 0; 351 unsigned int errorCount = 0;
350 (void)argc; /* Unused. Silent compiler warning. */ 352 (void) argc; /* Unused. Silent compiler warning. */
351 353
352 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 354 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
353 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 355 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
354 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 356 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
355 return 2; 357 return 2;
356 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 358 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
357 { 359 {
358 errorCount += testInternalPut (); 360 errorCount += testInternalPut ();
359 errorCount += testMultithreadedPut (); 361 errorCount += testMultithreadedPut ();
360 } 362 }
361 errorCount += testExternalPut (); 363 errorCount += testExternalPut ();
362 if (errorCount != 0) 364 if (errorCount != 0)
363 fprintf (stderr, "Error (code: %u)\n", errorCount); 365 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_put_chunked.c b/src/testzzuf/test_put_chunked.c
index d016d84e..f66e1ff9 100644
--- a/src/testzzuf/test_put_chunked.c
+++ b/src/testzzuf/test_put_chunked.c
@@ -87,34 +87,34 @@ ahc_echo (void *cls,
87 struct MHD_Response *response; 87 struct MHD_Response *response;
88 int ret; 88 int ret;
89 int have; 89 int have;
90 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 90 (void) version; (void) unused; /* Unused. Silent compiler warning. */
91 91
92 if (0 != strcmp ("PUT", method)) 92 if (0 != strcmp ("PUT", method))
93 return MHD_NO; /* unexpected method */ 93 return MHD_NO; /* unexpected method */
94 if ((*done) < 8) 94 if ((*done) < 8)
95 {
96 have = *upload_data_size;
97 if (have + *done > 8)
95 { 98 {
96 have = *upload_data_size; 99 return MHD_NO;
97 if (have + *done > 8) 100 }
98 { 101 if (0 == memcmp (upload_data, &"Hello123"[*done], have))
99 return MHD_NO; 102 {
100 } 103 *done += have;
101 if (0 == memcmp (upload_data, &"Hello123"[*done], have)) 104 *upload_data_size = 0;
102 { 105 }
103 *done += have; 106 else
104 *upload_data_size = 0; 107 {
105 } 108 return MHD_NO;
106 else 109 }
107 {
108 return MHD_NO;
109 }
110#if 0 110#if 0
111 fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8); 111 fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8);
112#endif 112#endif
113 return MHD_YES; 113 return MHD_YES;
114 } 114 }
115 response = MHD_create_response_from_buffer (strlen (url), 115 response = MHD_create_response_from_buffer (strlen (url),
116 (void *) url, 116 (void *) url,
117 MHD_RESPMEM_MUST_COPY); 117 MHD_RESPMEM_MUST_COPY);
118 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 118 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
119 MHD_destroy_response (response); 119 MHD_destroy_response (response);
120 return ret; 120 return ret;
@@ -142,30 +142,30 @@ testInternalPut ()
142 return 1; 142 return 1;
143 zzuf_socat_start (); 143 zzuf_socat_start ();
144 for (i = 0; i < LOOP_COUNT; i++) 144 for (i = 0; i < LOOP_COUNT; i++)
145 { 145 {
146 fprintf (stderr, "."); 146 fprintf (stderr, ".");
147 c = curl_easy_init (); 147 c = curl_easy_init ();
148 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11080/hello_world"); 148 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11080/hello_world");
149 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 149 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
150 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 150 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
151 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 151 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
152 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 152 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
153 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 153 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
154 /* by not giving the file size, we force chunking! */ 154 /* by not giving the file size, we force chunking! */
155 /* 155 /*
156 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 156 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
157 */ 157 */
158 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 158 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
159 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 159 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
160 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 160 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
161 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 161 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
162 /* NOTE: use of CONNECTTIMEOUT without also 162 /* NOTE: use of CONNECTTIMEOUT without also
163 * setting NOSIGNAL results in really weird 163 * setting NOSIGNAL results in really weird
164 * crashes on my system! */ 164 * crashes on my system! */
165 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 165 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
166 curl_easy_perform (c); 166 curl_easy_perform (c);
167 curl_easy_cleanup (c); 167 curl_easy_cleanup (c);
168 } 168 }
169 fprintf (stderr, "\n"); 169 fprintf (stderr, "\n");
170 zzuf_socat_stop (); 170 zzuf_socat_stop ();
171 MHD_stop_daemon (d); 171 MHD_stop_daemon (d);
@@ -186,7 +186,8 @@ testMultithreadedPut ()
186 cbc.buf = buf; 186 cbc.buf = buf;
187 cbc.size = 2048; 187 cbc.size = 2048;
188 cbc.pos = 0; 188 cbc.pos = 0;
189 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 189 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
190 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
190 11081, 191 11081,
191 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 192 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
192 if (d == NULL) 193 if (d == NULL)
@@ -211,14 +212,14 @@ testMultithreadedPut ()
211 * crashes on my system! */ 212 * crashes on my system! */
212 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 213 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
213 if (CURLE_OK != (errornum = curl_easy_perform (c))) 214 if (CURLE_OK != (errornum = curl_easy_perform (c)))
214 { 215 {
215 fprintf (stderr, 216 fprintf (stderr,
216 "curl_easy_perform failed: `%s'\n", 217 "curl_easy_perform failed: `%s'\n",
217 curl_easy_strerror (errornum)); 218 curl_easy_strerror (errornum));
218 curl_easy_cleanup (c); 219 curl_easy_cleanup (c);
219 MHD_stop_daemon (d); 220 MHD_stop_daemon (d);
220 return 32; 221 return 32;
221 } 222 }
222 curl_easy_cleanup (c); 223 curl_easy_cleanup (c);
223 MHD_stop_daemon (d); 224 MHD_stop_daemon (d);
224 if (cbc.pos != strlen ("/hello_world")) 225 if (cbc.pos != strlen ("/hello_world"))
@@ -262,90 +263,90 @@ testExternalPut ()
262 263
263 multi = curl_multi_init (); 264 multi = curl_multi_init ();
264 if (multi == NULL) 265 if (multi == NULL)
265 { 266 {
266 MHD_stop_daemon (d); 267 MHD_stop_daemon (d);
267 return 512; 268 return 512;
268 } 269 }
269 zzuf_socat_start (); 270 zzuf_socat_start ();
270 for (i = 0; i < LOOP_COUNT; i++) 271 for (i = 0; i < LOOP_COUNT; i++)
271 { 272 {
272 fprintf (stderr, "."); 273 fprintf (stderr, ".");
273 c = curl_easy_init (); 274 c = curl_easy_init ();
274 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11082/hello_world"); 275 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11082/hello_world");
275 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 276 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
276 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 277 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
277 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 278 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
278 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 279 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
279 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 280 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
280 /* by not giving the file size, we force chunking! */ 281 /* by not giving the file size, we force chunking! */
281 /* 282 /*
282 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); 283 curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
283 */ 284 */
284 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 285 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
285 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 286 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
286 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 287 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
287 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 288 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
288 /* NOTE: use of CONNECTTIMEOUT without also 289 /* NOTE: use of CONNECTTIMEOUT without also
289 * setting NOSIGNAL results in really weird 290 * setting NOSIGNAL results in really weird
290 * crashes on my system! */ 291 * crashes on my system! */
291 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 292 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
292 293
293 294
294 mret = curl_multi_add_handle (multi, c); 295 mret = curl_multi_add_handle (multi, c);
296 if (mret != CURLM_OK)
297 {
298 curl_multi_cleanup (multi);
299 curl_easy_cleanup (c);
300 zzuf_socat_stop ();
301 MHD_stop_daemon (d);
302 return 1024;
303 }
304 start = time (NULL);
305 while ((time (NULL) - start < 5) && (c != NULL))
306 {
307 max = 0;
308 FD_ZERO (&rs);
309 FD_ZERO (&ws);
310 FD_ZERO (&es);
311 curl_multi_perform (multi, &running);
312 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
295 if (mret != CURLM_OK) 313 if (mret != CURLM_OK)
296 { 314 {
297 curl_multi_cleanup (multi); 315 curl_multi_remove_handle (multi, c);
298 curl_easy_cleanup (c); 316 curl_multi_cleanup (multi);
299 zzuf_socat_stop (); 317 curl_easy_cleanup (c);
300 MHD_stop_daemon (d); 318 zzuf_socat_stop ();
301 return 1024; 319 MHD_stop_daemon (d);
302 } 320 return 2048;
303 start = time (NULL); 321 }
304 while ((time (NULL) - start < 5) && (c != NULL)) 322 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
305 { 323 {
306 max = 0; 324 curl_multi_remove_handle (multi, c);
307 FD_ZERO (&rs); 325 curl_multi_cleanup (multi);
308 FD_ZERO (&ws); 326 curl_easy_cleanup (c);
309 FD_ZERO (&es); 327 zzuf_socat_stop ();
310 curl_multi_perform (multi, &running); 328 MHD_stop_daemon (d);
311 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 329 return 4096;
312 if (mret != CURLM_OK) 330 }
313 { 331 tv.tv_sec = 0;
314 curl_multi_remove_handle (multi, c); 332 tv.tv_usec = 1000;
315 curl_multi_cleanup (multi); 333 select (max + 1, &rs, &ws, &es, &tv);
316 curl_easy_cleanup (c); 334 curl_multi_perform (multi, &running);
317 zzuf_socat_stop (); 335 if (running == 0)
318 MHD_stop_daemon (d); 336 {
319 return 2048; 337 curl_multi_info_read (multi, &running);
320 } 338 curl_multi_remove_handle (multi, c);
321 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 339 curl_easy_cleanup (c);
322 { 340 c = NULL;
323 curl_multi_remove_handle (multi, c); 341 }
324 curl_multi_cleanup (multi); 342 MHD_run (d);
325 curl_easy_cleanup (c); 343 }
326 zzuf_socat_stop (); 344 if (c != NULL)
327 MHD_stop_daemon (d); 345 {
328 return 4096; 346 curl_multi_remove_handle (multi, c);
329 } 347 curl_easy_cleanup (c);
330 tv.tv_sec = 0;
331 tv.tv_usec = 1000;
332 select (max + 1, &rs, &ws, &es, &tv);
333 curl_multi_perform (multi, &running);
334 if (running == 0)
335 {
336 curl_multi_info_read (multi, &running);
337 curl_multi_remove_handle (multi, c);
338 curl_easy_cleanup (c);
339 c = NULL;
340 }
341 MHD_run (d);
342 }
343 if (c != NULL)
344 {
345 curl_multi_remove_handle (multi, c);
346 curl_easy_cleanup (c);
347 }
348 } 348 }
349 }
349 fprintf (stderr, "\n"); 350 fprintf (stderr, "\n");
350 curl_multi_cleanup (multi); 351 curl_multi_cleanup (multi);
351 zzuf_socat_stop (); 352 zzuf_socat_stop ();
@@ -359,15 +360,15 @@ int
359main (int argc, char *const *argv) 360main (int argc, char *const *argv)
360{ 361{
361 unsigned int errorCount = 0; 362 unsigned int errorCount = 0;
362 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 363 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
363 364
364 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 365 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
365 return 2; 366 return 2;
366 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 367 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
367 { 368 {
368 errorCount += testInternalPut (); 369 errorCount += testInternalPut ();
369 errorCount += testMultithreadedPut (); 370 errorCount += testMultithreadedPut ();
370 } 371 }
371 errorCount += testExternalPut (); 372 errorCount += testExternalPut ();
372 if (errorCount != 0) 373 if (errorCount != 0)
373 fprintf (stderr, "Error (code: %u)\n", errorCount); 374 fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testzzuf/test_put_large.c b/src/testzzuf/test_put_large.c
index 815ce77d..1186f583 100644
--- a/src/testzzuf/test_put_large.c
+++ b/src/testzzuf/test_put_large.c
@@ -94,35 +94,35 @@ ahc_echo (void *cls,
94 int *done = cls; 94 int *done = cls;
95 struct MHD_Response *response; 95 struct MHD_Response *response;
96 int ret; 96 int ret;
97 (void)version;(void)unused; /* Unused. Silent compiler warning. */ 97 (void) version; (void) unused; /* Unused. Silent compiler warning. */
98 98
99 if (0 != strcmp ("PUT", method)) 99 if (0 != strcmp ("PUT", method))
100 return MHD_NO; /* unexpected method */ 100 return MHD_NO; /* unexpected method */
101 if ((*done) == 0) 101 if ((*done) == 0)
102 {
103 if (*upload_data_size != PUT_SIZE)
102 { 104 {
103 if (*upload_data_size != PUT_SIZE)
104 {
105#if 0 105#if 0
106 fprintf (stderr, 106 fprintf (stderr,
107 "Waiting for more data (%u/%u)...\n", 107 "Waiting for more data (%u/%u)...\n",
108 *upload_data_size, PUT_SIZE); 108 *upload_data_size, PUT_SIZE);
109#endif 109#endif
110 return MHD_YES; /* not yet ready */ 110 return MHD_YES; /* not yet ready */
111 }
112 if (0 == memcmp (upload_data, put_buffer, PUT_SIZE))
113 {
114 *upload_data_size = 0;
115 }
116 else
117 {
118 return MHD_NO;
119 }
120 *done = 1;
121 return MHD_YES;
122 } 111 }
112 if (0 == memcmp (upload_data, put_buffer, PUT_SIZE))
113 {
114 *upload_data_size = 0;
115 }
116 else
117 {
118 return MHD_NO;
119 }
120 *done = 1;
121 return MHD_YES;
122 }
123 response = MHD_create_response_from_buffer (strlen (url), 123 response = MHD_create_response_from_buffer (strlen (url),
124 (void *) url, 124 (void *) url,
125 MHD_RESPMEM_MUST_COPY); 125 MHD_RESPMEM_MUST_COPY);
126 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 126 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
127 MHD_destroy_response (response); 127 MHD_destroy_response (response);
128 return ret; 128 return ret;
@@ -143,38 +143,39 @@ testInternalPut ()
143 cbc.buf = buf; 143 cbc.buf = buf;
144 cbc.size = 2048; 144 cbc.size = 2048;
145 cbc.pos = 0; 145 cbc.pos = 0;
146 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 146 d = MHD_start_daemon (
147 11080, 147 MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
148 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 148 11080,
149 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
149 if (d == NULL) 150 if (d == NULL)
150 return 1; 151 return 1;
151 zzuf_socat_start (); 152 zzuf_socat_start ();
152 for (i = 0; i < LOOP_COUNT; i++) 153 for (i = 0; i < LOOP_COUNT; i++)
153 { 154 {
154 fprintf (stderr, "."); 155 fprintf (stderr, ".");
155 156
156 c = curl_easy_init (); 157 c = curl_easy_init ();
157 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 158 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
158 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 159 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
159 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 160 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
160 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 161 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
161 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 162 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
162 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 163 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
163 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE); 164 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE);
164 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 165 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
165 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 166 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
166 if (oneone) 167 if (oneone)
167 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 168 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
168 else 169 else
169 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 170 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
170 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 171 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
171 /* NOTE: use of CONNECTTIMEOUT without also 172 /* NOTE: use of CONNECTTIMEOUT without also
172 * setting NOSIGNAL results in really weird 173 * setting NOSIGNAL results in really weird
173 * crashes on my system! */ 174 * crashes on my system! */
174 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 175 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
175 curl_easy_perform (c); 176 curl_easy_perform (c);
176 curl_easy_cleanup (c); 177 curl_easy_cleanup (c);
177 } 178 }
178 fprintf (stderr, "\n"); 179 fprintf (stderr, "\n");
179 zzuf_socat_stop (); 180 zzuf_socat_stop ();
180 MHD_stop_daemon (d); 181 MHD_stop_daemon (d);
@@ -195,38 +196,39 @@ testMultithreadedPut ()
195 cbc.buf = buf; 196 cbc.buf = buf;
196 cbc.size = 2048; 197 cbc.size = 2048;
197 cbc.pos = 0; 198 cbc.pos = 0;
198 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 199 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
200 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */,
199 11080, 201 11080,
200 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); 202 NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
201 if (d == NULL) 203 if (d == NULL)
202 return 16; 204 return 16;
203 zzuf_socat_start (); 205 zzuf_socat_start ();
204 for (i = 0; i < LOOP_COUNT; i++) 206 for (i = 0; i < LOOP_COUNT; i++)
205 { 207 {
206 fprintf (stderr, "."); 208 fprintf (stderr, ".");
207 209
208 c = curl_easy_init (); 210 c = curl_easy_init ();
209 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 211 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
210 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 212 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
211 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 213 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
212 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); 214 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
213 curl_easy_setopt (c, CURLOPT_READDATA, &pos); 215 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
214 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); 216 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
215 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE); 217 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE);
216 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 218 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
217 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); 219 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
218 if (oneone) 220 if (oneone)
219 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 221 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
220 else 222 else
221 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 223 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
222 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); 224 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
223 /* NOTE: use of CONNECTTIMEOUT without also 225 /* NOTE: use of CONNECTTIMEOUT without also
224 * setting NOSIGNAL results in really weird 226 * setting NOSIGNAL results in really weird
225 * crashes on my system! */ 227 * crashes on my system! */
226 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 228 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
227 curl_easy_perform (c); 229 curl_easy_perform (c);
228 curl_easy_cleanup (c); 230 curl_easy_cleanup (c);
229 } 231 }
230 fprintf (stderr, "\n"); 232 fprintf (stderr, "\n");
231 zzuf_socat_stop (); 233 zzuf_socat_stop ();
232 MHD_stop_daemon (d); 234 MHD_stop_daemon (d);
@@ -267,92 +269,92 @@ testExternalPut ()
267 return 256; 269 return 256;
268 multi = curl_multi_init (); 270 multi = curl_multi_init ();
269 if (multi == NULL) 271 if (multi == NULL)
272 {
273 MHD_stop_daemon (d);
274 return 512;
275 }
276 zzuf_socat_start ();
277 for (i = 0; i < LOOP_COUNT; i++)
278 {
279 fprintf (stderr, ".");
280
281 c = curl_easy_init ();
282 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
283 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
284 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
285 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
286 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
287 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
288 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE);
289 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
290 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
291 if (oneone)
292 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
293 else
294 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
295 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
296 /* NOTE: use of CONNECTTIMEOUT without also
297 * setting NOSIGNAL results in really weird
298 * crashes on my system! */
299 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
300
301
302
303 mret = curl_multi_add_handle (multi, c);
304 if (mret != CURLM_OK)
270 { 305 {
306 curl_multi_cleanup (multi);
307 curl_easy_cleanup (c);
308 zzuf_socat_stop ();
271 MHD_stop_daemon (d); 309 MHD_stop_daemon (d);
272 return 512; 310 return 1024;
273 } 311 }
274 zzuf_socat_start (); 312 start = time (NULL);
275 for (i = 0; i < LOOP_COUNT; i++) 313 while ((time (NULL) - start < 5) && (c != NULL))
276 { 314 {
277 fprintf (stderr, "."); 315 max = 0;
278 316 FD_ZERO (&rs);
279 c = curl_easy_init (); 317 FD_ZERO (&ws);
280 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); 318 FD_ZERO (&es);
281 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 319 curl_multi_perform (multi, &running);
282 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 320 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
283 curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
284 curl_easy_setopt (c, CURLOPT_READDATA, &pos);
285 curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
286 curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE);
287 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
288 curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
289 if (oneone)
290 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
291 else
292 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
293 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
294 /* NOTE: use of CONNECTTIMEOUT without also
295 * setting NOSIGNAL results in really weird
296 * crashes on my system! */
297 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
298
299
300
301 mret = curl_multi_add_handle (multi, c);
302 if (mret != CURLM_OK) 321 if (mret != CURLM_OK)
303 { 322 {
304 curl_multi_cleanup (multi); 323 curl_multi_remove_handle (multi, c);
305 curl_easy_cleanup (c); 324 curl_multi_cleanup (multi);
306 zzuf_socat_stop (); 325 curl_easy_cleanup (c);
307 MHD_stop_daemon (d); 326 zzuf_socat_stop ();
308 return 1024; 327 MHD_stop_daemon (d);
309 } 328 return 2048;
310 start = time (NULL); 329 }
311 while ((time (NULL) - start < 5) && (c != NULL)) 330 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
312 { 331 {
313 max = 0; 332 curl_multi_remove_handle (multi, c);
314 FD_ZERO (&rs); 333 curl_multi_cleanup (multi);
315 FD_ZERO (&ws); 334 curl_easy_cleanup (c);
316 FD_ZERO (&es); 335 zzuf_socat_stop ();
317 curl_multi_perform (multi, &running); 336 MHD_stop_daemon (d);
318 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 337 return 4096;
319 if (mret != CURLM_OK) 338 }
320 { 339 tv.tv_sec = 0;
321 curl_multi_remove_handle (multi, c); 340 tv.tv_usec = 1000;
322 curl_multi_cleanup (multi); 341 select (max + 1, &rs, &ws, &es, &tv);
323 curl_easy_cleanup (c); 342 curl_multi_perform (multi, &running);
324 zzuf_socat_stop (); 343 if (running == 0)
325 MHD_stop_daemon (d); 344 {
326 return 2048; 345 curl_multi_info_read (multi, &running);
327 } 346 curl_multi_remove_handle (multi, c);
328 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 347 curl_easy_cleanup (c);
329 { 348 c = NULL;
330 curl_multi_remove_handle (multi, c); 349 }
331 curl_multi_cleanup (multi); 350 MHD_run (d);
332 curl_easy_cleanup (c);
333 zzuf_socat_stop ();
334 MHD_stop_daemon (d);
335 return 4096;
336 }
337 tv.tv_sec = 0;
338 tv.tv_usec = 1000;
339 select (max + 1, &rs, &ws, &es, &tv);
340 curl_multi_perform (multi, &running);
341 if (running == 0)
342 {
343 curl_multi_info_read (multi, &running);
344 curl_multi_remove_handle (multi, c);
345 curl_easy_cleanup (c);
346 c = NULL;
347 }
348 MHD_run (d);
349 }
350 if (c != NULL)
351 {
352 curl_multi_remove_handle (multi, c);
353 curl_easy_cleanup (c);
354 }
355 } 351 }
352 if (c != NULL)
353 {
354 curl_multi_remove_handle (multi, c);
355 curl_easy_cleanup (c);
356 }
357 }
356 fprintf (stderr, "\n"); 358 fprintf (stderr, "\n");
357 zzuf_socat_stop (); 359 zzuf_socat_stop ();
358 curl_multi_cleanup (multi); 360 curl_multi_cleanup (multi);
@@ -365,19 +367,19 @@ int
365main (int argc, char *const *argv) 367main (int argc, char *const *argv)
366{ 368{
367 unsigned int errorCount = 0; 369 unsigned int errorCount = 0;
368 (void)argc; /* Unused. Silent compiler warning. */ 370 (void) argc; /* Unused. Silent compiler warning. */
369 371
370 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 372 oneone = (NULL != strrchr (argv[0], (int) '/')) ?
371 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 373 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
372 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 374 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
373 return 2; 375 return 2;
374 put_buffer = malloc (PUT_SIZE); 376 put_buffer = malloc (PUT_SIZE);
375 memset (put_buffer, 1, PUT_SIZE); 377 memset (put_buffer, 1, PUT_SIZE);
376 if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) 378 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
377 { 379 {
378 errorCount += testInternalPut (); 380 errorCount += testInternalPut ();
379 errorCount += testMultithreadedPut (); 381 errorCount += testMultithreadedPut ();
380 } 382 }
381 errorCount += testExternalPut (); 383 errorCount += testExternalPut ();
382 free (put_buffer); 384 free (put_buffer);
383 if (errorCount != 0) 385 if (errorCount != 0)