aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/https/test_https_get_select.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/https/test_https_get_select.c')
-rw-r--r--src/testcurl/https/test_https_get_select.c185
1 files changed, 95 insertions, 90 deletions
diff --git a/src/testcurl/https/test_https_get_select.c b/src/testcurl/https/test_https_get_select.c
index 94b4a051..ce74c1d7 100644
--- a/src/testcurl/https/test_https_get_select.c
+++ b/src/testcurl/https/test_https_get_select.c
@@ -52,19 +52,19 @@ ahc_echo (void *cls,
52 const char *me = cls; 52 const char *me = cls;
53 struct MHD_Response *response; 53 struct MHD_Response *response;
54 int ret; 54 int ret;
55 (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 55 (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */
56 56
57 if (0 != strcmp (me, method)) 57 if (0 != strcmp (me, method))
58 return MHD_NO; /* unexpected method */ 58 return MHD_NO; /* unexpected method */
59 if (&ptr != *unused) 59 if (&ptr != *unused)
60 { 60 {
61 *unused = &ptr; 61 *unused = &ptr;
62 return MHD_YES; 62 return MHD_YES;
63 } 63 }
64 *unused = NULL; 64 *unused = NULL;
65 response = MHD_create_response_from_buffer (strlen (url), 65 response = MHD_create_response_from_buffer (strlen (url),
66 (void *) url, 66 (void *) url,
67 MHD_RESPMEM_MUST_COPY); 67 MHD_RESPMEM_MUST_COPY);
68 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 68 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
69 MHD_destroy_response (response); 69 MHD_destroy_response (response);
70 if (ret == MHD_NO) 70 if (ret == MHD_NO)
@@ -111,24 +111,26 @@ testExternalGet (int flags)
111 port, NULL, NULL, &ahc_echo, "GET", 111 port, NULL, NULL, &ahc_echo, "GET",
112 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 112 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
113 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 113 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
114 MHD_OPTION_END); 114 MHD_OPTION_END);
115 if (d == NULL) 115 if (d == NULL)
116 return 256; 116 return 256;
117 if (0 == port) 117 if (0 == port)
118 {
119 const union MHD_DaemonInfo *dinfo;
120 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
121 if ((NULL == dinfo) ||(0 == dinfo->port) )
118 { 122 {
119 const union MHD_DaemonInfo *dinfo; 123 MHD_stop_daemon (d); return 32;
120 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
121 if (NULL == dinfo || 0 == dinfo->port)
122 { MHD_stop_daemon (d); return 32; }
123 port = (int)dinfo->port;
124 } 124 }
125 port = (int) dinfo->port;
126 }
125 127
126 if (curl_uses_nss_ssl() == 0) 128 if (curl_uses_nss_ssl () == 0)
127 aes256_sha = "rsa_aes_256_sha"; 129 aes256_sha = "rsa_aes_256_sha";
128 130
129 c = curl_easy_init (); 131 c = curl_easy_init ();
130 curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world"); 132 curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world");
131 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 133 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
132 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 134 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
133 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 135 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
134 /* TLS options */ 136 /* TLS options */
@@ -151,90 +153,93 @@ testExternalGet (int flags)
151 153
152 multi = curl_multi_init (); 154 multi = curl_multi_init ();
153 if (multi == NULL) 155 if (multi == NULL)
156 {
157 curl_easy_cleanup (c);
158 MHD_stop_daemon (d);
159 return 512;
160 }
161 mret = curl_multi_add_handle (multi, c);
162 if (mret != CURLM_OK)
163 {
164 curl_multi_cleanup (multi);
165 curl_easy_cleanup (c);
166 MHD_stop_daemon (d);
167 return 1024;
168 }
169 start = time (NULL);
170 while ((time (NULL) - start < 5) && (multi != NULL))
171 {
172 maxsock = MHD_INVALID_SOCKET;
173 maxposixs = -1;
174 FD_ZERO (&rs);
175 FD_ZERO (&ws);
176 FD_ZERO (&es);
177 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
178 if (mret != CURLM_OK)
154 { 179 {
180 curl_multi_remove_handle (multi, c);
181 curl_multi_cleanup (multi);
155 curl_easy_cleanup (c); 182 curl_easy_cleanup (c);
156 MHD_stop_daemon (d); 183 MHD_stop_daemon (d);
157 return 512; 184 return 2048;
158 } 185 }
159 mret = curl_multi_add_handle (multi, c); 186 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
160 if (mret != CURLM_OK)
161 { 187 {
188 curl_multi_remove_handle (multi, c);
162 curl_multi_cleanup (multi); 189 curl_multi_cleanup (multi);
163 curl_easy_cleanup (c); 190 curl_easy_cleanup (c);
164 MHD_stop_daemon (d); 191 MHD_stop_daemon (d);
165 return 1024; 192 return 4096;
166 } 193 }
167 start = time (NULL); 194 tv.tv_sec = 0;
168 while ((time (NULL) - start < 5) && (multi != NULL)) 195 tv.tv_usec = 1000;
196 if (-1 != maxposixs)
169 { 197 {
170 maxsock = MHD_INVALID_SOCKET; 198 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
171 maxposixs = -1; 199 {
172 FD_ZERO (&rs);
173 FD_ZERO (&ws);
174 FD_ZERO (&es);
175 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
176 if (mret != CURLM_OK)
177 {
178 curl_multi_remove_handle (multi, c);
179 curl_multi_cleanup (multi);
180 curl_easy_cleanup (c);
181 MHD_stop_daemon (d);
182 return 2048;
183 }
184 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
185 {
186 curl_multi_remove_handle (multi, c);
187 curl_multi_cleanup (multi);
188 curl_easy_cleanup (c);
189 MHD_stop_daemon (d);
190 return 4096;
191 }
192 tv.tv_sec = 0;
193 tv.tv_usec = 1000;
194 if (-1 != maxposixs)
195 {
196 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
197 {
198#ifdef MHD_POSIX_SOCKETS 200#ifdef MHD_POSIX_SOCKETS
199 if (EINTR != errno) 201 if (EINTR != errno)
200 abort (); 202 abort ();
201#else 203#else
202 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 204 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
203 abort (); 205 ws.
204 Sleep (1000); 206 fd_count)
207 ||(0 != es.fd_count) )
208 abort ();
209 Sleep (1000);
205#endif 210#endif
206 } 211 }
207 }
208 else
209 (void)sleep (1);
210 curl_multi_perform (multi, &running);
211 if (running == 0)
212 {
213 msg = curl_multi_info_read (multi, &running);
214 if (msg == NULL)
215 break;
216 if (msg->msg == CURLMSG_DONE)
217 {
218 if (msg->data.result != CURLE_OK)
219 printf ("%s failed at %s:%d: `%s'\n",
220 "curl_multi_perform",
221 __FILE__,
222 __LINE__, curl_easy_strerror (msg->data.result));
223 curl_multi_remove_handle (multi, c);
224 curl_multi_cleanup (multi);
225 curl_easy_cleanup (c);
226 c = NULL;
227 multi = NULL;
228 }
229 }
230 MHD_run (d);
231 } 212 }
232 if (multi != NULL) 213 else
214 (void) sleep (1);
215 curl_multi_perform (multi, &running);
216 if (running == 0)
233 { 217 {
234 curl_multi_remove_handle (multi, c); 218 msg = curl_multi_info_read (multi, &running);
235 curl_easy_cleanup (c); 219 if (msg == NULL)
236 curl_multi_cleanup (multi); 220 break;
221 if (msg->msg == CURLMSG_DONE)
222 {
223 if (msg->data.result != CURLE_OK)
224 printf ("%s failed at %s:%d: `%s'\n",
225 "curl_multi_perform",
226 __FILE__,
227 __LINE__, curl_easy_strerror (msg->data.result));
228 curl_multi_remove_handle (multi, c);
229 curl_multi_cleanup (multi);
230 curl_easy_cleanup (c);
231 c = NULL;
232 multi = NULL;
233 }
237 } 234 }
235 MHD_run (d);
236 }
237 if (multi != NULL)
238 {
239 curl_multi_remove_handle (multi, c);
240 curl_easy_cleanup (c);
241 curl_multi_cleanup (multi);
242 }
238 MHD_stop_daemon (d); 243 MHD_stop_daemon (d);
239 if (cbc.pos != strlen ("/hello_world")) 244 if (cbc.pos != strlen ("/hello_world"))
240 return 8192; 245 return 8192;
@@ -248,17 +253,17 @@ int
248main (int argc, char *const *argv) 253main (int argc, char *const *argv)
249{ 254{
250 unsigned int errorCount = 0; 255 unsigned int errorCount = 0;
251 (void)argc; /* Unused. Silent compiler warning. */ 256 (void) argc; /* Unused. Silent compiler warning. */
252 257
253 oneone = 0; 258 oneone = 0;
254 if (!testsuite_curl_global_init ()) 259 if (! testsuite_curl_global_init ())
255 return 99; 260 return 99;
256 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) 261 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version)
257 { 262 {
258 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 263 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
259 curl_global_cleanup (); 264 curl_global_cleanup ();
260 return 77; 265 return 77;
261 } 266 }
262 267
263#ifdef EPOLL_SUPPORT 268#ifdef EPOLL_SUPPORT
264 errorCount += testExternalGet (MHD_USE_EPOLL); 269 errorCount += testExternalGet (MHD_USE_EPOLL);