aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_process_arguments.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_process_arguments.c')
-rw-r--r--src/testcurl/test_process_arguments.c176
1 files changed, 90 insertions, 86 deletions
diff --git a/src/testcurl/test_process_arguments.c b/src/testcurl/test_process_arguments.c
index 0817836d..3094a97f 100644
--- a/src/testcurl/test_process_arguments.c
+++ b/src/testcurl/test_process_arguments.c
@@ -74,15 +74,15 @@ ahc_echo (void *cls,
74 struct MHD_Response *response; 74 struct MHD_Response *response;
75 int ret; 75 int ret;
76 const char *hdr; 76 const char *hdr;
77 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 77 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
78 78
79 if (0 != strcmp (me, method)) 79 if (0 != strcmp (me, method))
80 return MHD_NO; /* unexpected method */ 80 return MHD_NO; /* unexpected method */
81 if (&ptr != *unused) 81 if (&ptr != *unused)
82 { 82 {
83 *unused = &ptr; 83 *unused = &ptr;
84 return MHD_YES; 84 return MHD_YES;
85 } 85 }
86 *unused = NULL; 86 *unused = NULL;
87 hdr = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "k"); 87 hdr = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "k");
88 if ((hdr == NULL) || (0 != strcmp (hdr, "v x"))) 88 if ((hdr == NULL) || (0 != strcmp (hdr, "v x")))
@@ -96,12 +96,12 @@ ahc_echo (void *cls,
96 if ((hdr == NULL) || (0 != strcmp (hdr, "\240bar"))) 96 if ((hdr == NULL) || (0 != strcmp (hdr, "\240bar")))
97 abort (); 97 abort ();
98 if (3 != MHD_get_connection_values (connection, 98 if (3 != MHD_get_connection_values (connection,
99 MHD_GET_ARGUMENT_KIND, 99 MHD_GET_ARGUMENT_KIND,
100 NULL, NULL)) 100 NULL, NULL))
101 abort (); 101 abort ();
102 response = MHD_create_response_from_buffer (strlen (url), 102 response = MHD_create_response_from_buffer (strlen (url),
103 (void *) url, 103 (void *) url,
104 MHD_RESPMEM_MUST_COPY); 104 MHD_RESPMEM_MUST_COPY);
105 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 105 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
106 MHD_destroy_response (response); 106 MHD_destroy_response (response);
107 if (ret == MHD_NO) 107 if (ret == MHD_NO)
@@ -137,11 +137,11 @@ testExternalGet ()
137 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 137 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
138 port = 0; 138 port = 0;
139 else 139 else
140 { 140 {
141 port = 1410; 141 port = 1410;
142 if (oneone) 142 if (oneone)
143 port += 5; 143 port += 5;
144 } 144 }
145 145
146 multi = NULL; 146 multi = NULL;
147 cbc.buf = buf; 147 cbc.buf = buf;
@@ -152,17 +152,19 @@ testExternalGet ()
152 if (d == NULL) 152 if (d == NULL)
153 return 256; 153 return 256;
154 if (0 == port) 154 if (0 == port)
155 {
156 const union MHD_DaemonInfo *dinfo;
157 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
158 if ((NULL == dinfo) ||(0 == dinfo->port) )
155 { 159 {
156 const union MHD_DaemonInfo *dinfo; 160 MHD_stop_daemon (d); return 32;
157 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
158 if (NULL == dinfo || 0 == dinfo->port)
159 { MHD_stop_daemon (d); return 32; }
160 port = (int)dinfo->port;
161 } 161 }
162 port = (int) dinfo->port;
163 }
162 c = curl_easy_init (); 164 c = curl_easy_init ();
163 curl_easy_setopt (c, CURLOPT_URL, 165 curl_easy_setopt (c, CURLOPT_URL,
164 "http://127.0.0.1/hello+world?k=v+x&hash=%23foo&space=%A0bar"); 166 "http://127.0.0.1/hello+world?k=v+x&hash=%23foo&space=%A0bar");
165 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 167 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
166 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 168 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
167 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 169 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
168 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); 170 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
@@ -180,86 +182,88 @@ testExternalGet ()
180 182
181 multi = curl_multi_init (); 183 multi = curl_multi_init ();
182 if (multi == NULL) 184 if (multi == NULL)
185 {
186 curl_easy_cleanup (c);
187 MHD_stop_daemon (d);
188 return 512;
189 }
190 mret = curl_multi_add_handle (multi, c);
191 if (mret != CURLM_OK)
192 {
193 curl_multi_cleanup (multi);
194 curl_easy_cleanup (c);
195 MHD_stop_daemon (d);
196 return 1024;
197 }
198 start = time (NULL);
199 while ((time (NULL) - start < 5) && (multi != NULL))
200 {
201 maxsock = MHD_INVALID_SOCKET;
202 maxposixs = -1;
203 FD_ZERO (&rs);
204 FD_ZERO (&ws);
205 FD_ZERO (&es);
206 curl_multi_perform (multi, &running);
207 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
208 if (mret != CURLM_OK)
183 { 209 {
210 curl_multi_remove_handle (multi, c);
211 curl_multi_cleanup (multi);
184 curl_easy_cleanup (c); 212 curl_easy_cleanup (c);
185 MHD_stop_daemon (d); 213 MHD_stop_daemon (d);
186 return 512; 214 return 2048;
187 } 215 }
188 mret = curl_multi_add_handle (multi, c); 216 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
189 if (mret != CURLM_OK)
190 { 217 {
218 curl_multi_remove_handle (multi, c);
191 curl_multi_cleanup (multi); 219 curl_multi_cleanup (multi);
192 curl_easy_cleanup (c); 220 curl_easy_cleanup (c);
193 MHD_stop_daemon (d); 221 MHD_stop_daemon (d);
194 return 1024; 222 return 4096;
195 } 223 }
196 start = time (NULL); 224 tv.tv_sec = 0;
197 while ((time (NULL) - start < 5) && (multi != NULL)) 225 tv.tv_usec = 1000;
226 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
198 { 227 {
199 maxsock = MHD_INVALID_SOCKET;
200 maxposixs = -1;
201 FD_ZERO (&rs);
202 FD_ZERO (&ws);
203 FD_ZERO (&es);
204 curl_multi_perform (multi, &running);
205 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
206 if (mret != CURLM_OK)
207 {
208 curl_multi_remove_handle (multi, c);
209 curl_multi_cleanup (multi);
210 curl_easy_cleanup (c);
211 MHD_stop_daemon (d);
212 return 2048;
213 }
214 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
215 {
216 curl_multi_remove_handle (multi, c);
217 curl_multi_cleanup (multi);
218 curl_easy_cleanup (c);
219 MHD_stop_daemon (d);
220 return 4096;
221 }
222 tv.tv_sec = 0;
223 tv.tv_usec = 1000;
224 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
225 {
226#ifdef MHD_POSIX_SOCKETS 228#ifdef MHD_POSIX_SOCKETS
227 if (EINTR != errno) 229 if (EINTR != errno)
228 abort (); 230 abort ();
229#else 231#else
230 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 232 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
231 abort (); 233 ws.fd_count)
232 Sleep (1000); 234 ||(0 != es.fd_count) )
235 abort ();
236 Sleep (1000);
233#endif 237#endif
234 }
235 curl_multi_perform (multi, &running);
236 if (running == 0)
237 {
238 msg = curl_multi_info_read (multi, &running);
239 if (msg == NULL)
240 break;
241 if (msg->msg == CURLMSG_DONE)
242 {
243 if (msg->data.result != CURLE_OK)
244 printf ("%s failed at %s:%d: `%s'\n",
245 "curl_multi_perform",
246 __FILE__,
247 __LINE__, curl_easy_strerror (msg->data.result));
248 curl_multi_remove_handle (multi, c);
249 curl_multi_cleanup (multi);
250 curl_easy_cleanup (c);
251 c = NULL;
252 multi = NULL;
253 }
254 }
255 MHD_run (d);
256 } 238 }
257 if (multi != NULL) 239 curl_multi_perform (multi, &running);
240 if (running == 0)
258 { 241 {
259 curl_multi_remove_handle (multi, c); 242 msg = curl_multi_info_read (multi, &running);
260 curl_easy_cleanup (c); 243 if (msg == NULL)
261 curl_multi_cleanup (multi); 244 break;
245 if (msg->msg == CURLMSG_DONE)
246 {
247 if (msg->data.result != CURLE_OK)
248 printf ("%s failed at %s:%d: `%s'\n",
249 "curl_multi_perform",
250 __FILE__,
251 __LINE__, curl_easy_strerror (msg->data.result));
252 curl_multi_remove_handle (multi, c);
253 curl_multi_cleanup (multi);
254 curl_easy_cleanup (c);
255 c = NULL;
256 multi = NULL;
257 }
262 } 258 }
259 MHD_run (d);
260 }
261 if (multi != NULL)
262 {
263 curl_multi_remove_handle (multi, c);
264 curl_easy_cleanup (c);
265 curl_multi_cleanup (multi);
266 }
263 MHD_stop_daemon (d); 267 MHD_stop_daemon (d);
264 if (cbc.pos != strlen ("/hello+world")) 268 if (cbc.pos != strlen ("/hello+world"))
265 return 8192; 269 return 8192;
@@ -273,9 +277,9 @@ int
273main (int argc, char *const *argv) 277main (int argc, char *const *argv)
274{ 278{
275 unsigned int errorCount = 0; 279 unsigned int errorCount = 0;
276 (void)argc; /* Unused. Silent compiler warning. */ 280 (void) argc; /* Unused. Silent compiler warning. */
277 281
278 if (NULL == argv || 0 == argv[0]) 282 if ((NULL == argv)||(0 == argv[0]))
279 return 99; 283 return 99;
280 oneone = has_in_name (argv[0], "11"); 284 oneone = has_in_name (argv[0], "11");
281 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 285 if (0 != curl_global_init (CURL_GLOBAL_WIN32))