aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/https/test_empty_response.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/https/test_empty_response.c')
-rw-r--r--src/testcurl/https/test_empty_response.c170
1 files changed, 88 insertions, 82 deletions
diff --git a/src/testcurl/https/test_empty_response.c b/src/testcurl/https/test_empty_response.c
index f53a70ec..41026896 100644
--- a/src/testcurl/https/test_empty_response.c
+++ b/src/testcurl/https/test_empty_response.c
@@ -49,11 +49,11 @@ ahc_echo (void *cls,
49{ 49{
50 struct MHD_Response *response; 50 struct MHD_Response *response;
51 int ret; 51 int ret;
52 (void)cls;(void)url;(void)method;(void)version; /* Unused. Silent compiler warning. */ 52 (void) cls; (void) url; (void) method; (void) version; /* Unused. Silent compiler warning. */
53 (void)upload_data;(void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ 53 (void) upload_data; (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */
54 54
55 response = MHD_create_response_from_buffer (0, NULL, 55 response = MHD_create_response_from_buffer (0, NULL,
56 MHD_RESPMEM_PERSISTENT); 56 MHD_RESPMEM_PERSISTENT);
57 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 57 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
58 MHD_destroy_response (response); 58 MHD_destroy_response (response);
59 return ret; 59 return ret;
@@ -88,31 +88,34 @@ testInternalSelectGet ()
88 cbc.buf = buf; 88 cbc.buf = buf;
89 cbc.size = 2048; 89 cbc.size = 2048;
90 cbc.pos = 0; 90 cbc.pos = 0;
91 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_TLS | MHD_USE_INTERNAL_POLLING_THREAD, 91 d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_TLS
92 | MHD_USE_INTERNAL_POLLING_THREAD,
92 port, NULL, NULL, &ahc_echo, "GET", 93 port, NULL, NULL, &ahc_echo, "GET",
93 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 94 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
94 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 95 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
95 MHD_OPTION_END); 96 MHD_OPTION_END);
96 if (d == NULL) 97 if (d == NULL)
97 return 256; 98 return 256;
98 99
99 if (0 == port) 100 if (0 == port)
101 {
102 const union MHD_DaemonInfo *dinfo;
103 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
104 if ((NULL == dinfo) ||(0 == dinfo->port) )
100 { 105 {
101 const union MHD_DaemonInfo *dinfo; 106 MHD_stop_daemon (d); return 32;
102 dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
103 if (NULL == dinfo || 0 == dinfo->port)
104 { MHD_stop_daemon (d); return 32; }
105 port = (int)dinfo->port;
106 } 107 }
108 port = (int) dinfo->port;
109 }
107 char *aes256_sha = "AES256-SHA"; 110 char *aes256_sha = "AES256-SHA";
108 if (curl_uses_nss_ssl() == 0) 111 if (curl_uses_nss_ssl () == 0)
109 { 112 {
110 aes256_sha = "rsa_aes_256_sha"; 113 aes256_sha = "rsa_aes_256_sha";
111 } 114 }
112 115
113 c = curl_easy_init (); 116 c = curl_easy_init ();
114 curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world"); 117 curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/hello_world");
115 curl_easy_setopt (c, CURLOPT_PORT, (long)port); 118 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
116 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 119 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
117 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 120 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
118 /* TLS options */ 121 /* TLS options */
@@ -135,80 +138,83 @@ testInternalSelectGet ()
135 138
136 multi = curl_multi_init (); 139 multi = curl_multi_init ();
137 if (multi == NULL) 140 if (multi == NULL)
138 { 141 {
139 curl_easy_cleanup (c); 142 curl_easy_cleanup (c);
140 MHD_stop_daemon (d); 143 MHD_stop_daemon (d);
141 return 512; 144 return 512;
142 } 145 }
143 mret = curl_multi_add_handle (multi, c); 146 mret = curl_multi_add_handle (multi, c);
144 if (mret != CURLM_OK) 147 if (mret != CURLM_OK)
148 {
149 curl_multi_cleanup (multi);
150 curl_easy_cleanup (c);
151 MHD_stop_daemon (d);
152 return 1024;
153 }
154 start = time (NULL);
155 while ((time (NULL) - start < 5) && (multi != NULL))
156 {
157 maxposixs = -1;
158 FD_ZERO (&rs);
159 FD_ZERO (&ws);
160 FD_ZERO (&es);
161 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
162 if (mret != CURLM_OK)
145 { 163 {
164 curl_multi_remove_handle (multi, c);
146 curl_multi_cleanup (multi); 165 curl_multi_cleanup (multi);
147 curl_easy_cleanup (c); 166 curl_easy_cleanup (c);
148 MHD_stop_daemon (d); 167 MHD_stop_daemon (d);
149 return 1024; 168 return 2048;
150 } 169 }
151 start = time (NULL); 170 tv.tv_sec = 0;
152 while ((time (NULL) - start < 5) && (multi != NULL)) 171 tv.tv_usec = 1000;
172 if (-1 != maxposixs)
153 { 173 {
154 maxposixs = -1; 174 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
155 FD_ZERO (&rs); 175 {
156 FD_ZERO (&ws);
157 FD_ZERO (&es);
158 mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
159 if (mret != CURLM_OK)
160 {
161 curl_multi_remove_handle (multi, c);
162 curl_multi_cleanup (multi);
163 curl_easy_cleanup (c);
164 MHD_stop_daemon (d);
165 return 2048;
166 }
167 tv.tv_sec = 0;
168 tv.tv_usec = 1000;
169 if (-1 != maxposixs)
170 {
171 if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
172 {
173#ifdef MHD_POSIX_SOCKETS 176#ifdef MHD_POSIX_SOCKETS
174 if (EINTR != errno) 177 if (EINTR != errno)
175 abort (); 178 abort ();
176#else 179#else
177 if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) 180 if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 !=
178 abort (); 181 ws.
179 Sleep (1000); 182 fd_count)
183 ||(0 != es.fd_count) )
184 abort ();
185 Sleep (1000);
180#endif 186#endif
181 } 187 }
182 }
183 else
184 (void)sleep (1);
185 curl_multi_perform (multi, &running);
186 if (running == 0)
187 {
188 msg = curl_multi_info_read (multi, &running);
189 if (msg == NULL)
190 break;
191 if (msg->msg == CURLMSG_DONE)
192 {
193 if (msg->data.result != CURLE_OK)
194 printf ("%s failed at %s:%d: `%s'\n",
195 "curl_multi_perform",
196 __FILE__,
197 __LINE__, curl_easy_strerror (msg->data.result));
198 curl_multi_remove_handle (multi, c);
199 curl_multi_cleanup (multi);
200 curl_easy_cleanup (c);
201 c = NULL;
202 multi = NULL;
203 }
204 }
205 } 188 }
206 if (multi != NULL) 189 else
190 (void) sleep (1);
191 curl_multi_perform (multi, &running);
192 if (running == 0)
207 { 193 {
208 curl_multi_remove_handle (multi, c); 194 msg = curl_multi_info_read (multi, &running);
209 curl_easy_cleanup (c); 195 if (msg == NULL)
210 curl_multi_cleanup (multi); 196 break;
197 if (msg->msg == CURLMSG_DONE)
198 {
199 if (msg->data.result != CURLE_OK)
200 printf ("%s failed at %s:%d: `%s'\n",
201 "curl_multi_perform",
202 __FILE__,
203 __LINE__, curl_easy_strerror (msg->data.result));
204 curl_multi_remove_handle (multi, c);
205 curl_multi_cleanup (multi);
206 curl_easy_cleanup (c);
207 c = NULL;
208 multi = NULL;
209 }
211 } 210 }
211 }
212 if (multi != NULL)
213 {
214 curl_multi_remove_handle (multi, c);
215 curl_easy_cleanup (c);
216 curl_multi_cleanup (multi);
217 }
212 MHD_stop_daemon (d); 218 MHD_stop_daemon (d);
213 if (cbc.pos != 0) 219 if (cbc.pos != 0)
214 return 8192; 220 return 8192;
@@ -220,16 +226,16 @@ int
220main (int argc, char *const *argv) 226main (int argc, char *const *argv)
221{ 227{
222 unsigned int errorCount = 0; 228 unsigned int errorCount = 0;
223 (void)argc; /* Unused. Silent compiler warning. */ 229 (void) argc; /* Unused. Silent compiler warning. */
224 230
225 if (!testsuite_curl_global_init ()) 231 if (! testsuite_curl_global_init ())
226 return 99; 232 return 99;
227 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) 233 if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version)
228 { 234 {
229 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); 235 fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
230 curl_global_cleanup (); 236 curl_global_cleanup ();
231 return 77; 237 return 77;
232 } 238 }
233 if (0 != (errorCount = testInternalSelectGet ())) 239 if (0 != (errorCount = testInternalSelectGet ()))
234 fprintf (stderr, "Failed test: %s, error: %u.\n", argv[0], errorCount); 240 fprintf (stderr, "Failed test: %s, error: %u.\n", argv[0], errorCount);
235 curl_global_cleanup (); 241 curl_global_cleanup ();