diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-17 16:56:41 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-17 16:56:41 +0200 |
commit | 972103dc288e2a2396e060018e7c3733f29a940d (patch) | |
tree | aeb0b3a182d5168f12752928d3204342c9581e91 /src/testcurl | |
parent | cbbfd0591fc639ddd21a5850f54f403fb7394174 (diff) | |
download | libmicrohttpd-972103dc288e2a2396e060018e7c3733f29a940d.tar.gz libmicrohttpd-972103dc288e2a2396e060018e7c3733f29a940d.zip |
applying uncrustify to ensure uniform indentation
Diffstat (limited to 'src/testcurl')
46 files changed, 5638 insertions, 5257 deletions
diff --git a/src/testcurl/curl_version_check.c b/src/testcurl/curl_version_check.c index dff143f8..d1134f42 100644 --- a/src/testcurl/curl_version_check.c +++ b/src/testcurl/curl_version_check.c | |||
@@ -39,11 +39,11 @@ parse_version_number (const char **s) | |||
39 | char num[17]; | 39 | char num[17]; |
40 | 40 | ||
41 | while (i < 16 && ((**s >= '0') & (**s <= '9'))) | 41 | while (i < 16 && ((**s >= '0') & (**s <= '9'))) |
42 | { | 42 | { |
43 | num[i] = **s; | 43 | num[i] = **s; |
44 | (*s)++; | 44 | (*s)++; |
45 | i++; | 45 | i++; |
46 | } | 46 | } |
47 | 47 | ||
48 | num[i] = '\0'; | 48 | num[i] = '\0'; |
49 | 49 | ||
@@ -53,7 +53,7 @@ parse_version_number (const char **s) | |||
53 | const char * | 53 | const char * |
54 | parse_version_string (const char *s, int *major, int *minor, int *micro) | 54 | parse_version_string (const char *s, int *major, int *minor, int *micro) |
55 | { | 55 | { |
56 | if (!s) | 56 | if (! s) |
57 | return NULL; | 57 | return NULL; |
58 | *major = parse_version_number (&s); | 58 | *major = parse_version_number (&s); |
59 | if (*s != '.') | 59 | if (*s != '.') |
@@ -69,9 +69,9 @@ parse_version_string (const char *s, int *major, int *minor, int *micro) | |||
69 | 69 | ||
70 | #ifdef HTTPS_SUPPORT | 70 | #ifdef HTTPS_SUPPORT |
71 | int | 71 | int |
72 | curl_uses_nss_ssl() | 72 | curl_uses_nss_ssl () |
73 | { | 73 | { |
74 | return (strstr(curl_version(), " NSS/") != NULL) ? 0 : -1; | 74 | return (strstr (curl_version (), " NSS/") != NULL) ? 0 : -1; |
75 | } | 75 | } |
76 | #endif /* HTTPS_SUPPORT */ | 76 | #endif /* HTTPS_SUPPORT */ |
77 | 77 | ||
@@ -105,23 +105,25 @@ curl_check_version (const char *req_version) | |||
105 | return -1; | 105 | return -1; |
106 | curl_ver++; | 106 | curl_ver++; |
107 | /* Parse version numbers */ | 107 | /* Parse version numbers */ |
108 | if ( (NULL == parse_version_string (req_version, &rq_major, &rq_minor, &rq_micro)) || | 108 | if ( (NULL == parse_version_string (req_version, &rq_major, &rq_minor, |
109 | (NULL == parse_version_string (curl_ver, &loc_major, &loc_minor, &loc_micro)) ) | 109 | &rq_micro)) || |
110 | (NULL == parse_version_string (curl_ver, &loc_major, &loc_minor, | ||
111 | &loc_micro)) ) | ||
110 | return -1; | 112 | return -1; |
111 | 113 | ||
112 | /* Compare version numbers. */ | 114 | /* Compare version numbers. */ |
113 | if ((loc_major > rq_major | 115 | if (((loc_major > rq_major) |
114 | || (loc_major == rq_major && loc_minor > rq_minor) | 116 | || ((loc_major == rq_major)&&(loc_minor > rq_minor)) |
115 | || (loc_major == rq_major && loc_minor == rq_minor | 117 | || ((loc_major == rq_major)&&(loc_minor == rq_minor) |
116 | && loc_micro > rq_micro) || (loc_major == rq_major | 118 | &&(loc_micro > rq_micro)) || ((loc_major == rq_major) |
117 | && loc_minor == rq_minor | 119 | &&(loc_minor == rq_minor) |
118 | && loc_micro == rq_micro)) == 0) | 120 | &&(loc_micro == rq_micro) )) == 0) |
119 | { | 121 | { |
120 | fprintf (stderr, | 122 | fprintf (stderr, |
121 | "Error: running curl test depends on local libcurl version > %s\n", | 123 | "Error: running curl test depends on local libcurl version > %s\n", |
122 | req_version); | 124 | req_version); |
123 | return -1; | 125 | return -1; |
124 | } | 126 | } |
125 | 127 | ||
126 | /* | 128 | /* |
127 | * enforce required gnutls/openssl version. | 129 | * enforce required gnutls/openssl version. |
@@ -133,44 +135,46 @@ curl_check_version (const char *req_version) | |||
133 | return -1; | 135 | return -1; |
134 | ssl_ver++; | 136 | ssl_ver++; |
135 | if (strncmp ("GnuTLS", ssl_ver, strlen ("GNUtls")) == 0) | 137 | if (strncmp ("GnuTLS", ssl_ver, strlen ("GNUtls")) == 0) |
136 | { | 138 | { |
137 | ssl_ver = strchr (ssl_ver, '/'); | 139 | ssl_ver = strchr (ssl_ver, '/'); |
138 | req_ssl_ver = MHD_REQ_CURL_GNUTLS_VERSION; | 140 | req_ssl_ver = MHD_REQ_CURL_GNUTLS_VERSION; |
139 | } | 141 | } |
140 | else if (strncmp ("OpenSSL", ssl_ver, strlen ("OpenSSL")) == 0) | 142 | else if (strncmp ("OpenSSL", ssl_ver, strlen ("OpenSSL")) == 0) |
141 | { | 143 | { |
142 | ssl_ver = strchr (ssl_ver, '/'); | 144 | ssl_ver = strchr (ssl_ver, '/'); |
143 | req_ssl_ver = MHD_REQ_CURL_OPENSSL_VERSION; | 145 | req_ssl_ver = MHD_REQ_CURL_OPENSSL_VERSION; |
144 | } | 146 | } |
145 | else if (strncmp ("NSS", ssl_ver, strlen ("NSS")) == 0) | 147 | else if (strncmp ("NSS", ssl_ver, strlen ("NSS")) == 0) |
146 | { | 148 | { |
147 | ssl_ver = strchr (ssl_ver, '/'); | 149 | ssl_ver = strchr (ssl_ver, '/'); |
148 | req_ssl_ver = MHD_REQ_CURL_NSS_VERSION; | 150 | req_ssl_ver = MHD_REQ_CURL_NSS_VERSION; |
149 | } | 151 | } |
150 | else | 152 | else |
151 | { | 153 | { |
152 | fprintf (stderr, "Error: unrecognized curl ssl library\n"); | 154 | fprintf (stderr, "Error: unrecognized curl ssl library\n"); |
153 | return -1; | 155 | return -1; |
154 | } | 156 | } |
155 | if (ssl_ver == NULL) | 157 | if (ssl_ver == NULL) |
156 | return -1; | 158 | return -1; |
157 | ssl_ver++; | 159 | ssl_ver++; |
158 | if ( (NULL == parse_version_string (req_ssl_ver, &rq_major, &rq_minor, &rq_micro)) || | 160 | if ( (NULL == parse_version_string (req_ssl_ver, &rq_major, &rq_minor, |
159 | (NULL == parse_version_string (ssl_ver, &loc_major, &loc_minor, &loc_micro)) ) | 161 | &rq_micro)) || |
162 | (NULL == parse_version_string (ssl_ver, &loc_major, &loc_minor, | ||
163 | &loc_micro)) ) | ||
160 | return -1; | 164 | return -1; |
161 | 165 | ||
162 | if ((loc_major > rq_major | 166 | if (((loc_major > rq_major) |
163 | || (loc_major == rq_major && loc_minor > rq_minor) | 167 | || ((loc_major == rq_major)&&(loc_minor > rq_minor)) |
164 | || (loc_major == rq_major && loc_minor == rq_minor | 168 | || ((loc_major == rq_major)&&(loc_minor == rq_minor) |
165 | && loc_micro > rq_micro) || (loc_major == rq_major | 169 | &&(loc_micro > rq_micro)) || ((loc_major == rq_major) |
166 | && loc_minor == rq_minor | 170 | &&(loc_minor == rq_minor) |
167 | && loc_micro == rq_micro)) == 0) | 171 | &&(loc_micro == rq_micro) )) == 0) |
168 | { | 172 | { |
169 | fprintf (stderr, | 173 | fprintf (stderr, |
170 | "Error: running curl test depends on local libcurl SSL version > %s\n", | 174 | "Error: running curl test depends on local libcurl SSL version > %s\n", |
171 | req_ssl_ver); | 175 | req_ssl_ver); |
172 | return -1; | 176 | return -1; |
173 | } | 177 | } |
174 | #endif /* HTTPS_SUPPORT */ | 178 | #endif /* HTTPS_SUPPORT */ |
175 | return 0; | 179 | return 0; |
176 | } | 180 | } |
diff --git a/src/testcurl/gauger.h b/src/testcurl/gauger.h index 6698f5d5..d00839c1 100644 --- a/src/testcurl/gauger.h +++ b/src/testcurl/gauger.h | |||
@@ -17,64 +17,64 @@ | |||
17 | #include <stdio.h> | 17 | #include <stdio.h> |
18 | #include <sys/wait.h> | 18 | #include <sys/wait.h> |
19 | 19 | ||
20 | #define GAUGER(category, counter, value, unit)\ | 20 | #define GAUGER(category, counter, value, unit) \ |
21 | {\ | 21 | { \ |
22 | const char * __gauger_v[10]; \ | 22 | const char *__gauger_v[10]; \ |
23 | char __gauger_s[32];\ | 23 | char __gauger_s[32]; \ |
24 | pid_t __gauger_p;\ | 24 | pid_t __gauger_p; \ |
25 | if(!(__gauger_p=fork())){\ | 25 | if (! (__gauger_p = fork ())) { \ |
26 | if(!fork()){ \ | 26 | if (! fork ()) { \ |
27 | sprintf(__gauger_s,"%Lf", (long double) (value));\ | 27 | sprintf (__gauger_s,"%Lf", (long double) (value)); \ |
28 | __gauger_v[0] = "gauger";\ | 28 | __gauger_v[0] = "gauger"; \ |
29 | __gauger_v[1] = "-n";\ | 29 | __gauger_v[1] = "-n"; \ |
30 | __gauger_v[2] = counter; \ | 30 | __gauger_v[2] = counter; \ |
31 | __gauger_v[3] = "-d";\ | 31 | __gauger_v[3] = "-d"; \ |
32 | __gauger_v[4] = __gauger_s;\ | 32 | __gauger_v[4] = __gauger_s; \ |
33 | __gauger_v[5] = "-u";\ | 33 | __gauger_v[5] = "-u"; \ |
34 | __gauger_v[6] = unit; \ | 34 | __gauger_v[6] = unit; \ |
35 | __gauger_v[7] = "-c";\ | 35 | __gauger_v[7] = "-c"; \ |
36 | __gauger_v[8] = category; \ | 36 | __gauger_v[8] = category; \ |
37 | __gauger_v[9] = (char *)NULL;\ | 37 | __gauger_v[9] = (char *) NULL; \ |
38 | execvp("gauger", (char*const*) __gauger_v); \ | 38 | execvp ("gauger", (char*const*) __gauger_v); \ |
39 | _exit(1);\ | 39 | _exit (1); \ |
40 | }else{\ | 40 | }else{ \ |
41 | _exit(0);\ | 41 | _exit (0); \ |
42 | }\ | 42 | } \ |
43 | }else{\ | 43 | }else{ \ |
44 | waitpid(__gauger_p,NULL,0);\ | 44 | waitpid (__gauger_p,NULL,0); \ |
45 | }\ | 45 | } \ |
46 | } | 46 | } |
47 | 47 | ||
48 | #define GAUGER_ID(category, counter, value, unit, id)\ | 48 | #define GAUGER_ID(category, counter, value, unit, id) \ |
49 | {\ | 49 | { \ |
50 | char* __gauger_v[12];\ | 50 | char*__gauger_v[12]; \ |
51 | char __gauger_s[32];\ | 51 | char __gauger_s[32]; \ |
52 | pid_t __gauger_p;\ | 52 | pid_t __gauger_p; \ |
53 | if(!(__gauger_p=fork())){\ | 53 | if (! (__gauger_p = fork ())) { \ |
54 | if(!fork()){\ | 54 | if (! fork ()) { \ |
55 | sprintf(__gauger_s,"%Lf", (long double) (value));\ | 55 | sprintf (__gauger_s,"%Lf", (long double) (value)); \ |
56 | __gauger_v[0] = "gauger";\ | 56 | __gauger_v[0] = "gauger"; \ |
57 | __gauger_v[1] = "-n";\ | 57 | __gauger_v[1] = "-n"; \ |
58 | __gauger_v[2] = counter;\ | 58 | __gauger_v[2] = counter; \ |
59 | __gauger_v[3] = "-d";\ | 59 | __gauger_v[3] = "-d"; \ |
60 | __gauger_v[4] = __gauger_s;\ | 60 | __gauger_v[4] = __gauger_s; \ |
61 | __gauger_v[5] = "-u";\ | 61 | __gauger_v[5] = "-u"; \ |
62 | __gauger_v[6] = unit;\ | 62 | __gauger_v[6] = unit; \ |
63 | __gauger_v[7] = "-i";\ | 63 | __gauger_v[7] = "-i"; \ |
64 | __gauger_v[8] = id;\ | 64 | __gauger_v[8] = id; \ |
65 | __gauger_v[9] = "-c";\ | 65 | __gauger_v[9] = "-c"; \ |
66 | __gauger_v[10] = category;\ | 66 | __gauger_v[10] = category; \ |
67 | __gauger_v[11] = (char *)NULL;\ | 67 | __gauger_v[11] = (char *) NULL; \ |
68 | execvp("gauger",__gauger_v);\ | 68 | execvp ("gauger",__gauger_v); \ |
69 | perror("gauger");\ | 69 | perror ("gauger"); \ |
70 | _exit(1);\ | 70 | _exit (1); \ |
71 | }else{\ | 71 | }else{ \ |
72 | _exit(0);\ | 72 | _exit (0); \ |
73 | }\ | 73 | } \ |
74 | }else{\ | 74 | }else{ \ |
75 | waitpid(__gauger_p,NULL,0);\ | 75 | waitpid (__gauger_p,NULL,0); \ |
76 | }\ | 76 | } \ |
77 | } | 77 | } |
78 | 78 | ||
79 | #else | 79 | #else |
80 | 80 | ||
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, ©Buffer); | 119 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
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 | |||
220 | main (int argc, char *const *argv) | 226 | main (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 (); |
diff --git a/src/testcurl/https/test_https_get.c b/src/testcurl/https/test_https_get.c index 61c25643..17248bf7 100644 --- a/src/testcurl/https/test_https_get.c +++ b/src/testcurl/https/test_https_get.c | |||
@@ -39,9 +39,9 @@ extern const char srv_signed_key_pem[]; | |||
39 | 39 | ||
40 | /* perform a HTTP GET request via SSL/TLS */ | 40 | /* perform a HTTP GET request via SSL/TLS */ |
41 | static int | 41 | static int |
42 | test_secure_get (FILE * test_fd, | 42 | test_secure_get (FILE *test_fd, |
43 | const char *cipher_suite, | 43 | const char *cipher_suite, |
44 | int proto_version) | 44 | int proto_version) |
45 | { | 45 | { |
46 | int ret; | 46 | int ret; |
47 | struct MHD_Daemon *d; | 47 | struct MHD_Daemon *d; |
@@ -52,26 +52,29 @@ test_secure_get (FILE * test_fd, | |||
52 | else | 52 | else |
53 | port = 3041; | 53 | port = 3041; |
54 | 54 | ||
55 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | | 55 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
56 | MHD_USE_ERROR_LOG, port, | 56 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
57 | | MHD_USE_ERROR_LOG, port, | ||
57 | NULL, NULL, &http_ahc, NULL, | 58 | NULL, NULL, &http_ahc, NULL, |
58 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, | 59 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, |
59 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, | 60 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, |
60 | MHD_OPTION_END); | 61 | MHD_OPTION_END); |
61 | 62 | ||
62 | if (d == NULL) | 63 | if (d == NULL) |
63 | { | 64 | { |
64 | fprintf (stderr, MHD_E_SERVER_INIT); | 65 | fprintf (stderr, MHD_E_SERVER_INIT); |
65 | return -1; | 66 | return -1; |
66 | } | 67 | } |
67 | if (0 == port) | 68 | if (0 == port) |
69 | { | ||
70 | const union MHD_DaemonInfo *dinfo; | ||
71 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
72 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
68 | { | 73 | { |
69 | const union MHD_DaemonInfo *dinfo; | 74 | MHD_stop_daemon (d); return -1; |
70 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
71 | if (NULL == dinfo || 0 == dinfo->port) | ||
72 | { MHD_stop_daemon (d); return -1; } | ||
73 | port = (int)dinfo->port; | ||
74 | } | 75 | } |
76 | port = (int) dinfo->port; | ||
77 | } | ||
75 | 78 | ||
76 | ret = test_https_transfer (test_fd, port, cipher_suite, proto_version); | 79 | ret = test_https_transfer (test_fd, port, cipher_suite, proto_version); |
77 | 80 | ||
@@ -85,7 +88,7 @@ main (int argc, char *const *argv) | |||
85 | { | 88 | { |
86 | unsigned int errorCount = 0; | 89 | unsigned int errorCount = 0; |
87 | const char *aes256_sha_tlsv1 = "AES256-SHA"; | 90 | const char *aes256_sha_tlsv1 = "AES256-SHA"; |
88 | (void)argc; /* Unused. Silent compiler warning. */ | 91 | (void) argc; /* Unused. Silent compiler warning. */ |
89 | 92 | ||
90 | #ifdef MHD_HTTPS_REQUIRE_GRYPT | 93 | #ifdef MHD_HTTPS_REQUIRE_GRYPT |
91 | gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); | 94 | gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); |
@@ -93,19 +96,19 @@ main (int argc, char *const *argv) | |||
93 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 96 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
94 | #endif | 97 | #endif |
95 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 98 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
96 | if (!testsuite_curl_global_init ()) | 99 | if (! testsuite_curl_global_init ()) |
97 | return 99; | 100 | return 99; |
98 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) | 101 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) |
99 | { | 102 | { |
100 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); | 103 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); |
101 | curl_global_cleanup (); | 104 | curl_global_cleanup (); |
102 | return 77; | 105 | return 77; |
103 | } | 106 | } |
104 | 107 | ||
105 | if (curl_uses_nss_ssl() == 0) | 108 | if (curl_uses_nss_ssl () == 0) |
106 | { | 109 | { |
107 | aes256_sha_tlsv1 = "rsa_aes_256_sha"; | 110 | aes256_sha_tlsv1 = "rsa_aes_256_sha"; |
108 | } | 111 | } |
109 | 112 | ||
110 | errorCount += | 113 | errorCount += |
111 | test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1); | 114 | test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1); |
diff --git a/src/testcurl/https/test_https_get_parallel.c b/src/testcurl/https/test_https_get_parallel.c index 27c23173..e4040874 100644 --- a/src/testcurl/https/test_https_get_parallel.c +++ b/src/testcurl/https/test_https_get_parallel.c | |||
@@ -36,10 +36,10 @@ | |||
36 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 36 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
37 | #include "tls_test_common.h" | 37 | #include "tls_test_common.h" |
38 | 38 | ||
39 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 4 | 39 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 4 |
40 | #undef CPU_COUNT | 40 | #undef CPU_COUNT |
41 | #endif | 41 | #endif |
42 | #if !defined(CPU_COUNT) | 42 | #if ! defined(CPU_COUNT) |
43 | #define CPU_COUNT 4 | 43 | #define CPU_COUNT 4 |
44 | #endif | 44 | #endif |
45 | 45 | ||
@@ -83,8 +83,8 @@ test_single_client (void *cls, int port, const char *cipher_suite, | |||
83 | { | 83 | { |
84 | void *client_thread_ret; | 84 | void *client_thread_ret; |
85 | struct https_test_data client_args = | 85 | struct https_test_data client_args = |
86 | { NULL, port, cipher_suite, curl_proto_version }; | 86 | { NULL, port, cipher_suite, curl_proto_version }; |
87 | (void)cls; /* Unused. Silent compiler warning. */ | 87 | (void) cls; /* Unused. Silent compiler warning. */ |
88 | 88 | ||
89 | client_thread_ret = https_transfer_thread_adapter (&client_args); | 89 | client_thread_ret = https_transfer_thread_adapter (&client_args); |
90 | if (client_thread_ret != NULL) | 90 | if (client_thread_ret != NULL) |
@@ -101,7 +101,7 @@ test_single_client (void *cls, int port, const char *cipher_suite, | |||
101 | * TODO : make client_count a parameter - numver of curl client threads to spawn | 101 | * TODO : make client_count a parameter - numver of curl client threads to spawn |
102 | */ | 102 | */ |
103 | static int | 103 | static int |
104 | test_parallel_clients (void * cls, int port, const char *cipher_suite, | 104 | test_parallel_clients (void *cls, int port, const char *cipher_suite, |
105 | int curl_proto_version) | 105 | int curl_proto_version) |
106 | { | 106 | { |
107 | int i; | 107 | int i; |
@@ -109,26 +109,26 @@ test_parallel_clients (void * cls, int port, const char *cipher_suite, | |||
109 | void *client_thread_ret; | 109 | void *client_thread_ret; |
110 | pthread_t client_arr[client_count]; | 110 | pthread_t client_arr[client_count]; |
111 | struct https_test_data client_args = | 111 | struct https_test_data client_args = |
112 | { NULL, port, cipher_suite, curl_proto_version }; | 112 | { NULL, port, cipher_suite, curl_proto_version }; |
113 | (void)cls; /* Unused. Silent compiler warning. */ | 113 | (void) cls; /* Unused. Silent compiler warning. */ |
114 | 114 | ||
115 | for (i = 0; i < client_count; ++i) | 115 | for (i = 0; i < client_count; ++i) |
116 | { | ||
117 | if (pthread_create (&client_arr[i], NULL, | ||
118 | &https_transfer_thread_adapter, &client_args) != 0) | ||
116 | { | 119 | { |
117 | if (pthread_create (&client_arr[i], NULL, | 120 | fprintf (stderr, "Error: failed to spawn test client threads.\n"); |
118 | &https_transfer_thread_adapter, &client_args) != 0) | 121 | return -1; |
119 | { | ||
120 | fprintf (stderr, "Error: failed to spawn test client threads.\n"); | ||
121 | return -1; | ||
122 | } | ||
123 | } | 122 | } |
123 | } | ||
124 | 124 | ||
125 | /* check all client requests fulfilled correctly */ | 125 | /* check all client requests fulfilled correctly */ |
126 | for (i = 0; i < client_count; ++i) | 126 | for (i = 0; i < client_count; ++i) |
127 | { | 127 | { |
128 | if ((pthread_join (client_arr[i], &client_thread_ret) != 0) || | 128 | if ((pthread_join (client_arr[i], &client_thread_ret) != 0) || |
129 | (client_thread_ret != NULL)) | 129 | (client_thread_ret != NULL)) |
130 | return -1; | 130 | return -1; |
131 | } | 131 | } |
132 | 132 | ||
133 | return 0; | 133 | return 0; |
134 | } | 134 | } |
@@ -136,11 +136,11 @@ test_parallel_clients (void * cls, int port, const char *cipher_suite, | |||
136 | 136 | ||
137 | int | 137 | int |
138 | main (int argc, char *const *argv) | 138 | main (int argc, char *const *argv) |
139 | { | 139 | { |
140 | unsigned int errorCount = 0; | 140 | unsigned int errorCount = 0; |
141 | const char *aes256_sha = "AES256-SHA"; | 141 | const char *aes256_sha = "AES256-SHA"; |
142 | int port; | 142 | int port; |
143 | (void)argc; /* Unused. Silent compiler warning. */ | 143 | (void) argc; /* Unused. Silent compiler warning. */ |
144 | 144 | ||
145 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 145 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
146 | port = 0; | 146 | port = 0; |
@@ -150,21 +150,23 @@ main (int argc, char *const *argv) | |||
150 | /* initialize random seed used by curl clients */ | 150 | /* initialize random seed used by curl clients */ |
151 | unsigned int iseed = (unsigned int) time (NULL); | 151 | unsigned int iseed = (unsigned int) time (NULL); |
152 | srand (iseed); | 152 | srand (iseed); |
153 | if (!testsuite_curl_global_init ()) | 153 | if (! testsuite_curl_global_init ()) |
154 | return 99; | 154 | return 99; |
155 | 155 | ||
156 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) | 156 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) |
157 | { | 157 | { |
158 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); | 158 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); |
159 | return 77; | 159 | return 77; |
160 | } | 160 | } |
161 | if (curl_uses_nss_ssl() == 0) | 161 | if (curl_uses_nss_ssl () == 0) |
162 | aes256_sha = "rsa_aes_256_sha"; | 162 | aes256_sha = "rsa_aes_256_sha"; |
163 | #ifdef EPOLL_SUPPORT | 163 | #ifdef EPOLL_SUPPORT |
164 | errorCount += | 164 | errorCount += |
165 | test_wrap ("single threaded daemon, single client, epoll", &test_single_client, | 165 | test_wrap ("single threaded daemon, single client, epoll", |
166 | &test_single_client, | ||
166 | NULL, port, | 167 | NULL, port, |
167 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_EPOLL, | 168 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
169 | | MHD_USE_ERROR_LOG | MHD_USE_EPOLL, | ||
168 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, | 170 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, |
169 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, | 171 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, |
170 | srv_self_signed_cert_pem, MHD_OPTION_END); | 172 | srv_self_signed_cert_pem, MHD_OPTION_END); |
@@ -172,7 +174,8 @@ main (int argc, char *const *argv) | |||
172 | errorCount += | 174 | errorCount += |
173 | test_wrap ("single threaded daemon, single client", &test_single_client, | 175 | test_wrap ("single threaded daemon, single client", &test_single_client, |
174 | NULL, port, | 176 | NULL, port, |
175 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG, | 177 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
178 | | MHD_USE_ERROR_LOG, | ||
176 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, | 179 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, |
177 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, | 180 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, |
178 | srv_self_signed_cert_pem, MHD_OPTION_END); | 181 | srv_self_signed_cert_pem, MHD_OPTION_END); |
@@ -180,7 +183,8 @@ main (int argc, char *const *argv) | |||
180 | errorCount += | 183 | errorCount += |
181 | test_wrap ("single threaded daemon, parallel clients, epoll", | 184 | test_wrap ("single threaded daemon, parallel clients, epoll", |
182 | &test_parallel_clients, NULL, port, | 185 | &test_parallel_clients, NULL, port, |
183 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_EPOLL, | 186 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
187 | | MHD_USE_ERROR_LOG | MHD_USE_EPOLL, | ||
184 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, | 188 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, |
185 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, | 189 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, |
186 | srv_self_signed_cert_pem, MHD_OPTION_END); | 190 | srv_self_signed_cert_pem, MHD_OPTION_END); |
@@ -188,7 +192,8 @@ main (int argc, char *const *argv) | |||
188 | errorCount += | 192 | errorCount += |
189 | test_wrap ("single threaded daemon, parallel clients", | 193 | test_wrap ("single threaded daemon, parallel clients", |
190 | &test_parallel_clients, NULL, port, | 194 | &test_parallel_clients, NULL, port, |
191 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG, | 195 | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
196 | | MHD_USE_ERROR_LOG, | ||
192 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, | 197 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, |
193 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, | 198 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, |
194 | srv_self_signed_cert_pem, MHD_OPTION_END); | 199 | srv_self_signed_cert_pem, MHD_OPTION_END); |
diff --git a/src/testcurl/https/test_https_get_parallel_threads.c b/src/testcurl/https/test_https_get_parallel_threads.c index c9fc8ffc..8ca976c2 100644 --- a/src/testcurl/https/test_https_get_parallel_threads.c +++ b/src/testcurl/https/test_https_get_parallel_threads.c | |||
@@ -38,10 +38,10 @@ | |||
38 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 38 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
39 | #include "tls_test_common.h" | 39 | #include "tls_test_common.h" |
40 | 40 | ||
41 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 4 | 41 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 4 |
42 | #undef CPU_COUNT | 42 | #undef CPU_COUNT |
43 | #endif | 43 | #endif |
44 | #if !defined(CPU_COUNT) | 44 | #if ! defined(CPU_COUNT) |
45 | #define CPU_COUNT 4 | 45 | #define CPU_COUNT 4 |
46 | #endif | 46 | #endif |
47 | 47 | ||
@@ -83,8 +83,8 @@ test_single_client (void *cls, int port, const char *cipher_suite, | |||
83 | { | 83 | { |
84 | void *client_thread_ret; | 84 | void *client_thread_ret; |
85 | struct https_test_data client_args = | 85 | struct https_test_data client_args = |
86 | { NULL, port, cipher_suite, curl_proto_version }; | 86 | { NULL, port, cipher_suite, curl_proto_version }; |
87 | (void)cls; /* Unused. Silent compiler warning. */ | 87 | (void) cls; /* Unused. Silent compiler warning. */ |
88 | 88 | ||
89 | client_thread_ret = https_transfer_thread_adapter (&client_args); | 89 | client_thread_ret = https_transfer_thread_adapter (&client_args); |
90 | if (client_thread_ret != NULL) | 90 | if (client_thread_ret != NULL) |
@@ -109,27 +109,27 @@ test_parallel_clients (void *cls, int port, const char *cipher_suite, | |||
109 | void *client_thread_ret; | 109 | void *client_thread_ret; |
110 | pthread_t client_arr[client_count]; | 110 | pthread_t client_arr[client_count]; |
111 | struct https_test_data client_args = | 111 | struct https_test_data client_args = |
112 | { NULL, port, cipher_suite, curl_proto_version }; | 112 | { NULL, port, cipher_suite, curl_proto_version }; |
113 | (void)cls; /* Unused. Silent compiler warning. */ | 113 | (void) cls; /* Unused. Silent compiler warning. */ |
114 | 114 | ||
115 | for (i = 0; i < client_count; ++i) | 115 | for (i = 0; i < client_count; ++i) |
116 | { | ||
117 | if (pthread_create (&client_arr[i], NULL, | ||
118 | &https_transfer_thread_adapter, &client_args) != 0) | ||
116 | { | 119 | { |
117 | if (pthread_create (&client_arr[i], NULL, | 120 | fprintf (stderr, "Error: failed to spawn test client threads.\n"); |
118 | &https_transfer_thread_adapter, &client_args) != 0) | ||
119 | { | ||
120 | fprintf (stderr, "Error: failed to spawn test client threads.\n"); | ||
121 | 121 | ||
122 | return -1; | 122 | return -1; |
123 | } | ||
124 | } | 123 | } |
124 | } | ||
125 | 125 | ||
126 | /* check all client requests fulfilled correctly */ | 126 | /* check all client requests fulfilled correctly */ |
127 | for (i = 0; i < client_count; ++i) | 127 | for (i = 0; i < client_count; ++i) |
128 | { | 128 | { |
129 | if ((pthread_join (client_arr[i], &client_thread_ret) != 0) || | 129 | if ((pthread_join (client_arr[i], &client_thread_ret) != 0) || |
130 | (client_thread_ret != NULL)) | 130 | (client_thread_ret != NULL)) |
131 | return -1; | 131 | return -1; |
132 | } | 132 | } |
133 | 133 | ||
134 | return 0; | 134 | return 0; |
135 | } | 135 | } |
@@ -141,7 +141,7 @@ main (int argc, char *const *argv) | |||
141 | unsigned int errorCount = 0; | 141 | unsigned int errorCount = 0; |
142 | const char *ssl_version; | 142 | const char *ssl_version; |
143 | int port; | 143 | int port; |
144 | (void)argc; /* Unused. Silent compiler warning. */ | 144 | (void) argc; /* Unused. Silent compiler warning. */ |
145 | 145 | ||
146 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 146 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
147 | port = 0; | 147 | port = 0; |
@@ -157,32 +157,33 @@ main (int argc, char *const *argv) | |||
157 | #endif | 157 | #endif |
158 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 158 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
159 | srand (iseed); | 159 | srand (iseed); |
160 | if (!testsuite_curl_global_init ()) | 160 | if (! testsuite_curl_global_init ()) |
161 | return 99; | 161 | return 99; |
162 | ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; | 162 | ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; |
163 | if (NULL == ssl_version) | 163 | if (NULL == ssl_version) |
164 | { | 164 | { |
165 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); | 165 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); |
166 | curl_global_cleanup (); | 166 | curl_global_cleanup (); |
167 | return 77; | 167 | return 77; |
168 | } | 168 | } |
169 | if (0 != strncmp (ssl_version, "GnuTLS", 6)) | 169 | if (0 != strncmp (ssl_version, "GnuTLS", 6)) |
170 | { | 170 | { |
171 | fprintf (stderr, "This test can be run only with libcurl-gnutls.\n"); | 171 | fprintf (stderr, "This test can be run only with libcurl-gnutls.\n"); |
172 | curl_global_cleanup (); | 172 | curl_global_cleanup (); |
173 | return 77; | 173 | return 77; |
174 | } | 174 | } |
175 | 175 | ||
176 | char *aes256_sha = "AES256-SHA"; | 176 | char *aes256_sha = "AES256-SHA"; |
177 | if (curl_uses_nss_ssl() == 0) | 177 | if (curl_uses_nss_ssl () == 0) |
178 | { | 178 | { |
179 | aes256_sha = "rsa_aes_256_sha"; | 179 | aes256_sha = "rsa_aes_256_sha"; |
180 | } | 180 | } |
181 | 181 | ||
182 | errorCount += | 182 | errorCount += |
183 | test_wrap ("multi threaded daemon, single client", &test_single_client, | 183 | test_wrap ("multi threaded daemon, single client", &test_single_client, |
184 | NULL, port, | 184 | NULL, port, |
185 | MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, | 185 | MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION |
186 | | MHD_USE_INTERNAL_POLLING_THREAD, | ||
186 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, | 187 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, |
187 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, | 188 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, |
188 | srv_self_signed_cert_pem, MHD_OPTION_END); | 189 | srv_self_signed_cert_pem, MHD_OPTION_END); |
@@ -190,7 +191,8 @@ main (int argc, char *const *argv) | |||
190 | errorCount += | 191 | errorCount += |
191 | test_wrap ("multi threaded daemon, parallel client", | 192 | test_wrap ("multi threaded daemon, parallel client", |
192 | &test_parallel_clients, NULL, port, | 193 | &test_parallel_clients, NULL, port, |
193 | MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, | 194 | MHD_USE_TLS | MHD_USE_ERROR_LOG | MHD_USE_THREAD_PER_CONNECTION |
195 | | MHD_USE_INTERNAL_POLLING_THREAD, | ||
194 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, | 196 | aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, |
195 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, | 197 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, |
196 | srv_self_signed_cert_pem, MHD_OPTION_END); | 198 | srv_self_signed_cert_pem, MHD_OPTION_END); |
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, ©Buffer); | 134 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
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 | |||
248 | main (int argc, char *const *argv) | 253 | main (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); |
diff --git a/src/testcurl/https/test_https_multi_daemon.c b/src/testcurl/https/test_https_multi_daemon.c index 130fa9df..de153ff6 100644 --- a/src/testcurl/https/test_https_multi_daemon.c +++ b/src/testcurl/https/test_https_multi_daemon.c | |||
@@ -43,70 +43,74 @@ extern const char srv_self_signed_cert_pem[]; | |||
43 | */ | 43 | */ |
44 | static int | 44 | static int |
45 | test_concurent_daemon_pair (void *cls, | 45 | test_concurent_daemon_pair (void *cls, |
46 | const char *cipher_suite, | 46 | const char *cipher_suite, |
47 | int proto_version) | 47 | int proto_version) |
48 | { | 48 | { |
49 | int ret; | 49 | int ret; |
50 | struct MHD_Daemon *d1; | 50 | struct MHD_Daemon *d1; |
51 | struct MHD_Daemon *d2; | 51 | struct MHD_Daemon *d2; |
52 | int port1, port2; | 52 | int port1, port2; |
53 | (void)cls; /* Unused. Silent compiler warning. */ | 53 | (void) cls; /* Unused. Silent compiler warning. */ |
54 | 54 | ||
55 | 55 | ||
56 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 56 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
57 | port1 = port2 = 0; | 57 | port1 = port2 = 0; |
58 | else | 58 | else |
59 | { | 59 | { |
60 | port1 = 3050; | 60 | port1 = 3050; |
61 | port2 = 3051; | 61 | port2 = 3051; |
62 | } | 62 | } |
63 | 63 | ||
64 | d1 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | | 64 | d1 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
65 | MHD_USE_ERROR_LOG, port1, | 65 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
66 | | MHD_USE_ERROR_LOG, port1, | ||
66 | NULL, NULL, &http_ahc, NULL, | 67 | NULL, NULL, &http_ahc, NULL, |
67 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | 68 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, |
68 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | 69 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, |
69 | MHD_OPTION_END); | 70 | MHD_OPTION_END); |
70 | 71 | ||
71 | if (d1 == NULL) | 72 | if (d1 == NULL) |
72 | { | 73 | { |
73 | fprintf (stderr, MHD_E_SERVER_INIT); | 74 | fprintf (stderr, MHD_E_SERVER_INIT); |
74 | return -1; | 75 | return -1; |
75 | } | 76 | } |
76 | if (0 == port1) | 77 | if (0 == port1) |
78 | { | ||
79 | const union MHD_DaemonInfo *dinfo; | ||
80 | dinfo = MHD_get_daemon_info (d1, MHD_DAEMON_INFO_BIND_PORT); | ||
81 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
77 | { | 82 | { |
78 | const union MHD_DaemonInfo *dinfo; | 83 | MHD_stop_daemon (d1); return -1; |
79 | dinfo = MHD_get_daemon_info (d1, MHD_DAEMON_INFO_BIND_PORT); | ||
80 | if (NULL == dinfo || 0 == dinfo->port) | ||
81 | { MHD_stop_daemon (d1); return -1; } | ||
82 | port1 = (int)dinfo->port; | ||
83 | } | 84 | } |
85 | port1 = (int) dinfo->port; | ||
86 | } | ||
84 | 87 | ||
85 | d2 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | | 88 | d2 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
86 | MHD_USE_ERROR_LOG, port2, | 89 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
90 | | MHD_USE_ERROR_LOG, port2, | ||
87 | NULL, NULL, &http_ahc, NULL, | 91 | NULL, NULL, &http_ahc, NULL, |
88 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | 92 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, |
89 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | 93 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, |
90 | MHD_OPTION_END); | 94 | MHD_OPTION_END); |
91 | 95 | ||
92 | if (d2 == NULL) | 96 | if (d2 == NULL) |
97 | { | ||
98 | MHD_stop_daemon (d1); | ||
99 | fprintf (stderr, MHD_E_SERVER_INIT); | ||
100 | return -1; | ||
101 | } | ||
102 | if (0 == port2) | ||
103 | { | ||
104 | const union MHD_DaemonInfo *dinfo; | ||
105 | dinfo = MHD_get_daemon_info (d2, MHD_DAEMON_INFO_BIND_PORT); | ||
106 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
93 | { | 107 | { |
94 | MHD_stop_daemon (d1); | 108 | MHD_stop_daemon (d1); |
95 | fprintf (stderr, MHD_E_SERVER_INIT); | 109 | MHD_stop_daemon (d2); |
96 | return -1; | 110 | return -1; |
97 | } | 111 | } |
98 | if (0 == port2) | 112 | port2 = (int) dinfo->port; |
99 | { | 113 | } |
100 | const union MHD_DaemonInfo *dinfo; | ||
101 | dinfo = MHD_get_daemon_info (d2, MHD_DAEMON_INFO_BIND_PORT); | ||
102 | if (NULL == dinfo || 0 == dinfo->port) | ||
103 | { | ||
104 | MHD_stop_daemon (d1); | ||
105 | MHD_stop_daemon (d2); | ||
106 | return -1; | ||
107 | } | ||
108 | port2 = (int)dinfo->port; | ||
109 | } | ||
110 | 114 | ||
111 | ret = | 115 | ret = |
112 | test_daemon_get (NULL, cipher_suite, proto_version, port1, 0); | 116 | test_daemon_get (NULL, cipher_suite, proto_version, port1, 0); |
@@ -128,7 +132,7 @@ main (int argc, char *const *argv) | |||
128 | unsigned int errorCount = 0; | 132 | unsigned int errorCount = 0; |
129 | FILE *cert; | 133 | FILE *cert; |
130 | const char *aes256_sha = "AES256-SHA"; | 134 | const char *aes256_sha = "AES256-SHA"; |
131 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 135 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
132 | 136 | ||
133 | #ifdef MHD_HTTPS_REQUIRE_GRYPT | 137 | #ifdef MHD_HTTPS_REQUIRE_GRYPT |
134 | gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); | 138 | gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); |
@@ -136,25 +140,25 @@ main (int argc, char *const *argv) | |||
136 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 140 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
137 | #endif | 141 | #endif |
138 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 142 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
139 | if (!testsuite_curl_global_init ()) | 143 | if (! testsuite_curl_global_init ()) |
140 | return 99; | 144 | return 99; |
141 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) | 145 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) |
142 | { | 146 | { |
143 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); | 147 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); |
144 | curl_global_cleanup (); | 148 | curl_global_cleanup (); |
145 | return 77; | 149 | return 77; |
146 | } | 150 | } |
147 | if ((cert = setup_ca_cert ()) == NULL) | 151 | if ((cert = setup_ca_cert ()) == NULL) |
148 | { | 152 | { |
149 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); | 153 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); |
150 | curl_global_cleanup (); | 154 | curl_global_cleanup (); |
151 | return 99; | 155 | return 99; |
152 | } | 156 | } |
153 | 157 | ||
154 | if (curl_uses_nss_ssl() == 0) | 158 | if (curl_uses_nss_ssl () == 0) |
155 | { | 159 | { |
156 | aes256_sha = "rsa_aes_256_sha"; | 160 | aes256_sha = "rsa_aes_256_sha"; |
157 | } | 161 | } |
158 | 162 | ||
159 | errorCount += | 163 | errorCount += |
160 | test_concurent_daemon_pair (NULL, aes256_sha, CURL_SSLVERSION_TLSv1); | 164 | test_concurent_daemon_pair (NULL, aes256_sha, CURL_SSLVERSION_TLSv1); |
@@ -165,7 +169,7 @@ main (int argc, char *const *argv) | |||
165 | fclose (cert); | 169 | fclose (cert); |
166 | if (0 != remove (ca_cert_file_name)) | 170 | if (0 != remove (ca_cert_file_name)) |
167 | fprintf (stderr, | 171 | fprintf (stderr, |
168 | "Failed to remove `%s'\n", | 172 | "Failed to remove `%s'\n", |
169 | ca_cert_file_name); | 173 | ca_cert_file_name); |
170 | return errorCount != 0 ? 1 : 0; | 174 | return errorCount != 0 ? 1 : 0; |
171 | } | 175 | } |
diff --git a/src/testcurl/https/test_https_session_info.c b/src/testcurl/https/test_https_session_info.c index 45f13981..b692af15 100644 --- a/src/testcurl/https/test_https_session_info.c +++ b/src/testcurl/https/test_https_session_info.c | |||
@@ -49,41 +49,41 @@ query_session_ahc (void *cls, struct MHD_Connection *connection, | |||
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; /* Unused. Silent compiler warning. */ | 53 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
54 | 54 | ||
55 | if (NULL == *ptr) | 55 | if (NULL == *ptr) |
56 | { | 56 | { |
57 | *ptr = (void*)&query_session_ahc; | 57 | *ptr = (void*) &query_session_ahc; |
58 | return MHD_YES; | 58 | return MHD_YES; |
59 | } | 59 | } |
60 | 60 | ||
61 | if (GNUTLS_TLS1_1 != | 61 | if (GNUTLS_TLS1_1 != |
62 | (ret = MHD_get_connection_info | 62 | (ret = MHD_get_connection_info |
63 | (connection, | 63 | (connection, |
64 | MHD_CONNECTION_INFO_PROTOCOL)->protocol)) | 64 | MHD_CONNECTION_INFO_PROTOCOL)->protocol)) |
65 | { | ||
66 | if (GNUTLS_TLS1_2 == ret) | ||
67 | { | ||
68 | /* as usual, TLS implementations sometimes don't | ||
69 | quite do what was asked, just mildly complain... */ | ||
70 | fprintf (stderr, | ||
71 | "Warning: requested TLS 1.1, got TLS 1.2\n"); | ||
72 | } | ||
73 | else | ||
65 | { | 74 | { |
66 | if (GNUTLS_TLS1_2 == ret) | 75 | /* really different version... */ |
67 | { | 76 | fprintf (stderr, |
68 | /* as usual, TLS implementations sometimes don't | 77 | "Error: requested protocol mismatch (wanted %d, got %d)\n", |
69 | quite do what was asked, just mildly complain... */ | 78 | GNUTLS_TLS1_1, |
70 | fprintf (stderr, | 79 | ret); |
71 | "Warning: requested TLS 1.1, got TLS 1.2\n"); | 80 | return -1; |
72 | } | ||
73 | else | ||
74 | { | ||
75 | /* really different version... */ | ||
76 | fprintf (stderr, | ||
77 | "Error: requested protocol mismatch (wanted %d, got %d)\n", | ||
78 | GNUTLS_TLS1_1, | ||
79 | ret); | ||
80 | return -1; | ||
81 | } | ||
82 | } | 81 | } |
82 | } | ||
83 | 83 | ||
84 | response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE), | 84 | response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE), |
85 | (void *) EMPTY_PAGE, | 85 | (void *) EMPTY_PAGE, |
86 | MHD_RESPMEM_PERSISTENT); | 86 | MHD_RESPMEM_PERSISTENT); |
87 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 87 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
88 | MHD_destroy_response (response); | 88 | MHD_destroy_response (response); |
89 | return ret; | 89 | return ret; |
@@ -114,37 +114,38 @@ test_query_session () | |||
114 | cbc.pos = 0; | 114 | cbc.pos = 0; |
115 | 115 | ||
116 | /* setup test */ | 116 | /* setup test */ |
117 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | | 117 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
118 | MHD_USE_ERROR_LOG, port, | 118 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
119 | | MHD_USE_ERROR_LOG, port, | ||
119 | NULL, NULL, &query_session_ahc, NULL, | 120 | NULL, NULL, &query_session_ahc, NULL, |
120 | MHD_OPTION_HTTPS_PRIORITIES, "NORMAL:+ARCFOUR-128", | 121 | MHD_OPTION_HTTPS_PRIORITIES, "NORMAL:+ARCFOUR-128", |
121 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | 122 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, |
122 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | 123 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, |
123 | MHD_OPTION_END); | 124 | MHD_OPTION_END); |
124 | 125 | ||
125 | if (d == NULL) | 126 | if (d == NULL) |
126 | { | 127 | { |
127 | free (cbc.buf); | 128 | free (cbc.buf); |
128 | return 2; | 129 | return 2; |
129 | } | 130 | } |
130 | if (0 == port) | 131 | if (0 == port) |
132 | { | ||
133 | const union MHD_DaemonInfo *dinfo; | ||
134 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
135 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
131 | { | 136 | { |
132 | const union MHD_DaemonInfo *dinfo; | 137 | MHD_stop_daemon (d); |
133 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | 138 | free (cbc.buf); |
134 | if (NULL == dinfo || 0 == dinfo->port) | 139 | return 32; |
135 | { | ||
136 | MHD_stop_daemon (d); | ||
137 | free (cbc.buf); | ||
138 | return 32; | ||
139 | } | ||
140 | port = (int)dinfo->port; | ||
141 | } | 140 | } |
141 | port = (int) dinfo->port; | ||
142 | } | ||
142 | 143 | ||
143 | const char *aes256_sha = "AES256-SHA"; | 144 | const char *aes256_sha = "AES256-SHA"; |
144 | if (curl_uses_nss_ssl() == 0) | 145 | if (curl_uses_nss_ssl () == 0) |
145 | { | 146 | { |
146 | aes256_sha = "rsa_aes_256_sha"; | 147 | aes256_sha = "rsa_aes_256_sha"; |
147 | } | 148 | } |
148 | 149 | ||
149 | gen_test_file_url (url, | 150 | gen_test_file_url (url, |
150 | sizeof (url), | 151 | sizeof (url), |
@@ -172,15 +173,15 @@ test_query_session () | |||
172 | * crashes on my system! */ | 173 | * crashes on my system! */ |
173 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 174 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
174 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 175 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
175 | { | 176 | { |
176 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", | 177 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", |
177 | curl_easy_strerror (errornum)); | 178 | curl_easy_strerror (errornum)); |
178 | 179 | ||
179 | MHD_stop_daemon (d); | 180 | MHD_stop_daemon (d); |
180 | curl_easy_cleanup (c); | 181 | curl_easy_cleanup (c); |
181 | free (cbc.buf); | 182 | free (cbc.buf); |
182 | return -1; | 183 | return -1; |
183 | } | 184 | } |
184 | 185 | ||
185 | curl_easy_cleanup (c); | 186 | curl_easy_cleanup (c); |
186 | MHD_stop_daemon (d); | 187 | MHD_stop_daemon (d); |
@@ -195,7 +196,7 @@ main (int argc, char *const *argv) | |||
195 | #if LIBCURL_VERSION_NUM >= 0x072200 | 196 | #if LIBCURL_VERSION_NUM >= 0x072200 |
196 | unsigned int errorCount = 0; | 197 | unsigned int errorCount = 0; |
197 | const char *ssl_version; | 198 | const char *ssl_version; |
198 | (void)argc; /* Unused. Silent compiler warning. */ | 199 | (void) argc; /* Unused. Silent compiler warning. */ |
199 | 200 | ||
200 | #ifdef MHD_HTTPS_REQUIRE_GRYPT | 201 | #ifdef MHD_HTTPS_REQUIRE_GRYPT |
201 | gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); | 202 | gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); |
@@ -203,7 +204,7 @@ main (int argc, char *const *argv) | |||
203 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 204 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
204 | #endif | 205 | #endif |
205 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 206 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
206 | if (!testsuite_curl_global_init ()) | 207 | if (! testsuite_curl_global_init ()) |
207 | return 99; | 208 | return 99; |
208 | 209 | ||
209 | ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; | 210 | ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; |
diff --git a/src/testcurl/https/test_https_sni.c b/src/testcurl/https/test_https_sni.c index 8af1472b..16576656 100644 --- a/src/testcurl/https/test_https_sni.c +++ b/src/testcurl/https/test_https_sni.c | |||
@@ -60,9 +60,9 @@ static struct Hosts *hosts; | |||
60 | * (This code is largely taken from GnuTLS). | 60 | * (This code is largely taken from GnuTLS). |
61 | */ | 61 | */ |
62 | static void | 62 | static void |
63 | load_keys(const char *hostname, | 63 | load_keys (const char *hostname, |
64 | const char *CERT_FILE, | 64 | const char *CERT_FILE, |
65 | const char *KEY_FILE) | 65 | const char *KEY_FILE) |
66 | { | 66 | { |
67 | int ret; | 67 | int ret; |
68 | gnutls_datum_t data; | 68 | gnutls_datum_t data; |
@@ -77,32 +77,32 @@ load_keys(const char *hostname, | |||
77 | 77 | ||
78 | ret = gnutls_load_file (CERT_FILE, &data); | 78 | ret = gnutls_load_file (CERT_FILE, &data); |
79 | if (ret < 0) | 79 | if (ret < 0) |
80 | { | 80 | { |
81 | fprintf (stderr, | 81 | fprintf (stderr, |
82 | "*** Error loading certificate file %s.\n", | 82 | "*** Error loading certificate file %s.\n", |
83 | CERT_FILE); | 83 | CERT_FILE); |
84 | exit (1); | 84 | exit (1); |
85 | } | 85 | } |
86 | ret = | 86 | ret = |
87 | gnutls_pcert_import_x509_raw (&host->pcrt, &data, GNUTLS_X509_FMT_PEM, | 87 | gnutls_pcert_import_x509_raw (&host->pcrt, &data, GNUTLS_X509_FMT_PEM, |
88 | 0); | 88 | 0); |
89 | if (ret < 0) | 89 | if (ret < 0) |
90 | { | 90 | { |
91 | fprintf (stderr, | 91 | fprintf (stderr, |
92 | "*** Error loading certificate file: %s\n", | 92 | "*** Error loading certificate file: %s\n", |
93 | gnutls_strerror (ret)); | 93 | gnutls_strerror (ret)); |
94 | exit (1); | 94 | exit (1); |
95 | } | 95 | } |
96 | gnutls_free (data.data); | 96 | gnutls_free (data.data); |
97 | 97 | ||
98 | ret = gnutls_load_file (KEY_FILE, &data); | 98 | ret = gnutls_load_file (KEY_FILE, &data); |
99 | if (ret < 0) | 99 | if (ret < 0) |
100 | { | 100 | { |
101 | fprintf (stderr, | 101 | fprintf (stderr, |
102 | "*** Error loading key file %s.\n", | 102 | "*** Error loading key file %s.\n", |
103 | KEY_FILE); | 103 | KEY_FILE); |
104 | exit (1); | 104 | exit (1); |
105 | } | 105 | } |
106 | 106 | ||
107 | gnutls_privkey_init (&host->key); | 107 | gnutls_privkey_init (&host->key); |
108 | ret = | 108 | ret = |
@@ -110,12 +110,12 @@ load_keys(const char *hostname, | |||
110 | &data, GNUTLS_X509_FMT_PEM, | 110 | &data, GNUTLS_X509_FMT_PEM, |
111 | NULL, 0); | 111 | NULL, 0); |
112 | if (ret < 0) | 112 | if (ret < 0) |
113 | { | 113 | { |
114 | fprintf (stderr, | 114 | fprintf (stderr, |
115 | "*** Error loading key file: %s\n", | 115 | "*** Error loading key file: %s\n", |
116 | gnutls_strerror (ret)); | 116 | gnutls_strerror (ret)); |
117 | exit (1); | 117 | exit (1); |
118 | } | 118 | } |
119 | gnutls_free (data.data); | 119 | gnutls_free (data.data); |
120 | } | 120 | } |
121 | 121 | ||
@@ -133,19 +133,19 @@ load_keys(const char *hostname, | |||
133 | */ | 133 | */ |
134 | static int | 134 | static int |
135 | sni_callback (gnutls_session_t session, | 135 | sni_callback (gnutls_session_t session, |
136 | const gnutls_datum_t* req_ca_dn, | 136 | const gnutls_datum_t*req_ca_dn, |
137 | int nreqs, | 137 | int nreqs, |
138 | const gnutls_pk_algorithm_t* pk_algos, | 138 | const gnutls_pk_algorithm_t*pk_algos, |
139 | int pk_algos_length, | 139 | int pk_algos_length, |
140 | gnutls_pcert_st** pcert, | 140 | gnutls_pcert_st**pcert, |
141 | unsigned int *pcert_length, | 141 | unsigned int *pcert_length, |
142 | gnutls_privkey_t * pkey) | 142 | gnutls_privkey_t *pkey) |
143 | { | 143 | { |
144 | char name[256]; | 144 | char name[256]; |
145 | size_t name_len; | 145 | size_t name_len; |
146 | struct Hosts *host; | 146 | struct Hosts *host; |
147 | unsigned int type; | 147 | unsigned int type; |
148 | (void)req_ca_dn;(void)nreqs;(void)pk_algos;(void)pk_algos_length; /* Unused. Silent compiler warning. */ | 148 | (void) req_ca_dn; (void) nreqs; (void) pk_algos; (void) pk_algos_length; /* Unused. Silent compiler warning. */ |
149 | 149 | ||
150 | name_len = sizeof (name); | 150 | name_len = sizeof (name); |
151 | if (GNUTLS_E_SUCCESS != | 151 | if (GNUTLS_E_SUCCESS != |
@@ -159,13 +159,13 @@ sni_callback (gnutls_session_t session, | |||
159 | if (0 == strncmp (name, host->hostname, name_len)) | 159 | if (0 == strncmp (name, host->hostname, name_len)) |
160 | break; | 160 | break; |
161 | if (NULL == host) | 161 | if (NULL == host) |
162 | { | 162 | { |
163 | fprintf (stderr, | 163 | fprintf (stderr, |
164 | "Need certificate for %.*s\n", | 164 | "Need certificate for %.*s\n", |
165 | (int) name_len, | 165 | (int) name_len, |
166 | name); | 166 | name); |
167 | return -1; | 167 | return -1; |
168 | } | 168 | } |
169 | #if 0 | 169 | #if 0 |
170 | fprintf (stderr, | 170 | fprintf (stderr, |
171 | "Returning certificate for %.*s\n", | 171 | "Returning certificate for %.*s\n", |
@@ -192,10 +192,10 @@ do_get (const char *url, int port) | |||
192 | 192 | ||
193 | len = strlen (test_data); | 193 | len = strlen (test_data); |
194 | if (NULL == (cbc.buf = malloc (sizeof (char) * len))) | 194 | if (NULL == (cbc.buf = malloc (sizeof (char) * len))) |
195 | { | 195 | { |
196 | fprintf (stderr, MHD_E_MEM); | 196 | fprintf (stderr, MHD_E_MEM); |
197 | return -1; | 197 | return -1; |
198 | } | 198 | } |
199 | cbc.size = len; | 199 | cbc.size = len; |
200 | cbc.pos = 0; | 200 | cbc.pos = 0; |
201 | 201 | ||
@@ -204,7 +204,7 @@ do_get (const char *url, int port) | |||
204 | curl_easy_setopt (c, CURLOPT_VERBOSE, 1L); | 204 | curl_easy_setopt (c, CURLOPT_VERBOSE, 1L); |
205 | #endif | 205 | #endif |
206 | curl_easy_setopt (c, CURLOPT_URL, url); | 206 | curl_easy_setopt (c, CURLOPT_URL, url); |
207 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 207 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
208 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | 208 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
209 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L); | 209 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L); |
210 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L); | 210 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L); |
@@ -215,9 +215,9 @@ do_get (const char *url, int port) | |||
215 | /* TODO merge into send_curl_req */ | 215 | /* TODO merge into send_curl_req */ |
216 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0L); | 216 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0L); |
217 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 2L); | 217 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 2L); |
218 | sprintf(buf, "host1:%d:127.0.0.1", port); | 218 | sprintf (buf, "host1:%d:127.0.0.1", port); |
219 | dns_info = curl_slist_append (NULL, buf); | 219 | dns_info = curl_slist_append (NULL, buf); |
220 | sprintf(buf, "host2:%d:127.0.0.1", port); | 220 | sprintf (buf, "host2:%d:127.0.0.1", port); |
221 | dns_info = curl_slist_append (dns_info, buf); | 221 | dns_info = curl_slist_append (dns_info, buf); |
222 | curl_easy_setopt (c, CURLOPT_RESOLVE, dns_info); | 222 | curl_easy_setopt (c, CURLOPT_RESOLVE, dns_info); |
223 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 223 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -227,23 +227,23 @@ do_get (const char *url, int port) | |||
227 | crashes on my system! */ | 227 | crashes on my system! */ |
228 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 228 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
229 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 229 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
230 | { | 230 | { |
231 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", | 231 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", |
232 | curl_easy_strerror (errornum)); | 232 | curl_easy_strerror (errornum)); |
233 | curl_easy_cleanup (c); | 233 | curl_easy_cleanup (c); |
234 | free (cbc.buf); | 234 | free (cbc.buf); |
235 | curl_slist_free_all (dns_info); | 235 | curl_slist_free_all (dns_info); |
236 | return errornum; | 236 | return errornum; |
237 | } | 237 | } |
238 | 238 | ||
239 | curl_easy_cleanup (c); | 239 | curl_easy_cleanup (c); |
240 | curl_slist_free_all (dns_info); | 240 | curl_slist_free_all (dns_info); |
241 | if (memcmp (cbc.buf, test_data, len) != 0) | 241 | if (memcmp (cbc.buf, test_data, len) != 0) |
242 | { | 242 | { |
243 | fprintf (stderr, "Error: local file & received file differ.\n"); | 243 | fprintf (stderr, "Error: local file & received file differ.\n"); |
244 | free (cbc.buf); | 244 | free (cbc.buf); |
245 | return -1; | 245 | return -1; |
246 | } | 246 | } |
247 | 247 | ||
248 | free (cbc.buf); | 248 | free (cbc.buf); |
249 | return 0; | 249 | return 0; |
@@ -256,7 +256,7 @@ main (int argc, char *const *argv) | |||
256 | unsigned int error_count = 0; | 256 | unsigned int error_count = 0; |
257 | struct MHD_Daemon *d; | 257 | struct MHD_Daemon *d; |
258 | int port; | 258 | int port; |
259 | (void)argc; /* Unused. Silent compiler warning. */ | 259 | (void) argc; /* Unused. Silent compiler warning. */ |
260 | 260 | ||
261 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 261 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
262 | port = 0; | 262 | port = 0; |
@@ -269,36 +269,40 @@ main (int argc, char *const *argv) | |||
269 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 269 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
270 | #endif | 270 | #endif |
271 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 271 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
272 | if (!testsuite_curl_global_init ()) | 272 | if (! testsuite_curl_global_init ()) |
273 | return 99; | 273 | return 99; |
274 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) | 274 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) |
275 | { | 275 | { |
276 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); | 276 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); |
277 | curl_global_cleanup (); | 277 | curl_global_cleanup (); |
278 | return 77; | 278 | return 77; |
279 | } | 279 | } |
280 | 280 | ||
281 | load_keys ("host1", ABS_SRCDIR "/host1.crt", ABS_SRCDIR "/host1.key"); | 281 | load_keys ("host1", ABS_SRCDIR "/host1.crt", ABS_SRCDIR "/host1.key"); |
282 | load_keys ("host2", ABS_SRCDIR "/host2.crt", ABS_SRCDIR "/host2.key"); | 282 | load_keys ("host2", ABS_SRCDIR "/host2.crt", ABS_SRCDIR "/host2.key"); |
283 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG, | 283 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
284 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | ||
285 | | MHD_USE_ERROR_LOG, | ||
284 | port, | 286 | port, |
285 | NULL, NULL, | 287 | NULL, NULL, |
286 | &http_ahc, NULL, | 288 | &http_ahc, NULL, |
287 | MHD_OPTION_HTTPS_CERT_CALLBACK, &sni_callback, | 289 | MHD_OPTION_HTTPS_CERT_CALLBACK, &sni_callback, |
288 | MHD_OPTION_END); | 290 | MHD_OPTION_END); |
289 | if (d == NULL) | 291 | if (d == NULL) |
290 | { | 292 | { |
291 | fprintf (stderr, MHD_E_SERVER_INIT); | 293 | fprintf (stderr, MHD_E_SERVER_INIT); |
292 | return -1; | 294 | return -1; |
293 | } | 295 | } |
294 | if (0 == port) | 296 | if (0 == port) |
297 | { | ||
298 | const union MHD_DaemonInfo *dinfo; | ||
299 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
300 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
295 | { | 301 | { |
296 | const union MHD_DaemonInfo *dinfo; | 302 | MHD_stop_daemon (d); return -1; |
297 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
298 | if (NULL == dinfo || 0 == dinfo->port) | ||
299 | { MHD_stop_daemon (d); return -1; } | ||
300 | port = (int)dinfo->port; | ||
301 | } | 303 | } |
304 | port = (int) dinfo->port; | ||
305 | } | ||
302 | if (0 != do_get ("https://host1/", port)) | 306 | if (0 != do_get ("https://host1/", port)) |
303 | error_count++; | 307 | error_count++; |
304 | if (0 != do_get ("https://host2/", port)) | 308 | if (0 != do_get ("https://host2/", port)) |
diff --git a/src/testcurl/https/test_https_time_out.c b/src/testcurl/https/test_https_time_out.c index e46923eb..d2f4d92c 100644 --- a/src/testcurl/https/test_https_time_out.c +++ b/src/testcurl/https/test_https_time_out.c | |||
@@ -55,10 +55,10 @@ test_tls_session_time_out (gnutls_session_t session, int port) | |||
55 | 55 | ||
56 | sd = socket (AF_INET, SOCK_STREAM, 0); | 56 | sd = socket (AF_INET, SOCK_STREAM, 0); |
57 | if (sd == MHD_INVALID_SOCKET) | 57 | if (sd == MHD_INVALID_SOCKET) |
58 | { | 58 | { |
59 | fprintf (stderr, "Failed to create socket: %s\n", strerror (errno)); | 59 | fprintf (stderr, "Failed to create socket: %s\n", strerror (errno)); |
60 | return -1; | 60 | return -1; |
61 | } | 61 | } |
62 | 62 | ||
63 | memset (&sa, '\0', sizeof (struct sockaddr_in)); | 63 | memset (&sa, '\0', sizeof (struct sockaddr_in)); |
64 | sa.sin_family = AF_INET; | 64 | sa.sin_family = AF_INET; |
@@ -70,30 +70,30 @@ test_tls_session_time_out (gnutls_session_t session, int port) | |||
70 | ret = connect (sd, (struct sockaddr *) &sa, sizeof (struct sockaddr_in)); | 70 | ret = connect (sd, (struct sockaddr *) &sa, sizeof (struct sockaddr_in)); |
71 | 71 | ||
72 | if (ret < 0) | 72 | if (ret < 0) |
73 | { | 73 | { |
74 | fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT); | 74 | fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT); |
75 | MHD_socket_close_chk_ (sd); | 75 | MHD_socket_close_chk_ (sd); |
76 | return -1; | 76 | return -1; |
77 | } | 77 | } |
78 | 78 | ||
79 | ret = gnutls_handshake (session); | 79 | ret = gnutls_handshake (session); |
80 | if (ret < 0) | 80 | if (ret < 0) |
81 | { | 81 | { |
82 | fprintf (stderr, "Handshake failed\n"); | 82 | fprintf (stderr, "Handshake failed\n"); |
83 | MHD_socket_close_chk_ (sd); | 83 | MHD_socket_close_chk_ (sd); |
84 | return -1; | 84 | return -1; |
85 | } | 85 | } |
86 | 86 | ||
87 | (void)sleep (TIME_OUT + 1); | 87 | (void) sleep (TIME_OUT + 1); |
88 | 88 | ||
89 | /* check that server has closed the connection */ | 89 | /* check that server has closed the connection */ |
90 | /* TODO better RST trigger */ | 90 | /* TODO better RST trigger */ |
91 | if (send (sd, "", 1, 0) == 0) | 91 | if (send (sd, "", 1, 0) == 0) |
92 | { | 92 | { |
93 | fprintf (stderr, "Connection failed to time-out\n"); | 93 | fprintf (stderr, "Connection failed to time-out\n"); |
94 | MHD_socket_close_chk_ (sd); | 94 | MHD_socket_close_chk_ (sd); |
95 | return -1; | 95 | return -1; |
96 | } | 96 | } |
97 | 97 | ||
98 | MHD_socket_close_chk_ (sd); | 98 | MHD_socket_close_chk_ (sd); |
99 | return 0; | 99 | return 0; |
@@ -110,7 +110,7 @@ main (int argc, char *const *argv) | |||
110 | gnutls_datum_t cert; | 110 | gnutls_datum_t cert; |
111 | gnutls_certificate_credentials_t xcred; | 111 | gnutls_certificate_credentials_t xcred; |
112 | int port; | 112 | int port; |
113 | (void)argc; /* Unused. Silent compiler warning. */ | 113 | (void) argc; /* Unused. Silent compiler warning. */ |
114 | 114 | ||
115 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 115 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
116 | port = 0; | 116 | port = 0; |
@@ -126,8 +126,9 @@ main (int argc, char *const *argv) | |||
126 | gnutls_global_init (); | 126 | gnutls_global_init (); |
127 | gnutls_global_set_log_level (11); | 127 | gnutls_global_set_log_level (11); |
128 | 128 | ||
129 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | | 129 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
130 | MHD_USE_ERROR_LOG, port, | 130 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
131 | | MHD_USE_ERROR_LOG, port, | ||
131 | NULL, NULL, &http_dummy_ahc, NULL, | 132 | NULL, NULL, &http_dummy_ahc, NULL, |
132 | MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT, | 133 | MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT, |
133 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | 134 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, |
@@ -135,24 +136,26 @@ main (int argc, char *const *argv) | |||
135 | MHD_OPTION_END); | 136 | MHD_OPTION_END); |
136 | 137 | ||
137 | if (NULL == d) | 138 | if (NULL == d) |
138 | { | 139 | { |
139 | fprintf (stderr, MHD_E_SERVER_INIT); | 140 | fprintf (stderr, MHD_E_SERVER_INIT); |
140 | return -1; | 141 | return -1; |
141 | } | 142 | } |
142 | if (0 == port) | 143 | if (0 == port) |
144 | { | ||
145 | const union MHD_DaemonInfo *dinfo; | ||
146 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
147 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
143 | { | 148 | { |
144 | const union MHD_DaemonInfo *dinfo; | 149 | MHD_stop_daemon (d); return -1; |
145 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
146 | if (NULL == dinfo || 0 == dinfo->port) | ||
147 | { MHD_stop_daemon (d); return -1; } | ||
148 | port = (int)dinfo->port; | ||
149 | } | 150 | } |
151 | port = (int) dinfo->port; | ||
152 | } | ||
150 | 153 | ||
151 | if (0 != setup_session (&session, &key, &cert, &xcred)) | 154 | if (0 != setup_session (&session, &key, &cert, &xcred)) |
152 | { | 155 | { |
153 | fprintf (stderr, "failed to setup session\n"); | 156 | fprintf (stderr, "failed to setup session\n"); |
154 | return 1; | 157 | return 1; |
155 | } | 158 | } |
156 | errorCount += test_tls_session_time_out (session, port); | 159 | errorCount += test_tls_session_time_out (session, port); |
157 | teardown_session (session, &key, &cert, xcred); | 160 | teardown_session (session, &key, &cert, xcred); |
158 | 161 | ||
diff --git a/src/testcurl/https/test_tls_authentication.c b/src/testcurl/https/test_tls_authentication.c index 2ed8f14c..51fb5331 100644 --- a/src/testcurl/https/test_tls_authentication.c +++ b/src/testcurl/https/test_tls_authentication.c | |||
@@ -41,38 +41,41 @@ extern const char srv_signed_key_pem[]; | |||
41 | 41 | ||
42 | /* perform a HTTP GET request via SSL/TLS */ | 42 | /* perform a HTTP GET request via SSL/TLS */ |
43 | static int | 43 | static int |
44 | test_secure_get (void * cls, char *cipher_suite, int proto_version) | 44 | test_secure_get (void *cls, char *cipher_suite, int proto_version) |
45 | { | 45 | { |
46 | int ret; | 46 | int ret; |
47 | struct MHD_Daemon *d; | 47 | struct MHD_Daemon *d; |
48 | int port; | 48 | int port; |
49 | (void)cls; /* Unused. Silent compiler warning. */ | 49 | (void) cls; /* Unused. Silent compiler warning. */ |
50 | 50 | ||
51 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 51 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
52 | port = 0; | 52 | port = 0; |
53 | else | 53 | else |
54 | port = 3070; | 54 | port = 3070; |
55 | 55 | ||
56 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | | 56 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
57 | MHD_USE_ERROR_LOG, port, | 57 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
58 | | MHD_USE_ERROR_LOG, port, | ||
58 | NULL, NULL, &http_ahc, NULL, | 59 | NULL, NULL, &http_ahc, NULL, |
59 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, | 60 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, |
60 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, | 61 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, |
61 | MHD_OPTION_END); | 62 | MHD_OPTION_END); |
62 | 63 | ||
63 | if (d == NULL) | 64 | if (d == NULL) |
64 | { | 65 | { |
65 | fprintf (stderr, MHD_E_SERVER_INIT); | 66 | fprintf (stderr, MHD_E_SERVER_INIT); |
66 | return -1; | 67 | return -1; |
67 | } | 68 | } |
68 | if (0 == port) | 69 | if (0 == port) |
70 | { | ||
71 | const union MHD_DaemonInfo *dinfo; | ||
72 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
73 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
69 | { | 74 | { |
70 | const union MHD_DaemonInfo *dinfo; | 75 | MHD_stop_daemon (d); return -1; |
71 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
72 | if (NULL == dinfo || 0 == dinfo->port) | ||
73 | { MHD_stop_daemon (d); return -1; } | ||
74 | port = (int)dinfo->port; | ||
75 | } | 76 | } |
77 | port = (int) dinfo->port; | ||
78 | } | ||
76 | 79 | ||
77 | ret = test_daemon_get (NULL, cipher_suite, proto_version, port, 0); | 80 | ret = test_daemon_get (NULL, cipher_suite, proto_version, port, 0); |
78 | 81 | ||
@@ -87,8 +90,8 @@ main (int argc, char *const *argv) | |||
87 | unsigned int errorCount = 0; | 90 | unsigned int errorCount = 0; |
88 | char *aes256_sha = "AES256-SHA"; | 91 | char *aes256_sha = "AES256-SHA"; |
89 | FILE *crt; | 92 | FILE *crt; |
90 | (void)argc; | 93 | (void) argc; |
91 | (void)argv; /* Unused. Silent compiler warning. */ | 94 | (void) argv; /* Unused. Silent compiler warning. */ |
92 | 95 | ||
93 | #ifdef MHD_HTTPS_REQUIRE_GRYPT | 96 | #ifdef MHD_HTTPS_REQUIRE_GRYPT |
94 | gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); | 97 | gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); |
@@ -96,26 +99,26 @@ main (int argc, char *const *argv) | |||
96 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 99 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
97 | #endif | 100 | #endif |
98 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 101 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
99 | if (!testsuite_curl_global_init ()) | 102 | if (! testsuite_curl_global_init ()) |
100 | return 99; | 103 | return 99; |
101 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) | 104 | if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) |
102 | { | 105 | { |
103 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); | 106 | fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); |
104 | curl_global_cleanup (); | 107 | curl_global_cleanup (); |
105 | return 77; | 108 | return 77; |
106 | } | 109 | } |
107 | 110 | ||
108 | if (NULL == (crt = setup_ca_cert ())) | 111 | if (NULL == (crt = setup_ca_cert ())) |
109 | { | 112 | { |
110 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); | 113 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); |
111 | curl_global_cleanup (); | 114 | curl_global_cleanup (); |
112 | return 99; | 115 | return 99; |
113 | } | 116 | } |
114 | fclose (crt); | 117 | fclose (crt); |
115 | if (curl_uses_nss_ssl() == 0) | 118 | if (curl_uses_nss_ssl () == 0) |
116 | { | 119 | { |
117 | aes256_sha = "rsa_aes_256_sha"; | 120 | aes256_sha = "rsa_aes_256_sha"; |
118 | } | 121 | } |
119 | 122 | ||
120 | errorCount += | 123 | errorCount += |
121 | test_secure_get (NULL, aes256_sha, CURL_SSLVERSION_TLSv1); | 124 | test_secure_get (NULL, aes256_sha, CURL_SSLVERSION_TLSv1); |
@@ -125,7 +128,7 @@ main (int argc, char *const *argv) | |||
125 | curl_global_cleanup (); | 128 | curl_global_cleanup (); |
126 | if (0 != remove (ca_cert_file_name)) | 129 | if (0 != remove (ca_cert_file_name)) |
127 | fprintf (stderr, | 130 | fprintf (stderr, |
128 | "Failed to remove `%s'\n", | 131 | "Failed to remove `%s'\n", |
129 | ca_cert_file_name); | 132 | ca_cert_file_name); |
130 | return errorCount != 0 ? 1 : 0; | 133 | return errorCount != 0 ? 1 : 0; |
131 | } | 134 | } |
diff --git a/src/testcurl/https/test_tls_extensions.c b/src/testcurl/https/test_tls_extensions.c index 08cde939..f5095359 100644 --- a/src/testcurl/https/test_tls_extensions.c +++ b/src/testcurl/https/test_tls_extensions.c | |||
@@ -69,20 +69,20 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t, | |||
69 | sd = -1; | 69 | sd = -1; |
70 | memset (&cbc, 0, sizeof (struct CBC)); | 70 | memset (&cbc, 0, sizeof (struct CBC)); |
71 | if (NULL == (cbc.buf = malloc (sizeof (char) * 256))) | 71 | if (NULL == (cbc.buf = malloc (sizeof (char) * 256))) |
72 | { | 72 | { |
73 | fprintf (stderr, MHD_E_MEM); | 73 | fprintf (stderr, MHD_E_MEM); |
74 | ret = -1; | 74 | ret = -1; |
75 | goto cleanup; | 75 | goto cleanup; |
76 | } | 76 | } |
77 | cbc.size = 256; | 77 | cbc.size = 256; |
78 | 78 | ||
79 | sd = socket (AF_INET, SOCK_STREAM, 0); | 79 | sd = socket (AF_INET, SOCK_STREAM, 0); |
80 | if (sd == -1) | 80 | if (sd == -1) |
81 | { | 81 | { |
82 | fprintf(stderr, "Failed to create socket: %s\n", strerror(errno)); | 82 | fprintf (stderr, "Failed to create socket: %s\n", strerror (errno)); |
83 | free (cbc.buf); | 83 | free (cbc.buf); |
84 | return -1; | 84 | return -1; |
85 | } | 85 | } |
86 | memset (&sa, '\0', sizeof (struct sockaddr_in)); | 86 | memset (&sa, '\0', sizeof (struct sockaddr_in)); |
87 | sa.sin_family = AF_INET; | 87 | sa.sin_family = AF_INET; |
88 | sa.sin_port = htons (port); | 88 | sa.sin_port = htons (port); |
@@ -101,10 +101,10 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t, | |||
101 | 101 | ||
102 | data = MHD_gnutls_malloc (datalen); | 102 | data = MHD_gnutls_malloc (datalen); |
103 | if (data == NULL) | 103 | if (data == NULL) |
104 | { | 104 | { |
105 | free (cbc.buf); | 105 | free (cbc.buf); |
106 | return -1; | 106 | return -1; |
107 | } | 107 | } |
108 | hver = MHD_gtls_version_max (session); | 108 | hver = MHD_gtls_version_max (session); |
109 | data[pos++] = MHD_gtls_version_get_major (hver); | 109 | data[pos++] = MHD_gtls_version_get_major (hver); |
110 | data[pos++] = MHD_gtls_version_get_minor (hver); | 110 | data[pos++] = MHD_gtls_version_get_minor (hver); |
@@ -119,7 +119,8 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t, | |||
119 | /* generate session client random */ | 119 | /* generate session client random */ |
120 | memset (session->security_parameters.client_random, 0, TLS_RANDOM_SIZE); | 120 | memset (session->security_parameters.client_random, 0, TLS_RANDOM_SIZE); |
121 | gnutls_write_uint32 (time (NULL), rnd); | 121 | gnutls_write_uint32 (time (NULL), rnd); |
122 | if (GC_OK != MHD_gc_nonce ((char *) &rnd[4], TLS_RANDOM_SIZE - 4)) abort (); | 122 | if (GC_OK != MHD_gc_nonce ((char *) &rnd[4], TLS_RANDOM_SIZE - 4)) |
123 | abort (); | ||
123 | memcpy (session->security_parameters.client_random, rnd, TLS_RANDOM_SIZE); | 124 | memcpy (session->security_parameters.client_random, rnd, TLS_RANDOM_SIZE); |
124 | memcpy (&data[pos], rnd, TLS_RANDOM_SIZE); | 125 | memcpy (&data[pos], rnd, TLS_RANDOM_SIZE); |
125 | pos += TLS_RANDOM_SIZE; | 126 | pos += TLS_RANDOM_SIZE; |
@@ -148,37 +149,37 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t, | |||
148 | gnutls_write_uint16 (exten_data_len, &data[pos]); | 149 | gnutls_write_uint16 (exten_data_len, &data[pos]); |
149 | pos += 2; | 150 | pos += 2; |
150 | for (i = 0; i < ext_count; ++i) | 151 | for (i = 0; i < ext_count; ++i) |
151 | { | 152 | { |
152 | /* write extension type */ | 153 | /* write extension type */ |
153 | gnutls_write_uint16 (exten_t, &data[pos]); | 154 | gnutls_write_uint16 (exten_t, &data[pos]); |
154 | pos += 2; | 155 | pos += 2; |
155 | gnutls_write_uint16 (ext_length, &data[pos]); | 156 | gnutls_write_uint16 (ext_length, &data[pos]); |
156 | pos += 2; | 157 | pos += 2; |
157 | /* we might want to generate random data here */ | 158 | /* we might want to generate random data here */ |
158 | memset (&data[pos], 0, ext_length); | 159 | memset (&data[pos], 0, ext_length); |
159 | pos += ext_length; | 160 | pos += ext_length; |
160 | } | 161 | } |
161 | 162 | ||
162 | if (connect (sd, &sa, sizeof (struct sockaddr_in)) < 0) | 163 | if (connect (sd, &sa, sizeof (struct sockaddr_in)) < 0) |
163 | { | 164 | { |
164 | fprintf (stderr, "%s\n", MHD_E_FAILED_TO_CONNECT); | 165 | fprintf (stderr, "%s\n", MHD_E_FAILED_TO_CONNECT); |
165 | ret = -1; | 166 | ret = -1; |
166 | goto cleanup; | 167 | goto cleanup; |
167 | } | 168 | } |
168 | 169 | ||
169 | gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd); | 170 | gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd); |
170 | 171 | ||
171 | if (gen_test_file_url (url, | 172 | if (gen_test_file_url (url, |
172 | sizeof (url), | 173 | sizeof (url), |
173 | port)) | 174 | port)) |
174 | { | 175 | { |
175 | ret = -1; | 176 | ret = -1; |
176 | goto cleanup; | 177 | goto cleanup; |
177 | } | 178 | } |
178 | 179 | ||
179 | /* this should crash the server */ | 180 | /* this should crash the server */ |
180 | ret = gnutls_send_handshake (session, data, datalen, | 181 | ret = gnutls_send_handshake (session, data, datalen, |
181 | GNUTLS_HANDSHAKE_CLIENT_HELLO); | 182 | GNUTLS_HANDSHAKE_CLIENT_HELLO); |
182 | 183 | ||
183 | /* advance to STATE2 */ | 184 | /* advance to STATE2 */ |
184 | session->internals.handshake_state = STATE2; | 185 | session->internals.handshake_state = STATE2; |
@@ -190,10 +191,10 @@ test_hello_extension (gnutls_session_t session, int port, extensions_t exten_t, | |||
190 | /* make sure daemon is still functioning */ | 191 | /* make sure daemon is still functioning */ |
191 | if (CURLE_OK != send_curl_req (url, &cbc, "AES128-SHA", | 192 | if (CURLE_OK != send_curl_req (url, &cbc, "AES128-SHA", |
192 | MHD_GNUTLS_PROTOCOL_TLS1_2)) | 193 | MHD_GNUTLS_PROTOCOL_TLS1_2)) |
193 | { | 194 | { |
194 | ret = -1; | 195 | ret = -1; |
195 | goto cleanup; | 196 | goto cleanup; |
196 | } | 197 | } |
197 | 198 | ||
198 | cleanup: | 199 | cleanup: |
199 | if (-1 != sd) | 200 | if (-1 != sd) |
@@ -233,34 +234,37 @@ main (int argc, char *const *argv) | |||
233 | MHD_gtls_global_set_log_level (11); | 234 | MHD_gtls_global_set_log_level (11); |
234 | 235 | ||
235 | if ((test_fd = setup_test_file ()) == NULL) | 236 | if ((test_fd = setup_test_file ()) == NULL) |
236 | { | 237 | { |
237 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); | 238 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); |
238 | return -1; | 239 | return -1; |
239 | } | 240 | } |
240 | 241 | ||
241 | if (!testsuite_curl_global_init ()) | 242 | if (! testsuite_curl_global_init ()) |
242 | return 99; | 243 | return 99; |
243 | 244 | ||
244 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | | 245 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
245 | MHD_USE_ERROR_LOG, port, | 246 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
247 | | MHD_USE_ERROR_LOG, port, | ||
246 | NULL, NULL, &http_ahc, NULL, | 248 | NULL, NULL, &http_ahc, NULL, |
247 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | 249 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, |
248 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | 250 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, |
249 | MHD_OPTION_END); | 251 | MHD_OPTION_END); |
250 | 252 | ||
251 | if (d == NULL) | 253 | if (d == NULL) |
252 | { | 254 | { |
253 | fprintf (stderr, "%s\n", MHD_E_SERVER_INIT); | 255 | fprintf (stderr, "%s\n", MHD_E_SERVER_INIT); |
254 | return -1; | 256 | return -1; |
255 | } | 257 | } |
256 | if (0 == port) | 258 | if (0 == port) |
259 | { | ||
260 | const union MHD_DaemonInfo *dinfo; | ||
261 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
262 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
257 | { | 263 | { |
258 | const union MHD_DaemonInfo *dinfo; | 264 | MHD_stop_daemon (d); return -1; |
259 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
260 | if (NULL == dinfo || 0 == dinfo->port) | ||
261 | { MHD_stop_daemon (d); return -1; } | ||
262 | port = (int)dinfo->port; | ||
263 | } | 265 | } |
266 | port = (int) dinfo->port; | ||
267 | } | ||
264 | 268 | ||
265 | i = 0; | 269 | i = 0; |
266 | setup_session (&session, &key, &cert, &xcred); | 270 | setup_session (&session, &key, &cert, &xcred); |
@@ -269,21 +273,21 @@ main (int argc, char *const *argv) | |||
269 | #if 1 | 273 | #if 1 |
270 | i = 0; | 274 | i = 0; |
271 | while (ext_arr[i] != -1) | 275 | while (ext_arr[i] != -1) |
272 | { | 276 | { |
273 | setup_session (&session, &key, &cert, &xcred); | 277 | setup_session (&session, &key, &cert, &xcred); |
274 | errorCount += test_hello_extension (session, port, ext_arr[i], 1, 16); | 278 | errorCount += test_hello_extension (session, port, ext_arr[i], 1, 16); |
275 | teardown_session (session, &key, &cert, xcred); | 279 | teardown_session (session, &key, &cert, xcred); |
276 | 280 | ||
277 | setup_session (&session, &key, &cert, &xcred); | 281 | setup_session (&session, &key, &cert, &xcred); |
278 | errorCount += test_hello_extension (session, port, ext_arr[i], 3, 8); | 282 | errorCount += test_hello_extension (session, port, ext_arr[i], 3, 8); |
279 | teardown_session (session, &key, &cert, xcred); | 283 | teardown_session (session, &key, &cert, xcred); |
280 | 284 | ||
281 | /* this test specifically tests the issue raised in CVE-2008-1948 */ | 285 | /* this test specifically tests the issue raised in CVE-2008-1948 */ |
282 | setup_session (&session, &key, &cert, &xcred); | 286 | setup_session (&session, &key, &cert, &xcred); |
283 | errorCount += test_hello_extension (session, port, ext_arr[i], 6, 0); | 287 | errorCount += test_hello_extension (session, port, ext_arr[i], 6, 0); |
284 | teardown_session (session, &key, &cert, xcred); | 288 | teardown_session (session, &key, &cert, xcred); |
285 | i++; | 289 | i++; |
286 | } | 290 | } |
287 | #endif | 291 | #endif |
288 | 292 | ||
289 | print_test_result (errorCount, argv[0]); | 293 | print_test_result (errorCount, argv[0]); |
diff --git a/src/testcurl/https/test_tls_options.c b/src/testcurl/https/test_tls_options.c index 703ae92a..f94834b5 100644 --- a/src/testcurl/https/test_tls_options.c +++ b/src/testcurl/https/test_tls_options.c | |||
@@ -43,17 +43,17 @@ int curl_check_version (const char *req_version, ...); | |||
43 | * | 43 | * |
44 | */ | 44 | */ |
45 | static int | 45 | static int |
46 | test_unmatching_ssl_version (void * cls, int port, const char *cipher_suite, | 46 | test_unmatching_ssl_version (void *cls, int port, const char *cipher_suite, |
47 | int curl_req_ssl_version) | 47 | int curl_req_ssl_version) |
48 | { | 48 | { |
49 | struct CBC cbc; | 49 | struct CBC cbc; |
50 | (void)cls; /* Unused. Silent compiler warning. */ | 50 | (void) cls; /* Unused. Silent compiler warning. */ |
51 | if (NULL == (cbc.buf = malloc (sizeof (char) * 256))) | 51 | if (NULL == (cbc.buf = malloc (sizeof (char) * 256))) |
52 | { | 52 | { |
53 | fprintf (stderr, "Error: failed to allocate: %s\n", | 53 | fprintf (stderr, "Error: failed to allocate: %s\n", |
54 | strerror (errno)); | 54 | strerror (errno)); |
55 | return -1; | 55 | return -1; |
56 | } | 56 | } |
57 | cbc.size = 256; | 57 | cbc.size = 256; |
58 | cbc.pos = 0; | 58 | cbc.pos = 0; |
59 | 59 | ||
@@ -61,21 +61,22 @@ test_unmatching_ssl_version (void * cls, int port, const char *cipher_suite, | |||
61 | if (gen_test_file_url (url, | 61 | if (gen_test_file_url (url, |
62 | sizeof (url), | 62 | sizeof (url), |
63 | port)) | 63 | port)) |
64 | { | 64 | { |
65 | free (cbc.buf); | 65 | free (cbc.buf); |
66 | fprintf (stderr, | 66 | fprintf (stderr, |
67 | "Internal error in gen_test_file_url\n"); | 67 | "Internal error in gen_test_file_url\n"); |
68 | return -1; | 68 | return -1; |
69 | } | 69 | } |
70 | 70 | ||
71 | /* assert daemon *rejected* request */ | 71 | /* assert daemon *rejected* request */ |
72 | if (CURLE_OK == | 72 | if (CURLE_OK == |
73 | send_curl_req (url, &cbc, cipher_suite, curl_req_ssl_version)) | 73 | send_curl_req (url, &cbc, cipher_suite, curl_req_ssl_version)) |
74 | { | 74 | { |
75 | free (cbc.buf); | 75 | free (cbc.buf); |
76 | fprintf (stderr, "cURL failed to reject request despite SSL version mismatch!\n"); | 76 | fprintf (stderr, |
77 | return -1; | 77 | "cURL failed to reject request despite SSL version mismatch!\n"); |
78 | } | 78 | return -1; |
79 | } | ||
79 | 80 | ||
80 | free (cbc.buf); | 81 | free (cbc.buf); |
81 | return 0; | 82 | return 0; |
@@ -89,9 +90,10 @@ main (int argc, char *const *argv) | |||
89 | unsigned int errorCount = 0; | 90 | unsigned int errorCount = 0; |
90 | const char *ssl_version; | 91 | const char *ssl_version; |
91 | int daemon_flags = | 92 | int daemon_flags = |
92 | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG; | 93 | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD |
94 | | MHD_USE_TLS | MHD_USE_ERROR_LOG; | ||
93 | int port; | 95 | int port; |
94 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 96 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
95 | 97 | ||
96 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 98 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
97 | port = 0; | 99 | port = 0; |
@@ -105,10 +107,10 @@ main (int argc, char *const *argv) | |||
105 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 107 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
106 | #endif | 108 | #endif |
107 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 109 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
108 | if (curl_check_version (MHD_REQ_CURL_VERSION)) | 110 | if (curl_check_version (MHD_REQ_CURL_VERSION)) |
109 | { | 111 | { |
110 | return 77; | 112 | return 77; |
111 | } | 113 | } |
112 | ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; | 114 | ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; |
113 | if (NULL == ssl_version) | 115 | if (NULL == ssl_version) |
114 | { | 116 | { |
@@ -121,46 +123,48 @@ main (int argc, char *const *argv) | |||
121 | return 77; | 123 | return 77; |
122 | } | 124 | } |
123 | 125 | ||
124 | if (!testsuite_curl_global_init ()) | 126 | if (! testsuite_curl_global_init ()) |
125 | return 99; | 127 | return 99; |
126 | 128 | ||
127 | const char *aes128_sha = "AES128-SHA"; | 129 | const char *aes128_sha = "AES128-SHA"; |
128 | const char *aes256_sha = "AES256-SHA"; | 130 | const char *aes256_sha = "AES256-SHA"; |
129 | if (curl_uses_nss_ssl() == 0) | 131 | if (curl_uses_nss_ssl () == 0) |
130 | { | 132 | { |
131 | aes128_sha = "rsa_aes_128_sha"; | 133 | aes128_sha = "rsa_aes_128_sha"; |
132 | aes256_sha = "rsa_aes_256_sha"; | 134 | aes256_sha = "rsa_aes_256_sha"; |
133 | } | 135 | } |
134 | 136 | ||
135 | 137 | ||
136 | if (0 != | 138 | if (0 != |
137 | test_wrap ("TLS1.0-AES-SHA1", | 139 | test_wrap ("TLS1.0-AES-SHA1", |
138 | &test_https_transfer, NULL, port, daemon_flags, | 140 | &test_https_transfer, NULL, port, daemon_flags, |
139 | aes128_sha, | 141 | aes128_sha, |
140 | CURL_SSLVERSION_TLSv1, | 142 | CURL_SSLVERSION_TLSv1, |
141 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | 143 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, |
142 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | 144 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, |
143 | MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL", | 145 | MHD_OPTION_HTTPS_PRIORITIES, |
144 | MHD_OPTION_END)) | 146 | "NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL", |
145 | { | 147 | MHD_OPTION_END)) |
146 | fprintf (stderr, "TLS1.0-AES-SHA1 test failed\n"); | 148 | { |
147 | errorCount++; | 149 | fprintf (stderr, "TLS1.0-AES-SHA1 test failed\n"); |
148 | } | 150 | errorCount++; |
151 | } | ||
149 | fprintf (stderr, | 152 | fprintf (stderr, |
150 | "The following handshake should fail (and print an error message)...\n"); | 153 | "The following handshake should fail (and print an error message)...\n"); |
151 | if (0 != | 154 | if (0 != |
152 | test_wrap ("TLS1.0 vs SSL3", | 155 | test_wrap ("TLS1.0 vs SSL3", |
153 | &test_unmatching_ssl_version, NULL, port, daemon_flags, | 156 | &test_unmatching_ssl_version, NULL, port, daemon_flags, |
154 | aes256_sha, | 157 | aes256_sha, |
155 | CURL_SSLVERSION_SSLv3, | 158 | CURL_SSLVERSION_SSLv3, |
156 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | 159 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, |
157 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | 160 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, |
158 | MHD_OPTION_HTTPS_PRIORITIES, "NONE:+VERS-TLS1.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL", | 161 | MHD_OPTION_HTTPS_PRIORITIES, |
159 | MHD_OPTION_END)) | 162 | "NONE:+VERS-TLS1.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL", |
160 | { | 163 | MHD_OPTION_END)) |
161 | fprintf (stderr, "TLS1.0 vs SSL3 test failed\n"); | 164 | { |
162 | errorCount++; | 165 | fprintf (stderr, "TLS1.0 vs SSL3 test failed\n"); |
163 | } | 166 | errorCount++; |
167 | } | ||
164 | curl_global_cleanup (); | 168 | curl_global_cleanup (); |
165 | 169 | ||
166 | return errorCount != 0 ? 1 : 0; | 170 | return errorCount != 0 ? 1 : 0; |
diff --git a/src/testcurl/https/tls_test_common.c b/src/testcurl/https/tls_test_common.c index 367bed00..eb7cb14c 100644 --- a/src/testcurl/https/tls_test_common.c +++ b/src/testcurl/https/tls_test_common.c | |||
@@ -33,26 +33,26 @@ setup_ca_cert () | |||
33 | FILE *cert_fd; | 33 | FILE *cert_fd; |
34 | 34 | ||
35 | if (NULL == (cert_fd = fopen (ca_cert_file_name, "wb+"))) | 35 | if (NULL == (cert_fd = fopen (ca_cert_file_name, "wb+"))) |
36 | { | 36 | { |
37 | fprintf (stderr, "Error: failed to open `%s': %s\n", | 37 | fprintf (stderr, "Error: failed to open `%s': %s\n", |
38 | ca_cert_file_name, strerror (errno)); | 38 | ca_cert_file_name, strerror (errno)); |
39 | return NULL; | 39 | return NULL; |
40 | } | 40 | } |
41 | if (fwrite (ca_cert_pem, sizeof (char), strlen (ca_cert_pem) + 1, cert_fd) | 41 | if (fwrite (ca_cert_pem, sizeof (char), strlen (ca_cert_pem) + 1, cert_fd) |
42 | != strlen (ca_cert_pem) + 1) | 42 | != strlen (ca_cert_pem) + 1) |
43 | { | 43 | { |
44 | fprintf (stderr, "Error: failed to write `%s. %s'\n", | 44 | fprintf (stderr, "Error: failed to write `%s. %s'\n", |
45 | ca_cert_file_name, strerror (errno)); | 45 | ca_cert_file_name, strerror (errno)); |
46 | fclose (cert_fd); | 46 | fclose (cert_fd); |
47 | return NULL; | 47 | return NULL; |
48 | } | 48 | } |
49 | if (fflush (cert_fd)) | 49 | if (fflush (cert_fd)) |
50 | { | 50 | { |
51 | fprintf (stderr, "Error: failed to flush ca cert file stream. %s\n", | 51 | fprintf (stderr, "Error: failed to flush ca cert file stream. %s\n", |
52 | strerror (errno)); | 52 | strerror (errno)); |
53 | fclose (cert_fd); | 53 | fclose (cert_fd); |
54 | return NULL; | 54 | return NULL; |
55 | } | 55 | } |
56 | return cert_fd; | 56 | return cert_fd; |
57 | } | 57 | } |
58 | 58 | ||
@@ -62,23 +62,23 @@ setup_ca_cert () | |||
62 | */ | 62 | */ |
63 | int | 63 | int |
64 | test_daemon_get (void *cls, | 64 | test_daemon_get (void *cls, |
65 | const char *cipher_suite, int proto_version, | 65 | const char *cipher_suite, int proto_version, |
66 | int port, | 66 | int port, |
67 | int ver_peer) | 67 | int ver_peer) |
68 | { | 68 | { |
69 | CURL *c; | 69 | CURL *c; |
70 | struct CBC cbc; | 70 | struct CBC cbc; |
71 | CURLcode errornum; | 71 | CURLcode errornum; |
72 | char url[255]; | 72 | char url[255]; |
73 | size_t len; | 73 | size_t len; |
74 | (void)cls; /* Unused. Silent compiler warning. */ | 74 | (void) cls; /* Unused. Silent compiler warning. */ |
75 | 75 | ||
76 | len = strlen (test_data); | 76 | len = strlen (test_data); |
77 | if (NULL == (cbc.buf = malloc (sizeof (char) * len))) | 77 | if (NULL == (cbc.buf = malloc (sizeof (char) * len))) |
78 | { | 78 | { |
79 | fprintf (stderr, MHD_E_MEM); | 79 | fprintf (stderr, MHD_E_MEM); |
80 | return -1; | 80 | return -1; |
81 | } | 81 | } |
82 | cbc.size = len; | 82 | cbc.size = len; |
83 | cbc.pos = 0; | 83 | cbc.pos = 0; |
84 | 84 | ||
@@ -115,22 +115,22 @@ test_daemon_get (void *cls, | |||
115 | crashes on my system! */ | 115 | crashes on my system! */ |
116 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 116 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
117 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 117 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
118 | { | 118 | { |
119 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", | 119 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", |
120 | curl_easy_strerror (errornum)); | 120 | curl_easy_strerror (errornum)); |
121 | curl_easy_cleanup (c); | 121 | curl_easy_cleanup (c); |
122 | free (cbc.buf); | 122 | free (cbc.buf); |
123 | return errornum; | 123 | return errornum; |
124 | } | 124 | } |
125 | 125 | ||
126 | curl_easy_cleanup (c); | 126 | curl_easy_cleanup (c); |
127 | 127 | ||
128 | if (memcmp (cbc.buf, test_data, len) != 0) | 128 | if (memcmp (cbc.buf, test_data, len) != 0) |
129 | { | 129 | { |
130 | fprintf (stderr, "Error: local file & received file differ.\n"); | 130 | fprintf (stderr, "Error: local file & received file differ.\n"); |
131 | free (cbc.buf); | 131 | free (cbc.buf); |
132 | return -1; | 132 | return -1; |
133 | } | 133 | } |
134 | 134 | ||
135 | free (cbc.buf); | 135 | free (cbc.buf); |
136 | return 0; | 136 | return 0; |
@@ -141,7 +141,9 @@ void | |||
141 | print_test_result (int test_outcome, char *test_name) | 141 | print_test_result (int test_outcome, char *test_name) |
142 | { | 142 | { |
143 | if (test_outcome != 0) | 143 | if (test_outcome != 0) |
144 | fprintf (stderr, "running test: %s [fail: %u]\n", test_name, (unsigned int)test_outcome); | 144 | fprintf (stderr, "running test: %s [fail: %u]\n", test_name, (unsigned |
145 | int) | ||
146 | test_outcome); | ||
145 | #if 0 | 147 | #if 0 |
146 | else | 148 | else |
147 | fprintf (stdout, "running test: %s [pass]\n", test_name); | 149 | fprintf (stdout, "running test: %s [pass]\n", test_name); |
@@ -171,21 +173,21 @@ http_ahc (void *cls, struct MHD_Connection *connection, | |||
171 | static int aptr; | 173 | static int aptr; |
172 | struct MHD_Response *response; | 174 | struct MHD_Response *response; |
173 | int ret; | 175 | int ret; |
174 | (void)cls;(void)url;(void)version; /* Unused. Silent compiler warning. */ | 176 | (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */ |
175 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 177 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
176 | 178 | ||
177 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) | 179 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) |
178 | return MHD_NO; /* unexpected method */ | 180 | return MHD_NO; /* unexpected method */ |
179 | if (&aptr != *ptr) | 181 | if (&aptr != *ptr) |
180 | { | 182 | { |
181 | /* do never respond on first call */ | 183 | /* do never respond on first call */ |
182 | *ptr = &aptr; | 184 | *ptr = &aptr; |
183 | return MHD_YES; | 185 | return MHD_YES; |
184 | } | 186 | } |
185 | *ptr = NULL; /* reset when done */ | 187 | *ptr = NULL; /* reset when done */ |
186 | response = MHD_create_response_from_buffer (strlen (test_data), | 188 | response = MHD_create_response_from_buffer (strlen (test_data), |
187 | (void *) test_data, | 189 | (void *) test_data, |
188 | MHD_RESPMEM_PERSISTENT); | 190 | MHD_RESPMEM_PERSISTENT); |
189 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 191 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
190 | MHD_destroy_response (response); | 192 | MHD_destroy_response (response); |
191 | return ret; | 193 | return ret; |
@@ -198,9 +200,9 @@ http_dummy_ahc (void *cls, struct MHD_Connection *connection, | |||
198 | const char *upload_data, size_t *upload_data_size, | 200 | const char *upload_data, size_t *upload_data_size, |
199 | void **ptr) | 201 | void **ptr) |
200 | { | 202 | { |
201 | (void)cls;(void)connection;(void)url;(void)method;(void)version; /* Unused. Silent compiler warning. */ | 203 | (void) cls; (void) connection; (void) url; (void) method; (void) version; /* Unused. Silent compiler warning. */ |
202 | (void)upload_data;(void)upload_data_size;(void)ptr; /* Unused. Silent compiler warning. */ | 204 | (void) upload_data; (void) upload_data_size; (void) ptr; /* Unused. Silent compiler warning. */ |
203 | return 0; | 205 | return 0; |
204 | } | 206 | } |
205 | 207 | ||
206 | /** | 208 | /** |
@@ -213,7 +215,7 @@ http_dummy_ahc (void *cls, struct MHD_Connection *connection, | |||
213 | */ | 215 | */ |
214 | /* TODO have test wrap consider a NULL cbc */ | 216 | /* TODO have test wrap consider a NULL cbc */ |
215 | int | 217 | int |
216 | send_curl_req (char *url, struct CBC * cbc, const char *cipher_suite, | 218 | send_curl_req (char *url, struct CBC *cbc, const char *cipher_suite, |
217 | int proto_version) | 219 | int proto_version) |
218 | { | 220 | { |
219 | CURL *c; | 221 | CURL *c; |
@@ -228,10 +230,10 @@ send_curl_req (char *url, struct CBC * cbc, const char *cipher_suite, | |||
228 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 60L); | 230 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 60L); |
229 | 231 | ||
230 | if (cbc != NULL) | 232 | if (cbc != NULL) |
231 | { | 233 | { |
232 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 234 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
233 | curl_easy_setopt (c, CURLOPT_FILE, cbc); | 235 | curl_easy_setopt (c, CURLOPT_FILE, cbc); |
234 | } | 236 | } |
235 | 237 | ||
236 | /* TLS options */ | 238 | /* TLS options */ |
237 | curl_easy_setopt (c, CURLOPT_SSLVERSION, proto_version); | 239 | curl_easy_setopt (c, CURLOPT_SSLVERSION, proto_version); |
@@ -248,12 +250,12 @@ send_curl_req (char *url, struct CBC * cbc, const char *cipher_suite, | |||
248 | crashes on my system! */ | 250 | crashes on my system! */ |
249 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 251 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
250 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 252 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
251 | { | 253 | { |
252 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", | 254 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", |
253 | curl_easy_strerror (errornum)); | 255 | curl_easy_strerror (errornum)); |
254 | curl_easy_cleanup (c); | 256 | curl_easy_cleanup (c); |
255 | return errornum; | 257 | return errornum; |
256 | } | 258 | } |
257 | curl_easy_cleanup (c); | 259 | curl_easy_cleanup (c); |
258 | 260 | ||
259 | return CURLE_OK; | 261 | return CURLE_OK; |
@@ -286,27 +288,27 @@ gen_test_file_url (char *url, | |||
286 | size_t i; | 288 | size_t i; |
287 | #endif /* ! WINDOWS */ | 289 | #endif /* ! WINDOWS */ |
288 | if (NULL == (doc_path = malloc (doc_path_len))) | 290 | if (NULL == (doc_path = malloc (doc_path_len))) |
289 | { | 291 | { |
290 | fprintf (stderr, MHD_E_MEM); | 292 | fprintf (stderr, MHD_E_MEM); |
291 | return -1; | 293 | return -1; |
292 | } | 294 | } |
293 | if (NULL == getcwd (doc_path, doc_path_len)) | 295 | if (NULL == getcwd (doc_path, doc_path_len)) |
294 | { | 296 | { |
295 | fprintf (stderr, | 297 | fprintf (stderr, |
296 | "Error: failed to get working directory. %s\n", | 298 | "Error: failed to get working directory. %s\n", |
297 | strerror (errno)); | 299 | strerror (errno)); |
298 | free (doc_path); | 300 | free (doc_path); |
299 | return -1; | 301 | return -1; |
300 | } | 302 | } |
301 | #ifdef WINDOWS | 303 | #ifdef WINDOWS |
302 | for (i = 0; i < doc_path_len; i++) | 304 | for (i = 0; i < doc_path_len; i++) |
303 | { | 305 | { |
304 | if (doc_path[i] == 0) | 306 | if (doc_path[i] == 0) |
305 | break; | 307 | break; |
306 | if (doc_path[i] == '\\') | 308 | if (doc_path[i] == '\\') |
307 | { | 309 | { |
308 | doc_path[i] = '/'; | 310 | doc_path[i] = '/'; |
309 | } | 311 | } |
310 | if (doc_path[i] != ':') | 312 | if (doc_path[i] != ':') |
311 | continue; | 313 | continue; |
312 | if (i == 0) | 314 | if (i == 0) |
@@ -322,7 +324,7 @@ gen_test_file_url (char *url, | |||
322 | "https://127.0.0.1", | 324 | "https://127.0.0.1", |
323 | port, | 325 | port, |
324 | doc_path, | 326 | doc_path, |
325 | "urlpath") >= (long long)url_len) | 327 | "urlpath") >= (long long) url_len) |
326 | ret = -1; | 328 | ret = -1; |
327 | 329 | ||
328 | free (doc_path); | 330 | free (doc_path); |
@@ -343,41 +345,41 @@ test_https_transfer (void *cls, | |||
343 | int ret = 0; | 345 | int ret = 0; |
344 | struct CBC cbc; | 346 | struct CBC cbc; |
345 | char url[255]; | 347 | char url[255]; |
346 | (void)cls; /* Unused. Silent compiler warning. */ | 348 | (void) cls; /* Unused. Silent compiler warning. */ |
347 | 349 | ||
348 | len = strlen (test_data); | 350 | len = strlen (test_data); |
349 | if (NULL == (cbc.buf = malloc (sizeof (char) * len))) | 351 | if (NULL == (cbc.buf = malloc (sizeof (char) * len))) |
350 | { | 352 | { |
351 | fprintf (stderr, MHD_E_MEM); | 353 | fprintf (stderr, MHD_E_MEM); |
352 | return -1; | 354 | return -1; |
353 | } | 355 | } |
354 | cbc.size = len; | 356 | cbc.size = len; |
355 | cbc.pos = 0; | 357 | cbc.pos = 0; |
356 | 358 | ||
357 | if (gen_test_file_url (url, | 359 | if (gen_test_file_url (url, |
358 | sizeof (url), | 360 | sizeof (url), |
359 | port)) | 361 | port)) |
360 | { | 362 | { |
361 | ret = -1; | 363 | ret = -1; |
362 | goto cleanup; | 364 | goto cleanup; |
363 | } | 365 | } |
364 | 366 | ||
365 | if (CURLE_OK != | 367 | if (CURLE_OK != |
366 | send_curl_req (url, &cbc, cipher_suite, proto_version)) | 368 | send_curl_req (url, &cbc, cipher_suite, proto_version)) |
367 | { | 369 | { |
368 | ret = -1; | 370 | ret = -1; |
369 | goto cleanup; | 371 | goto cleanup; |
370 | } | 372 | } |
371 | 373 | ||
372 | /* compare test file & daemon responce */ | 374 | /* compare test file & daemon responce */ |
373 | if ( (len != strlen (test_data)) || | 375 | if ( (len != strlen (test_data)) || |
374 | (memcmp (cbc.buf, | 376 | (memcmp (cbc.buf, |
375 | test_data, | 377 | test_data, |
376 | len) != 0) ) | 378 | len) != 0) ) |
377 | { | 379 | { |
378 | fprintf (stderr, "Error: local file & received file differ.\n"); | 380 | fprintf (stderr, "Error: local file & received file differ.\n"); |
379 | ret = -1; | 381 | ret = -1; |
380 | } | 382 | } |
381 | cleanup: | 383 | cleanup: |
382 | free (cbc.buf); | 384 | free (cbc.buf); |
383 | return ret; | 385 | return ret; |
@@ -392,28 +394,29 @@ cleanup: | |||
392 | * @return port number on success or zero on failure | 394 | * @return port number on success or zero on failure |
393 | */ | 395 | */ |
394 | int | 396 | int |
395 | setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list arg_list) | 397 | setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list |
398 | arg_list) | ||
396 | { | 399 | { |
397 | *d = MHD_start_daemon_va (daemon_flags, port, | 400 | *d = MHD_start_daemon_va (daemon_flags, port, |
398 | NULL, NULL, &http_ahc, NULL, arg_list); | 401 | NULL, NULL, &http_ahc, NULL, arg_list); |
399 | 402 | ||
400 | if (*d == NULL) | 403 | if (*d == NULL) |
401 | { | 404 | { |
402 | fprintf (stderr, MHD_E_SERVER_INIT); | 405 | fprintf (stderr, MHD_E_SERVER_INIT); |
403 | return 0; | 406 | return 0; |
404 | } | 407 | } |
405 | 408 | ||
406 | if (0 == port) | 409 | if (0 == port) |
410 | { | ||
411 | const union MHD_DaemonInfo *dinfo; | ||
412 | dinfo = MHD_get_daemon_info (*d, MHD_DAEMON_INFO_BIND_PORT); | ||
413 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
407 | { | 414 | { |
408 | const union MHD_DaemonInfo *dinfo; | 415 | MHD_stop_daemon (*d); |
409 | dinfo = MHD_get_daemon_info (*d, MHD_DAEMON_INFO_BIND_PORT); | 416 | return 0; |
410 | if (NULL == dinfo || 0 == dinfo->port) | ||
411 | { | ||
412 | MHD_stop_daemon (*d); | ||
413 | return 0; | ||
414 | } | ||
415 | port = (int)dinfo->port; | ||
416 | } | 417 | } |
418 | port = (int) dinfo->port; | ||
419 | } | ||
417 | 420 | ||
418 | return port; | 421 | return port; |
419 | } | 422 | } |
@@ -425,10 +428,10 @@ teardown_testcase (struct MHD_Daemon *d) | |||
425 | } | 428 | } |
426 | 429 | ||
427 | int | 430 | int |
428 | setup_session (gnutls_session_t * session, | 431 | setup_session (gnutls_session_t *session, |
429 | gnutls_datum_t * key, | 432 | gnutls_datum_t *key, |
430 | gnutls_datum_t * cert, | 433 | gnutls_datum_t *cert, |
431 | gnutls_certificate_credentials_t * xcred) | 434 | gnutls_certificate_credentials_t *xcred) |
432 | { | 435 | { |
433 | int ret; | 436 | int ret; |
434 | const char *err_pos; | 437 | const char *err_pos; |
@@ -437,42 +440,42 @@ setup_session (gnutls_session_t * session, | |||
437 | key->size = strlen (srv_key_pem) + 1; | 440 | key->size = strlen (srv_key_pem) + 1; |
438 | key->data = malloc (key->size); | 441 | key->data = malloc (key->size); |
439 | if (NULL == key->data) | 442 | if (NULL == key->data) |
440 | { | 443 | { |
441 | gnutls_certificate_free_credentials (*xcred); | 444 | gnutls_certificate_free_credentials (*xcred); |
442 | return -1; | 445 | return -1; |
443 | } | 446 | } |
444 | memcpy (key->data, srv_key_pem, key->size); | 447 | memcpy (key->data, srv_key_pem, key->size); |
445 | cert->size = strlen (srv_self_signed_cert_pem) + 1; | 448 | cert->size = strlen (srv_self_signed_cert_pem) + 1; |
446 | cert->data = malloc (cert->size); | 449 | cert->data = malloc (cert->size); |
447 | if (NULL == cert->data) | 450 | if (NULL == cert->data) |
448 | { | 451 | { |
449 | gnutls_certificate_free_credentials (*xcred); | 452 | gnutls_certificate_free_credentials (*xcred); |
450 | free (key->data); | 453 | free (key->data); |
451 | return -1; | 454 | return -1; |
452 | } | 455 | } |
453 | memcpy (cert->data, srv_self_signed_cert_pem, cert->size); | 456 | memcpy (cert->data, srv_self_signed_cert_pem, cert->size); |
454 | gnutls_certificate_set_x509_key_mem (*xcred, cert, key, | 457 | gnutls_certificate_set_x509_key_mem (*xcred, cert, key, |
455 | GNUTLS_X509_FMT_PEM); | 458 | GNUTLS_X509_FMT_PEM); |
456 | gnutls_init (session, GNUTLS_CLIENT); | 459 | gnutls_init (session, GNUTLS_CLIENT); |
457 | ret = gnutls_priority_set_direct (*session, | 460 | ret = gnutls_priority_set_direct (*session, |
458 | "NORMAL", &err_pos); | 461 | "NORMAL", &err_pos); |
459 | if (ret < 0) | 462 | if (ret < 0) |
460 | { | 463 | { |
461 | gnutls_deinit (*session); | 464 | gnutls_deinit (*session); |
462 | gnutls_certificate_free_credentials (*xcred); | 465 | gnutls_certificate_free_credentials (*xcred); |
463 | free (key->data); | 466 | free (key->data); |
464 | return -1; | 467 | return -1; |
465 | } | 468 | } |
466 | gnutls_credentials_set (*session, | 469 | gnutls_credentials_set (*session, |
467 | GNUTLS_CRD_CERTIFICATE, | 470 | GNUTLS_CRD_CERTIFICATE, |
468 | *xcred); | 471 | *xcred); |
469 | return 0; | 472 | return 0; |
470 | } | 473 | } |
471 | 474 | ||
472 | int | 475 | int |
473 | teardown_session (gnutls_session_t session, | 476 | teardown_session (gnutls_session_t session, |
474 | gnutls_datum_t * key, | 477 | gnutls_datum_t *key, |
475 | gnutls_datum_t * cert, | 478 | gnutls_datum_t *cert, |
476 | gnutls_certificate_credentials_t xcred) | 479 | gnutls_certificate_credentials_t xcred) |
477 | { | 480 | { |
478 | free (key->data); | 481 | free (key->data); |
@@ -489,37 +492,37 @@ teardown_session (gnutls_session_t session, | |||
489 | /* TODO test_wrap: change sig to (setup_func, test, va_list test_arg) */ | 492 | /* TODO test_wrap: change sig to (setup_func, test, va_list test_arg) */ |
490 | int | 493 | int |
491 | test_wrap (const char *test_name, int | 494 | test_wrap (const char *test_name, int |
492 | (*test_function) (void * cls, int port, const char *cipher_suite, | 495 | (*test_function)(void *cls, int port, const char *cipher_suite, |
493 | int proto_version), void * cls, | 496 | int proto_version), void *cls, |
494 | int port, | 497 | int port, |
495 | int daemon_flags, const char *cipher_suite, int proto_version, ...) | 498 | int daemon_flags, const char *cipher_suite, int proto_version, ...) |
496 | { | 499 | { |
497 | int ret; | 500 | int ret; |
498 | va_list arg_list; | 501 | va_list arg_list; |
499 | struct MHD_Daemon *d; | 502 | struct MHD_Daemon *d; |
500 | (void)cls; /* Unused. Silent compiler warning. */ | 503 | (void) cls; /* Unused. Silent compiler warning. */ |
501 | 504 | ||
502 | va_start (arg_list, proto_version); | 505 | va_start (arg_list, proto_version); |
503 | port = setup_testcase (&d, port, daemon_flags, arg_list); | 506 | port = setup_testcase (&d, port, daemon_flags, arg_list); |
504 | if (0 == port) | 507 | if (0 == port) |
505 | { | 508 | { |
506 | va_end (arg_list); | 509 | va_end (arg_list); |
507 | fprintf (stderr, "Failed to setup testcase %s\n", test_name); | 510 | fprintf (stderr, "Failed to setup testcase %s\n", test_name); |
508 | return -1; | 511 | return -1; |
509 | } | 512 | } |
510 | #if 0 | 513 | #if 0 |
511 | fprintf (stdout, "running test: %s ", test_name); | 514 | fprintf (stdout, "running test: %s ", test_name); |
512 | #endif | 515 | #endif |
513 | ret = test_function (NULL, port, cipher_suite, proto_version); | 516 | ret = test_function (NULL, port, cipher_suite, proto_version); |
514 | #if 0 | 517 | #if 0 |
515 | if (ret == 0) | 518 | if (ret == 0) |
516 | { | 519 | { |
517 | fprintf (stdout, "[pass]\n"); | 520 | fprintf (stdout, "[pass]\n"); |
518 | } | 521 | } |
519 | else | 522 | else |
520 | { | 523 | { |
521 | fprintf (stdout, "[fail]\n"); | 524 | fprintf (stdout, "[fail]\n"); |
522 | } | 525 | } |
523 | #endif | 526 | #endif |
524 | teardown_testcase (d); | 527 | teardown_testcase (d); |
525 | va_end (arg_list); | 528 | va_end (arg_list); |
@@ -532,17 +535,19 @@ testsuite_curl_global_init (void) | |||
532 | { | 535 | { |
533 | CURLcode res; | 536 | CURLcode res; |
534 | #if LIBCURL_VERSION_NUM >= 0x073800 | 537 | #if LIBCURL_VERSION_NUM >= 0x073800 |
535 | if (CURLSSLSET_OK != curl_global_sslset(CURLSSLBACKEND_GNUTLS, NULL, NULL)) | 538 | if (CURLSSLSET_OK != curl_global_sslset (CURLSSLBACKEND_GNUTLS, NULL, NULL)) |
536 | { | 539 | { |
537 | if (CURLSSLSET_TOO_LATE == curl_global_sslset(CURLSSLBACKEND_OPENSSL, NULL, NULL)) | 540 | if (CURLSSLSET_TOO_LATE == curl_global_sslset (CURLSSLBACKEND_OPENSSL, NULL, |
538 | fprintf (stderr, "WARNING: libcurl was already initialised.\n"); | 541 | NULL)) |
539 | } | 542 | fprintf (stderr, "WARNING: libcurl was already initialised.\n"); |
543 | } | ||
540 | #endif /* LIBCURL_VERSION_NUM >= 0x07380 */ | 544 | #endif /* LIBCURL_VERSION_NUM >= 0x07380 */ |
541 | res = curl_global_init (CURL_GLOBAL_ALL); | 545 | res = curl_global_init (CURL_GLOBAL_ALL); |
542 | if (CURLE_OK != res) | 546 | if (CURLE_OK != res) |
543 | { | 547 | { |
544 | fprintf (stderr, "libcurl initialisation error: %s\n", curl_easy_strerror(res)); | 548 | fprintf (stderr, "libcurl initialisation error: %s\n", curl_easy_strerror ( |
545 | return 0; | 549 | res)); |
546 | } | 550 | return 0; |
551 | } | ||
547 | return 1; | 552 | return 1; |
548 | } | 553 | } |
diff --git a/src/testcurl/https/tls_test_common.h b/src/testcurl/https/tls_test_common.h index 490239ef..36f5ffa5 100644 --- a/src/testcurl/https/tls_test_common.h +++ b/src/testcurl/https/tls_test_common.h | |||
@@ -35,15 +35,18 @@ | |||
35 | #define test_data "Hello World\n" | 35 | #define test_data "Hello World\n" |
36 | #define ca_cert_file_name "tmp_ca_cert.pem" | 36 | #define ca_cert_file_name "tmp_ca_cert.pem" |
37 | 37 | ||
38 | #define EMPTY_PAGE "<html><head><title>Empty page</title></head><body>Empty page</body></html>" | 38 | #define EMPTY_PAGE \ |
39 | #define PAGE_NOT_FOUND "<html><head><title>File not found</title></head><body>File not found</body></html>" | 39 | "<html><head><title>Empty page</title></head><body>Empty page</body></html>" |
40 | #define PAGE_NOT_FOUND \ | ||
41 | "<html><head><title>File not found</title></head><body>File not found</body></html>" | ||
40 | 42 | ||
41 | #define MHD_E_MEM "Error: memory error\n" | 43 | #define MHD_E_MEM "Error: memory error\n" |
42 | #define MHD_E_SERVER_INIT "Error: failed to start server\n" | 44 | #define MHD_E_SERVER_INIT "Error: failed to start server\n" |
43 | #define MHD_E_TEST_FILE_CREAT "Error: failed to setup test file\n" | 45 | #define MHD_E_TEST_FILE_CREAT "Error: failed to setup test file\n" |
44 | #define MHD_E_CERT_FILE_CREAT "Error: failed to setup test certificate\n" | 46 | #define MHD_E_CERT_FILE_CREAT "Error: failed to setup test certificate\n" |
45 | #define MHD_E_KEY_FILE_CREAT "Error: failed to setup test certificate\n" | 47 | #define MHD_E_KEY_FILE_CREAT "Error: failed to setup test certificate\n" |
46 | #define MHD_E_FAILED_TO_CONNECT "Error: server connection could not be established\n" | 48 | #define MHD_E_FAILED_TO_CONNECT \ |
49 | "Error: server connection could not be established\n" | ||
47 | 50 | ||
48 | /* TODO rm if unused */ | 51 | /* TODO rm if unused */ |
49 | struct https_test_data | 52 | struct https_test_data |
@@ -82,8 +85,8 @@ setup_ca_cert (void); | |||
82 | * perform cURL request for file | 85 | * perform cURL request for file |
83 | */ | 86 | */ |
84 | int | 87 | int |
85 | test_daemon_get (void * cls, | 88 | test_daemon_get (void *cls, |
86 | const char *cipher_suite, int proto_version, | 89 | const char *cipher_suite, int proto_version, |
87 | int port, int ver_peer); | 90 | int port, int ver_peer); |
88 | 91 | ||
89 | void | 92 | void |
@@ -122,31 +125,33 @@ send_curl_req (char *url, struct CBC *cbc, const char *cipher_suite, | |||
122 | int proto_version); | 125 | int proto_version); |
123 | 126 | ||
124 | int | 127 | int |
125 | test_https_transfer (void *cls, int port, const char *cipher_suite, int proto_version); | 128 | test_https_transfer (void *cls, int port, const char *cipher_suite, int |
129 | proto_version); | ||
126 | 130 | ||
127 | int | 131 | int |
128 | setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list arg_list); | 132 | setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list |
133 | arg_list); | ||
129 | 134 | ||
130 | void | 135 | void |
131 | teardown_testcase (struct MHD_Daemon *d); | 136 | teardown_testcase (struct MHD_Daemon *d); |
132 | 137 | ||
133 | 138 | ||
134 | int | 139 | int |
135 | setup_session (gnutls_session_t * session, | 140 | setup_session (gnutls_session_t *session, |
136 | gnutls_datum_t * key, | 141 | gnutls_datum_t *key, |
137 | gnutls_datum_t * cert, | 142 | gnutls_datum_t *cert, |
138 | gnutls_certificate_credentials_t * xcred); | 143 | gnutls_certificate_credentials_t *xcred); |
139 | 144 | ||
140 | int | 145 | int |
141 | teardown_session (gnutls_session_t session, | 146 | teardown_session (gnutls_session_t session, |
142 | gnutls_datum_t * key, | 147 | gnutls_datum_t *key, |
143 | gnutls_datum_t * cert, | 148 | gnutls_datum_t *cert, |
144 | gnutls_certificate_credentials_t xcred); | 149 | gnutls_certificate_credentials_t xcred); |
145 | 150 | ||
146 | int | 151 | int |
147 | test_wrap (const char *test_name, int | 152 | test_wrap (const char *test_name, int |
148 | (*test_function) (void * cls, int port, const char *cipher_suite, | 153 | (*test_function)(void *cls, int port, const char *cipher_suite, |
149 | int proto_version), void * cls, | 154 | int proto_version), void *cls, |
150 | int port, | 155 | int port, |
151 | int daemon_flags, const char *cipher_suite, int proto_version, ...); | 156 | int daemon_flags, const char *cipher_suite, int proto_version, ...); |
152 | 157 | ||
diff --git a/src/testcurl/https/tls_test_keys.h b/src/testcurl/https/tls_test_keys.h index b6e37eec..76f6f06f 100644 --- a/src/testcurl/https/tls_test_keys.h +++ b/src/testcurl/https/tls_test_keys.h | |||
@@ -24,150 +24,150 @@ | |||
24 | 24 | ||
25 | /* Certificate Authority key */ | 25 | /* Certificate Authority key */ |
26 | const char ca_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" | 26 | const char ca_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" |
27 | "MIIEowIBAAKCAQEA0EdlP613rjFvEj93tGo9fzBoKWU3CW+AbbfcJ397C89MyZ9J\n" | 27 | "MIIEowIBAAKCAQEA0EdlP613rjFvEj93tGo9fzBoKWU3CW+AbbfcJ397C89MyZ9J\n" |
28 | "rlxyLGfa6qVX7CFVNmzgWWfcl2tHlw/fZmWtf/SFgrlkldvuGyY8H3n2HuMsWz/E\n" | 28 | "rlxyLGfa6qVX7CFVNmzgWWfcl2tHlw/fZmWtf/SFgrlkldvuGyY8H3n2HuMsWz/E\n" |
29 | "h7n5VgwBX8NsP4eZNmikepxpr1mYx25K8FjnsKjAR9jGUSV8UfZ7VLIY0x/yqe+3\n" | 29 | "h7n5VgwBX8NsP4eZNmikepxpr1mYx25K8FjnsKjAR9jGUSV8UfZ7VLIY0x/yqe+3\n" |
30 | "32oqc4D/wJbV1AwwvC5Xf9rvHJwcZg57eqbDCL/4GDDk7d9Gark4XK6ZG+FnnxQn\n" | 30 | "32oqc4D/wJbV1AwwvC5Xf9rvHJwcZg57eqbDCL/4GDDk7d9Gark4XK6ZG+FnnxQn\n" |
31 | "4a4jIdf4FoPp9s0EieHrHwYzs/uBqmfCSF4wXiaO8bmEwtbAsVbZH74Le7ggUbEe\n" | 31 | "4a4jIdf4FoPp9s0EieHrHwYzs/uBqmfCSF4wXiaO8bmEwtbAsVbZH74Le7ggUbEe\n" |
32 | "o+jan9XK0dE88AIImGzgoBnlic/Rr7J8OWA+iwIDAQABAoIBAEICZqXkUdpsw2F6\n" | 32 | "o+jan9XK0dE88AIImGzgoBnlic/Rr7J8OWA+iwIDAQABAoIBAEICZqXkUdpsw2F6\n" |
33 | "qPMOergNPO3lrKg6ZO8hBs6j2fj3tcPuzljK5sqJDboxNejZ9Zo+rmnXf3Oj5fgL\n" | 33 | "qPMOergNPO3lrKg6ZO8hBs6j2fj3tcPuzljK5sqJDboxNejZ9Zo+rmnXf3Oj5fgL\n" |
34 | "6UcYMYEsm4W/QRA3uEJ1fzeQnT7Ty9KNprlHaSzquCLEGlIWJSo3xu0vFlWjJUcL\n" | 34 | "6UcYMYEsm4W/QRA3uEJ1fzeQnT7Ty9KNprlHaSzquCLEGlIWJSo3xu0vFlWjJUcL\n" |
35 | "fwemfaOhD/OVUeEU6s5FOngwy6pZUsOajs3fNRtwBGuuXjniKZZlpSf2Wqu3xpHZ\n" | 35 | "fwemfaOhD/OVUeEU6s5FOngwy6pZUsOajs3fNRtwBGuuXjniKZZlpSf2Wqu3xpHZ\n" |
36 | "31OF1V0ycUCGPPFtpmUCtnZhS9L8QBTkNtfTIdXv6SfoBRFm0oXb0uL5HGft6yc7\n" | 36 | "31OF1V0ycUCGPPFtpmUCtnZhS9L8QBTkNtfTIdXv6SfoBRFm0oXb0uL5HGft6yc7\n" |
37 | "eYRXIscllQciqG3ymJ/y9o0E3A0YsBVauQyi7OEk+Kg8uoYOBkZCIY69hoN2Znlk\n" | 37 | "eYRXIscllQciqG3ymJ/y9o0E3A0YsBVauQyi7OEk+Kg8uoYOBkZCIY69hoN2Znlk\n" |
38 | "OY5S5Z0CgYEA3j8pRAJzvc827KcX4vJf05HYD4aCyaI80fNmx1DgXfglTSGLQ361\n" | 38 | "OY5S5Z0CgYEA3j8pRAJzvc827KcX4vJf05HYD4aCyaI80fNmx1DgXfglTSGLQ361\n" |
39 | "6i05YW8WtIvgkma3wF+jJOckBCW/7iq8wAX7Kz75WKGRyyTEb0wSfjx0G8grxX4d\n" | 39 | "6i05YW8WtIvgkma3wF+jJOckBCW/7iq8wAX7Kz75WKGRyyTEb0wSfjx0G8grxX4d\n" |
40 | "7sTIAAOnQj5WT6E/bkqxQZAYnVtIPxKtSlwts0H/bjPVYwSFchHK7t8CgYEA7+ks\n" | 40 | "7sTIAAOnQj5WT6E/bkqxQZAYnVtIPxKtSlwts0H/bjPVYwSFchHK7t8CgYEA7+ks\n" |
41 | "C0EMjF8CDeCfvbOUGiiqAvU3G20LEC3WlJM3AU+J9Jzp6AMkgaIA8J5oNdsbFBn4\n" | 41 | "C0EMjF8CDeCfvbOUGiiqAvU3G20LEC3WlJM3AU+J9Jzp6AMkgaIA8J5oNdsbFBn4\n" |
42 | "N12JPOO+7WRUk6Av8bsh4faE36ThnHohgAL8guRU7jIXvsFyO5yiY7/o/0lES0/V\n" | 42 | "N12JPOO+7WRUk6Av8bsh4faE36ThnHohgAL8guRU7jIXvsFyO5yiY7/o/0lES0/V\n" |
43 | "6xkh/Epj4MReuCGkiD9ifCVAo+dhHskeE9qbYdUCgYA4yBpa7eV0UUTPIcHQkew5\n" | 43 | "6xkh/Epj4MReuCGkiD9ifCVAo+dhHskeE9qbYdUCgYA4yBpa7eV0UUTPIcHQkew5\n" |
44 | "ucFh9hPkQDcZzP4tXlR0rbmaAz/5dp4zvmoyopdCeZpezS+VTtn3y7Y/+QUYbILc\n" | 44 | "ucFh9hPkQDcZzP4tXlR0rbmaAz/5dp4zvmoyopdCeZpezS+VTtn3y7Y/+QUYbILc\n" |
45 | "7KpHWkeKhX0iUbp+VQlEh12C25mTU62CG3SdzFEnc5XJsoDqRNsUzSP80B2dP8BW\n" | 45 | "7KpHWkeKhX0iUbp+VQlEh12C25mTU62CG3SdzFEnc5XJsoDqRNsUzSP80B2dP8BW\n" |
46 | "h0aFzg7csRGLwtP1WOZoMQKBgQCrgsKd+Q8Dexh421DXyX3jhZalLrEKxlXWZy60\n" | 46 | "h0aFzg7csRGLwtP1WOZoMQKBgQCrgsKd+Q8Dexh421DXyX3jhZalLrEKxlXWZy60\n" |
47 | "YNo98aLqYRNHbpe2pR6O5nARsGYXZMlyq0flY9um0sc0Epyz79g1NoufZrxzpUw1\n" | 47 | "YNo98aLqYRNHbpe2pR6O5nARsGYXZMlyq0flY9um0sc0Epyz79g1NoufZrxzpUw1\n" |
48 | "u+zRlnKxJtaa5KjJvRzKuvPTLYnJXXXM8Na/Cl+E3F3qvQJm9QlvPyKLCmsAGz+J\n" | 48 | "u+zRlnKxJtaa5KjJvRzKuvPTLYnJXXXM8Na/Cl+E3F3qvQJm9QlvPyKLCmsAGz+J\n" |
49 | "agsTUQKBgC0wqqJ6b1tbrAD8AVeeAn/IiP1rxYpc3x2s6ikFO2FMHXHC9wgrRPOc\n" | 49 | "agsTUQKBgC0wqqJ6b1tbrAD8AVeeAn/IiP1rxYpc3x2s6ikFO2FMHXHC9wgrRPOc\n" |
50 | "mkokV+DrUOv3I/7jG8wQA/FmBUPy562a1bObIKzg6CPXzrN68AmNnOIVU+H8fdxI\n" | 50 | "mkokV+DrUOv3I/7jG8wQA/FmBUPy562a1bObIKzg6CPXzrN68AmNnOIVU+H8fdxI\n" |
51 | "iGyfT8WNpcRmtN11v34qXHwOWGQhpyyk2yNa8VIBSpkShq/EseZ1\n" | 51 | "iGyfT8WNpcRmtN11v34qXHwOWGQhpyyk2yNa8VIBSpkShq/EseZ1\n" |
52 | "-----END RSA PRIVATE KEY-----\n"; | 52 | "-----END RSA PRIVATE KEY-----\n"; |
53 | 53 | ||
54 | /* Certificate Authority cert */ | 54 | /* Certificate Authority cert */ |
55 | const char ca_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" | 55 | const char ca_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" |
56 | "MIIC6DCCAdKgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" | 56 | "MIIC6DCCAdKgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" |
57 | "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" | 57 | "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" |
58 | "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" | 58 | "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" |
59 | "0EdlP613rjFvEj93tGo9fzBoKWU3CW+AbbfcJ397C89MyZ9JrlxyLGfa6qVX7CFV\n" | 59 | "0EdlP613rjFvEj93tGo9fzBoKWU3CW+AbbfcJ397C89MyZ9JrlxyLGfa6qVX7CFV\n" |
60 | "NmzgWWfcl2tHlw/fZmWtf/SFgrlkldvuGyY8H3n2HuMsWz/Eh7n5VgwBX8NsP4eZ\n" | 60 | "NmzgWWfcl2tHlw/fZmWtf/SFgrlkldvuGyY8H3n2HuMsWz/Eh7n5VgwBX8NsP4eZ\n" |
61 | "Nmikepxpr1mYx25K8FjnsKjAR9jGUSV8UfZ7VLIY0x/yqe+332oqc4D/wJbV1Aww\n" | 61 | "Nmikepxpr1mYx25K8FjnsKjAR9jGUSV8UfZ7VLIY0x/yqe+332oqc4D/wJbV1Aww\n" |
62 | "vC5Xf9rvHJwcZg57eqbDCL/4GDDk7d9Gark4XK6ZG+FnnxQn4a4jIdf4FoPp9s0E\n" | 62 | "vC5Xf9rvHJwcZg57eqbDCL/4GDDk7d9Gark4XK6ZG+FnnxQn4a4jIdf4FoPp9s0E\n" |
63 | "ieHrHwYzs/uBqmfCSF4wXiaO8bmEwtbAsVbZH74Le7ggUbEeo+jan9XK0dE88AII\n" | 63 | "ieHrHwYzs/uBqmfCSF4wXiaO8bmEwtbAsVbZH74Le7ggUbEeo+jan9XK0dE88AII\n" |
64 | "mGzgoBnlic/Rr7J8OWA+iwIDAQABo0MwQTAPBgNVHRMBAf8EBTADAQH/MA8GA1Ud\n" | 64 | "mGzgoBnlic/Rr7J8OWA+iwIDAQABo0MwQTAPBgNVHRMBAf8EBTADAQH/MA8GA1Ud\n" |
65 | "DwEB/wQFAwMHBAAwHQYDVR0OBBYEFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsGCSqG\n" | 65 | "DwEB/wQFAwMHBAAwHQYDVR0OBBYEFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsGCSqG\n" |
66 | "SIb3DQEBBQOCAQEAebD5m+vZkVXa8y+QZ5GtsiR9gpH+LKtdWBjk1kmfSgvQI/xA\n" | 66 | "SIb3DQEBBQOCAQEAebD5m+vZkVXa8y+QZ5GtsiR9gpH+LKtdWBjk1kmfSgvQI/xA\n" |
67 | "aDCV/9BhdNGIBOTYGkln8urWd7g2Mj3TwKEAfNTUFpAsrBAlSSLTGYCSt72S2NsS\n" | 67 | "aDCV/9BhdNGIBOTYGkln8urWd7g2Mj3TwKEAfNTUFpAsrBAlSSLTGYCSt72S2NsS\n" |
68 | "L/qUxmj1W6X95UHXCo49mSZx3LlaY3mz1L87gq/kK0XpzA3g2uF25jt84RvshsXy\n" | 68 | "L/qUxmj1W6X95UHXCo49mSZx3LlaY3mz1L87gq/kK0XpzA3g2uF25jt84RvshsXy\n" |
69 | "clOc+eRrVETqFZqer96WB7kzFTv+qmROQKmW8X4a2A5r5Jl4vRwOz5/rEeB9Qs0K\n" | 69 | "clOc+eRrVETqFZqer96WB7kzFTv+qmROQKmW8X4a2A5r5Jl4vRwOz5/rEeB9Qs0K\n" |
70 | "rmK8+5HgvWd80WB8BtfFtZfoY/hHVM8nLD3ELVJrOKiTeIACunQFyT5lV0QkdmSA\n" | 70 | "rmK8+5HgvWd80WB8BtfFtZfoY/hHVM8nLD3ELVJrOKiTeIACunQFyT5lV0QkdmSA\n" |
71 | "CGInU7jzs8nu+s2avf6j+eVZUbVJ+dFMApTJgg==\n" | 71 | "CGInU7jzs8nu+s2avf6j+eVZUbVJ+dFMApTJgg==\n" |
72 | "-----END CERTIFICATE-----\n"; | 72 | "-----END CERTIFICATE-----\n"; |
73 | 73 | ||
74 | /* test server CA signed certificates */ | 74 | /* test server CA signed certificates */ |
75 | const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" | 75 | const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" |
76 | "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" | 76 | "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" |
77 | "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" | 77 | "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" |
78 | "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" | 78 | "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" |
79 | "vfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW+K03KwEku55QvnUn\n" | 79 | "vfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW+K03KwEku55QvnUn\n" |
80 | "dwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8ILq4sw32vo0fbMu5BZ\n" | 80 | "dwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8ILq4sw32vo0fbMu5BZ\n" |
81 | "F49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ020Q5EAAEseD1YtWC\n" | 81 | "F49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ020Q5EAAEseD1YtWC\n" |
82 | "IpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6QYGGh1QmHRPAy3CB\n" | 82 | "IpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6QYGGh1QmHRPAy3CB\n" |
83 | "II6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6xyoOl204xuekZOaG9\n" | 83 | "II6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6xyoOl204xuekZOaG9\n" |
84 | "RUPId74Rtmwfi1TLbBzo2wIDAQABo3YwdDAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n" | 84 | "RUPId74Rtmwfi1TLbBzo2wIDAQABo3YwdDAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n" |
85 | "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFOFi4ilKOP1d\n" | 85 | "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFOFi4ilKOP1d\n" |
86 | "XHlWCMwmVKr7mgy8MB8GA1UdIwQYMBaAFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsG\n" | 86 | "XHlWCMwmVKr7mgy8MB8GA1UdIwQYMBaAFP2olB4s2T/xuoQ5pT2RKojFwZo2MAsG\n" |
87 | "CSqGSIb3DQEBBQOCAQEAHVWPxazupbOkG7Did+dY9z2z6RjTzYvurTtEKQgzM2Vz\n" | 87 | "CSqGSIb3DQEBBQOCAQEAHVWPxazupbOkG7Did+dY9z2z6RjTzYvurTtEKQgzM2Vz\n" |
88 | "GQBA+3pZ3c5mS97fPIs9hZXfnQeelMeZ2XP1a+9vp35bJjZBBhVH+pqxjCgiUflg\n" | 88 | "GQBA+3pZ3c5mS97fPIs9hZXfnQeelMeZ2XP1a+9vp35bJjZBBhVH+pqxjCgiUflg\n" |
89 | "A3Zqy0XwwVCgQLE2HyaU3DLUD/aeIFK5gJaOSdNTXZLv43K8kl4cqDbMeRpVTbkt\n" | 89 | "A3Zqy0XwwVCgQLE2HyaU3DLUD/aeIFK5gJaOSdNTXZLv43K8kl4cqDbMeRpVTbkt\n" |
90 | "YmG4AyEOYRNKGTqMEJXJoxD5E3rBUNrVI/XyTjYrulxbNPcMWEHKNeeqWpKDYTFo\n" | 90 | "YmG4AyEOYRNKGTqMEJXJoxD5E3rBUNrVI/XyTjYrulxbNPcMWEHKNeeqWpKDYTFo\n" |
91 | "Bb01PCthGXiq/4A2RLAFosadzRa8SBpoSjPPfZ0b2w4MJpReHqKbR5+T2t6hzml6\n" | 91 | "Bb01PCthGXiq/4A2RLAFosadzRa8SBpoSjPPfZ0b2w4MJpReHqKbR5+T2t6hzml6\n" |
92 | "4ToyOKPDmamiTuN5KzLN3cw7DQlvWMvqSOChPLnA3Q==\n" | 92 | "4ToyOKPDmamiTuN5KzLN3cw7DQlvWMvqSOChPLnA3Q==\n" |
93 | "-----END CERTIFICATE-----\n"; | 93 | "-----END CERTIFICATE-----\n"; |
94 | 94 | ||
95 | /* test server key */ | 95 | /* test server key */ |
96 | const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" | 96 | const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" |
97 | "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n" | 97 | "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n" |
98 | "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n" | 98 | "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n" |
99 | "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n" | 99 | "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n" |
100 | "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n" | 100 | "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n" |
101 | "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n" | 101 | "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n" |
102 | "yoOl204xuekZOaG9RUPId74Rtmwfi1TLbBzo2wIDAQABAoIBADu09WSICNq5cMe4\n" | 102 | "yoOl204xuekZOaG9RUPId74Rtmwfi1TLbBzo2wIDAQABAoIBADu09WSICNq5cMe4\n" |
103 | "+NKCLlgAT1NiQpLls1gKRbDhKiHU9j8QWNvWWkJWrCya4QdUfLCfeddCMeiQmv3K\n" | 103 | "+NKCLlgAT1NiQpLls1gKRbDhKiHU9j8QWNvWWkJWrCya4QdUfLCfeddCMeiQmv3K\n" |
104 | "lJMvDs+5OjJSHFoOsGiuW2Ias7IjnIojaJalfBml6frhJ84G27IXmdz6gzOiTIer\n" | 104 | "lJMvDs+5OjJSHFoOsGiuW2Ias7IjnIojaJalfBml6frhJ84G27IXmdz6gzOiTIer\n" |
105 | "DjeAgcwBaKH5WwIay2TxIaScl7AwHBauQkrLcyb4hTmZuQh6ArVIN6+pzoVuORXM\n" | 105 | "DjeAgcwBaKH5WwIay2TxIaScl7AwHBauQkrLcyb4hTmZuQh6ArVIN6+pzoVuORXM\n" |
106 | "bpeNWl2l/HSN3VtUN6aCAKbN/X3o0GavCCMn5Fa85uJFsab4ss/uP+2PusU71+zP\n" | 106 | "bpeNWl2l/HSN3VtUN6aCAKbN/X3o0GavCCMn5Fa85uJFsab4ss/uP+2PusU71+zP\n" |
107 | "sBm6p/2IbGvF5k3VPDA7X5YX61sukRjRBihY8xSnNYx1UcoOsX6AiPnbhifD8+xQ\n" | 107 | "sBm6p/2IbGvF5k3VPDA7X5YX61sukRjRBihY8xSnNYx1UcoOsX6AiPnbhifD8+xQ\n" |
108 | "Tlf8oJUCgYEA0BTfzqNpr9Wxw5/QXaSdw7S/0eP5a0C/nwURvmfSzuTD4equzbEN\n" | 108 | "Tlf8oJUCgYEA0BTfzqNpr9Wxw5/QXaSdw7S/0eP5a0C/nwURvmfSzuTD4equzbEN\n" |
109 | "d+dI/s2JMxrdj/I4uoAfUXRGaabevQIjFzC9uyE3LaOyR2zhuvAzX+vVcs6bSXeU\n" | 109 | "d+dI/s2JMxrdj/I4uoAfUXRGaabevQIjFzC9uyE3LaOyR2zhuvAzX+vVcs6bSXeU\n" |
110 | "pKpCAcN+3Z3evMaX2f+z/nfSUAl2i4J2R+/LQAWJW4KwRky/m+cxpfUCgYEA6bN1\n" | 110 | "pKpCAcN+3Z3evMaX2f+z/nfSUAl2i4J2R+/LQAWJW4KwRky/m+cxpfUCgYEA6bN1\n" |
111 | "b73bMgM8wpNt6+fcmS+5n0iZihygQ2U2DEud8nZJL4Nrm1dwTnfZfJBnkGj6+0Q0\n" | 111 | "b73bMgM8wpNt6+fcmS+5n0iZihygQ2U2DEud8nZJL4Nrm1dwTnfZfJBnkGj6+0Q0\n" |
112 | "cOwj2KS0/wcEdJBP0jucU4v60VMhp75AQeHqidIde0bTViSRo3HWKXHBIFGYoU3T\n" | 112 | "cOwj2KS0/wcEdJBP0jucU4v60VMhp75AQeHqidIde0bTViSRo3HWKXHBIFGYoU3T\n" |
113 | "LyPyKndbqsOObnsFXHn56Nwhr2HLf6nw4taGQY8CgYBoSW36FLCNbd6QGvLFXBGt\n" | 113 | "LyPyKndbqsOObnsFXHn56Nwhr2HLf6nw4taGQY8CgYBoSW36FLCNbd6QGvLFXBGt\n" |
114 | "2lMhEM8az/K58kJ4WXSwOLtr6MD/WjNT2tkcy0puEJLm6BFCd6A6pLn9jaKou/92\n" | 114 | "2lMhEM8az/K58kJ4WXSwOLtr6MD/WjNT2tkcy0puEJLm6BFCd6A6pLn9jaKou/92\n" |
115 | "SfltZjJPb3GUlp9zn5tAAeSSi7YMViBrfuFiHObij5LorefBXISLjuYbMwL03MgH\n" | 115 | "SfltZjJPb3GUlp9zn5tAAeSSi7YMViBrfuFiHObij5LorefBXISLjuYbMwL03MgH\n" |
116 | "Ocl2JtA2ywMp2KFXs8GQWQKBgFyIVv5ogQrbZ0pvj31xr9HjqK6d01VxIi+tOmpB\n" | 116 | "Ocl2JtA2ywMp2KFXs8GQWQKBgFyIVv5ogQrbZ0pvj31xr9HjqK6d01VxIi+tOmpB\n" |
117 | "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n" | 117 | "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n" |
118 | "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n" | 118 | "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n" |
119 | "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n" | 119 | "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n" |
120 | "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n" | 120 | "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n" |
121 | "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n" | 121 | "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n" |
122 | "-----END RSA PRIVATE KEY-----\n"; | 122 | "-----END RSA PRIVATE KEY-----\n"; |
123 | 123 | ||
124 | /* test server self signed certificates */ | 124 | /* test server self signed certificates */ |
125 | const char srv_self_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" | 125 | const char srv_self_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" |
126 | "MIIC+jCCAeSgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" | 126 | "MIIC+jCCAeSgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" |
127 | "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" | 127 | "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" |
128 | "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" | 128 | "A1UEAxMMdGVzdF9jYV9jZXJ0MIIBHzALBgkqhkiG9w0BAQEDggEOADCCAQkCggEA\n" |
129 | "tDEagv3p9OUhUL55jMucxjNK9N5cuozhcnrwDfBSU6oVrqm5kPqO1I7Cggzw68Y5\n" | 129 | "tDEagv3p9OUhUL55jMucxjNK9N5cuozhcnrwDfBSU6oVrqm5kPqO1I7Cggzw68Y5\n" |
130 | "jhTcBi4FXmYOZppm1R3MhSJ5JSi/67Q7X4J5rnJLXYGN27qjMpnoGQ/2xmsNG/is\n" | 130 | "jhTcBi4FXmYOZppm1R3MhSJ5JSi/67Q7X4J5rnJLXYGN27qjMpnoGQ/2xmsNG/is\n" |
131 | "i+h/2vbtPU+WP9SEJnTfPLLpZ7KqCAk7FUUzKsuLx3/SOKtdkrWxPKwYTgnDEN6D\n" | 131 | "i+h/2vbtPU+WP9SEJnTfPLLpZ7KqCAk7FUUzKsuLx3/SOKtdkrWxPKwYTgnDEN6D\n" |
132 | "JL7tEzCnG5DFc4mQ7YW9PaRdC3rS1T8PvQ3jB2BUnohM0cFvKRuiU35tU7h7CPbL\n" | 132 | "JL7tEzCnG5DFc4mQ7YW9PaRdC3rS1T8PvQ3jB2BUnohM0cFvKRuiU35tU7h7CPbL\n" |
133 | "4L66VglXoiwqmgcrwI2U968bD0+wRQ5c5bzNoshJOzN6CTMh1IhbklSh/Z6FA/e8\n" | 133 | "4L66VglXoiwqmgcrwI2U968bD0+wRQ5c5bzNoshJOzN6CTMh1IhbklSh/Z6FA/e8\n" |
134 | "hj0yVo2tdllXuJGVs3PIEwIDAQABo1UwUzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n" | 134 | "hj0yVo2tdllXuJGVs3PIEwIDAQABo1UwUzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQM\n" |
135 | "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFDfU7pAv9LYn\n" | 135 | "MAoGCCsGAQUFBwMBMA8GA1UdDwEB/wQFAwMHIAAwHQYDVR0OBBYEFDfU7pAv9LYn\n" |
136 | "n7jb4WHl4+Vgi2FnMAsGCSqGSIb3DQEBBQOCAQEAkaembPQMmv6OOjbIod8zTatr\n" | 136 | "n7jb4WHl4+Vgi2FnMAsGCSqGSIb3DQEBBQOCAQEAkaembPQMmv6OOjbIod8zTatr\n" |
137 | "x5Bwkwp3TOE1NRyy2OytzFIYRUkNrZYlcmrxcbNNycIK41CNVXbriFCF8gcmIq9y\n" | 137 | "x5Bwkwp3TOE1NRyy2OytzFIYRUkNrZYlcmrxcbNNycIK41CNVXbriFCF8gcmIq9y\n" |
138 | "vaKZn8Gcy+vGggv+1BP9IAPBGKRwSi0wmq9JoGE8hx+qqTpRSdfbM/cps/09hicO\n" | 138 | "vaKZn8Gcy+vGggv+1BP9IAPBGKRwSi0wmq9JoGE8hx+qqTpRSdfbM/cps/09hicO\n" |
139 | "0EIR7kWEbvnpMBcMKYOtYE9Gce7rdSMWVAsKc174xn8vW6TxCUvmWFv5DPg5HG1v\n" | 139 | "0EIR7kWEbvnpMBcMKYOtYE9Gce7rdSMWVAsKc174xn8vW6TxCUvmWFv5DPg5HG1v\n" |
140 | "y1SUX73qafRo+W6FN4UC/DHfwRhF8RSKEnVbmgDVCs6GHdKBjU2qRgYyj6nWZqK1\n" | 140 | "y1SUX73qafRo+W6FN4UC/DHfwRhF8RSKEnVbmgDVCs6GHdKBjU2qRgYyj6nWZqK1\n" |
141 | "XFUTWgia+Fl3D9vlsXaFcSZKA0Bq1eojl0B0AfeYAxTFwPWXscKvt/bXZfH8bg==\n" | 141 | "XFUTWgia+Fl3D9vlsXaFcSZKA0Bq1eojl0B0AfeYAxTFwPWXscKvt/bXZfH8bg==\n" |
142 | "-----END CERTIFICATE-----\n"; | 142 | "-----END CERTIFICATE-----\n"; |
143 | 143 | ||
144 | /* test server key */ | 144 | /* test server key */ |
145 | const char srv_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" | 145 | const char srv_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" |
146 | "MIIEpAIBAAKCAQEAtDEagv3p9OUhUL55jMucxjNK9N5cuozhcnrwDfBSU6oVrqm5\n" | 146 | "MIIEpAIBAAKCAQEAtDEagv3p9OUhUL55jMucxjNK9N5cuozhcnrwDfBSU6oVrqm5\n" |
147 | "kPqO1I7Cggzw68Y5jhTcBi4FXmYOZppm1R3MhSJ5JSi/67Q7X4J5rnJLXYGN27qj\n" | 147 | "kPqO1I7Cggzw68Y5jhTcBi4FXmYOZppm1R3MhSJ5JSi/67Q7X4J5rnJLXYGN27qj\n" |
148 | "MpnoGQ/2xmsNG/isi+h/2vbtPU+WP9SEJnTfPLLpZ7KqCAk7FUUzKsuLx3/SOKtd\n" | 148 | "MpnoGQ/2xmsNG/isi+h/2vbtPU+WP9SEJnTfPLLpZ7KqCAk7FUUzKsuLx3/SOKtd\n" |
149 | "krWxPKwYTgnDEN6DJL7tEzCnG5DFc4mQ7YW9PaRdC3rS1T8PvQ3jB2BUnohM0cFv\n" | 149 | "krWxPKwYTgnDEN6DJL7tEzCnG5DFc4mQ7YW9PaRdC3rS1T8PvQ3jB2BUnohM0cFv\n" |
150 | "KRuiU35tU7h7CPbL4L66VglXoiwqmgcrwI2U968bD0+wRQ5c5bzNoshJOzN6CTMh\n" | 150 | "KRuiU35tU7h7CPbL4L66VglXoiwqmgcrwI2U968bD0+wRQ5c5bzNoshJOzN6CTMh\n" |
151 | "1IhbklSh/Z6FA/e8hj0yVo2tdllXuJGVs3PIEwIDAQABAoIBAAEtcg+LFLGtoxjq\n" | 151 | "1IhbklSh/Z6FA/e8hj0yVo2tdllXuJGVs3PIEwIDAQABAoIBAAEtcg+LFLGtoxjq\n" |
152 | "b+tFttBJfbRcfdG6ocYqBGmUXF+MgFs573DHX3sHNOQxlaNHtSgIclF1eYgNZFFt\n" | 152 | "b+tFttBJfbRcfdG6ocYqBGmUXF+MgFs573DHX3sHNOQxlaNHtSgIclF1eYgNZFFt\n" |
153 | "VLIoBFTzfEQXoFosPUDoEuqVMeXLttmD7P2jwL780XJLZ4Xj6GY07npq1iGBcEZf\n" | 153 | "VLIoBFTzfEQXoFosPUDoEuqVMeXLttmD7P2jwL780XJLZ4Xj6GY07npq1iGBcEZf\n" |
154 | "yCcdoyGkr9jgc5Auyis8DStGg/jfUBC4NBvF0GnuuNPAdYRPKUpKw9EatI+FdMjy\n" | 154 | "yCcdoyGkr9jgc5Auyis8DStGg/jfUBC4NBvF0GnuuNPAdYRPKUpKw9EatI+FdMjy\n" |
155 | "BuroD90fhdkK8EwMEVb9P17bdIc1MCIZFpUE9YHjVdK/oxCUhQ8KRfdbI4JU5Zh3\n" | 155 | "BuroD90fhdkK8EwMEVb9P17bdIc1MCIZFpUE9YHjVdK/oxCUhQ8KRfdbI4JU5Zh3\n" |
156 | "UtO6Jm2wFuP3VmeVpPvE/C2rxI70pyl6HMSiFGNc0rhJYCQ+yhohWj7nZ67H4vLx\n" | 156 | "UtO6Jm2wFuP3VmeVpPvE/C2rxI70pyl6HMSiFGNc0rhJYCQ+yhohWj7nZ67H4vLx\n" |
157 | "plv5LxkCgYEAz7ewou8oFafDAMNoxaqKudvUg+lxXewdLDKaYBF5ACi9uAPCJ+v7\n" | 157 | "plv5LxkCgYEAz7ewou8oFafDAMNoxaqKudvUg+lxXewdLDKaYBF5ACi9uAPCJ+v7\n" |
158 | "M5c/fvPFn/XHzo7xaXbtTAH3Z5xzBs+80OsvL+e1Ut4xR+ELRkybknh/s2wQeABk\n" | 158 | "M5c/fvPFn/XHzo7xaXbtTAH3Z5xzBs+80OsvL+e1Ut4xR+ELRkybknh/s2wQeABk\n" |
159 | "Kb0vA59ukQGj12LV5phZMaVoXe6KJ7hZnN62d3K6m1wGE/k58i4pPLUCgYEA3hN8\n" | 159 | "Kb0vA59ukQGj12LV5phZMaVoXe6KJ7hZnN62d3K6m1wGE/k58i4pPLUCgYEA3hN8\n" |
160 | "G95zW7g0jVdSr+KUeVmephph9yh8Yb+3I3ojwOIv6d45TopGx8pFZlnBAMZf1ZQx\n" | 160 | "G95zW7g0jVdSr+KUeVmephph9yh8Yb+3I3ojwOIv6d45TopGx8pFZlnBAMZf1ZQx\n" |
161 | "DIhzJNnaqZy/4w7RNaOGWnPA/5f+MIoHBiLGEEmfHC3lt087Yp9OuwDUHwpETYdV\n" | 161 | "DIhzJNnaqZy/4w7RNaOGWnPA/5f+MIoHBiLGEEmfHC3lt087Yp9OuwDUHwpETYdV\n" |
162 | "o+KBCvVh60Et3bZUgF/1k/3YXxn8J5dsmJsjNqcCgYBLflyRa1BrRnTGMz9CEDCp\n" | 162 | "o+KBCvVh60Et3bZUgF/1k/3YXxn8J5dsmJsjNqcCgYBLflyRa1BrRnTGMz9CEDCp\n" |
163 | "Si9b3h1Y4Hbd2GppHhCXMTd6yMrpDYhYANGQB3M9Juv+s88j4JhwNoq/uonH4Pqk\n" | 163 | "Si9b3h1Y4Hbd2GppHhCXMTd6yMrpDYhYANGQB3M9Juv+s88j4JhwNoq/uonH4Pqk\n" |
164 | "B8Y3qAQr4RuSH0WkwDUOsALhqBX4N1QwI1USAQEDbNAqeP5698X7GD3tXcQSmZrg\n" | 164 | "B8Y3qAQr4RuSH0WkwDUOsALhqBX4N1QwI1USAQEDbNAqeP5698X7GD3tXcQSmZrg\n" |
165 | "O8WfdjBCRNjkq4EW9xX/vQKBgQDONtmwJ0iHiu2BseyeVo/4fzfKlgUSNQ4K1rOA\n" | 165 | "O8WfdjBCRNjkq4EW9xX/vQKBgQDONtmwJ0iHiu2BseyeVo/4fzfKlgUSNQ4K1rOA\n" |
166 | "xhIdMeu8Bxa/z7caHsGC4SVPSuYCtbE2Kh6BwapChcPJXCD45fgEViiJLuJiwEj1\n" | 166 | "xhIdMeu8Bxa/z7caHsGC4SVPSuYCtbE2Kh6BwapChcPJXCD45fgEViiJLuJiwEj1\n" |
167 | "caTpyvNsf1IoffJvCe9ZxtMyX549P8ZOgC3Dt0hN5CBrGLwu2Ox5l+YrqT10pi+5\n" | 167 | "caTpyvNsf1IoffJvCe9ZxtMyX549P8ZOgC3Dt0hN5CBrGLwu2Ox5l+YrqT10pi+5\n" |
168 | "JZX1UQKBgQCrcXrdkkDAc/a4+PxNRpJRLcU4fhv8/lr+UWItE8eUe7bd25bTQfQm\n" | 168 | "JZX1UQKBgQCrcXrdkkDAc/a4+PxNRpJRLcU4fhv8/lr+UWItE8eUe7bd25bTQfQm\n" |
169 | "VpNKc/kAJ66PjIED6fy3ADhd2y4naT2a24uAgQ/M494J68qLnGh6K4JU/09uxR2v\n" | 169 | "VpNKc/kAJ66PjIED6fy3ADhd2y4naT2a24uAgQ/M494J68qLnGh6K4JU/09uxR2v\n" |
170 | "1i2q/4FNLdFFk1XP4iNnTHRLZ+NYr2p5Y9RcvQfTjOauz8Ahav0lyg==\n" | 170 | "1i2q/4FNLdFFk1XP4iNnTHRLZ+NYr2p5Y9RcvQfTjOauz8Ahav0lyg==\n" |
171 | "-----END RSA PRIVATE KEY-----\n"; | 171 | "-----END RSA PRIVATE KEY-----\n"; |
172 | 172 | ||
173 | #endif | 173 | #endif |
diff --git a/src/testcurl/mhd_has_in_name.h b/src/testcurl/mhd_has_in_name.h index 50f32cca..aff15e15 100644 --- a/src/testcurl/mhd_has_in_name.h +++ b/src/testcurl/mhd_has_in_name.h | |||
@@ -39,27 +39,27 @@ | |||
39 | * name. | 39 | * name. |
40 | */ | 40 | */ |
41 | static int | 41 | static int |
42 | has_in_name(const char *prog_name, const char *marker) | 42 | has_in_name (const char *prog_name, const char *marker) |
43 | { | 43 | { |
44 | size_t name_pos; | 44 | size_t name_pos; |
45 | size_t pos; | 45 | size_t pos; |
46 | 46 | ||
47 | if (!prog_name || !marker || !prog_name[0] || !marker[0]) | 47 | if (! prog_name || ! marker || ! prog_name[0] || ! marker[0]) |
48 | return 0; | 48 | return 0; |
49 | 49 | ||
50 | pos = 0; | 50 | pos = 0; |
51 | name_pos = 0; | 51 | name_pos = 0; |
52 | while (prog_name[pos]) | 52 | while (prog_name[pos]) |
53 | { | 53 | { |
54 | if ('/' == prog_name[pos]) | 54 | if ('/' == prog_name[pos]) |
55 | name_pos = pos + 1; | 55 | name_pos = pos + 1; |
56 | #if defined(_WIN32) || defined(__CYGWIN__) | 56 | #if defined(_WIN32) || defined(__CYGWIN__) |
57 | else if ('\\' == prog_name[pos]) | 57 | else if ('\\' == prog_name[pos]) |
58 | name_pos = pos + 1; | 58 | name_pos = pos + 1; |
59 | #endif /* _WIN32 || __CYGWIN__ */ | 59 | #endif /* _WIN32 || __CYGWIN__ */ |
60 | pos++; | 60 | pos++; |
61 | } | 61 | } |
62 | if (name_pos == pos) | 62 | if (name_pos == pos) |
63 | return 0; | 63 | return 0; |
64 | return strstr(prog_name + name_pos, marker) != (char*)0; | 64 | return strstr (prog_name + name_pos, marker) != (char*) 0; |
65 | } | 65 | } |
diff --git a/src/testcurl/perf_get.c b/src/testcurl/perf_get.c index a0af70cd..112046d5 100644 --- a/src/testcurl/perf_get.c +++ b/src/testcurl/perf_get.c | |||
@@ -51,10 +51,10 @@ | |||
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 54 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
55 | #undef CPU_COUNT | 55 | #undef CPU_COUNT |
56 | #endif | 56 | #endif |
57 | #if !defined(CPU_COUNT) | 57 | #if ! defined(CPU_COUNT) |
58 | #define CPU_COUNT 2 | 58 | #define CPU_COUNT 2 |
59 | #endif | 59 | #endif |
60 | 60 | ||
@@ -91,8 +91,8 @@ now () | |||
91 | struct timeval tv; | 91 | struct timeval tv; |
92 | 92 | ||
93 | gettimeofday (&tv, NULL); | 93 | gettimeofday (&tv, NULL); |
94 | return (((unsigned long long) tv.tv_sec * 1000LL) + | 94 | return (((unsigned long long) tv.tv_sec * 1000LL) |
95 | ((unsigned long long) tv.tv_usec / 1000LL)); | 95 | + ((unsigned long long) tv.tv_usec / 1000LL)); |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
@@ -100,7 +100,7 @@ now () | |||
100 | * Start the timer. | 100 | * Start the timer. |
101 | */ | 101 | */ |
102 | static void | 102 | static void |
103 | start_timer() | 103 | start_timer () |
104 | { | 104 | { |
105 | start_time = now (); | 105 | start_time = now (); |
106 | } | 106 | } |
@@ -114,17 +114,17 @@ start_timer() | |||
114 | static void | 114 | static void |
115 | stop (const char *desc) | 115 | stop (const char *desc) |
116 | { | 116 | { |
117 | double rps = ((double) (ROUNDS * 1000)) / ((double) (now() - start_time)); | 117 | double rps = ((double) (ROUNDS * 1000)) / ((double) (now () - start_time)); |
118 | 118 | ||
119 | fprintf (stderr, | 119 | fprintf (stderr, |
120 | "Sequential GETs using %s: %f %s\n", | 120 | "Sequential GETs using %s: %f %s\n", |
121 | desc, | 121 | desc, |
122 | rps, | 122 | rps, |
123 | "requests/s"); | 123 | "requests/s"); |
124 | GAUGER (desc, | 124 | GAUGER (desc, |
125 | "Sequential GETs", | 125 | "Sequential GETs", |
126 | rps, | 126 | rps, |
127 | "requests/s"); | 127 | "requests/s"); |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
@@ -138,8 +138,8 @@ struct CBC | |||
138 | 138 | ||
139 | static size_t | 139 | static size_t |
140 | copyBuffer (void *ptr, | 140 | copyBuffer (void *ptr, |
141 | size_t size, size_t nmemb, | 141 | size_t size, size_t nmemb, |
142 | void *ctx) | 142 | void *ctx) |
143 | { | 143 | { |
144 | struct CBC *cbc = ctx; | 144 | struct CBC *cbc = ctx; |
145 | 145 | ||
@@ -162,16 +162,16 @@ ahc_echo (void *cls, | |||
162 | static int ptr; | 162 | static int ptr; |
163 | const char *me = cls; | 163 | const char *me = cls; |
164 | int ret; | 164 | int ret; |
165 | (void)url;(void)version; /* Unused. Silent compiler warning. */ | 165 | (void) url; (void) version; /* Unused. Silent compiler warning. */ |
166 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 166 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
167 | 167 | ||
168 | if (0 != strcmp (me, method)) | 168 | if (0 != strcmp (me, method)) |
169 | return MHD_NO; /* unexpected method */ | 169 | return MHD_NO; /* unexpected method */ |
170 | if (&ptr != *unused) | 170 | if (&ptr != *unused) |
171 | { | 171 | { |
172 | *unused = &ptr; | 172 | *unused = &ptr; |
173 | return MHD_YES; | 173 | return MHD_YES; |
174 | } | 174 | } |
175 | *unused = NULL; | 175 | *unused = NULL; |
176 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 176 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
177 | if (ret == MHD_NO) | 177 | if (ret == MHD_NO) |
@@ -191,60 +191,64 @@ testInternalGet (int port, int poll_flag) | |||
191 | unsigned int i; | 191 | unsigned int i; |
192 | char url[64]; | 192 | char url[64]; |
193 | 193 | ||
194 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 194 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
195 | port = 0; | 195 | port = 0; |
196 | 196 | ||
197 | cbc.buf = buf; | 197 | cbc.buf = buf; |
198 | cbc.size = 2048; | 198 | cbc.size = 2048; |
199 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 199 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
200 | | poll_flag, | ||
200 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 201 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
201 | if (d == NULL) | 202 | if (d == NULL) |
202 | return 1; | 203 | return 1; |
203 | if (0 == port) | 204 | if (0 == port) |
205 | { | ||
206 | const union MHD_DaemonInfo *dinfo; | ||
207 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
208 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
204 | { | 209 | { |
205 | const union MHD_DaemonInfo *dinfo; | 210 | MHD_stop_daemon (d); return 32; |
206 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
207 | if (NULL == dinfo || 0 == dinfo->port) | ||
208 | { MHD_stop_daemon (d); return 32; } | ||
209 | port = (int)dinfo->port; | ||
210 | } | 211 | } |
212 | port = (int) dinfo->port; | ||
213 | } | ||
211 | snprintf (url, | 214 | snprintf (url, |
212 | sizeof (url), | 215 | sizeof (url), |
213 | "http://127.0.0.1:%d/hello_world", | 216 | "http://127.0.0.1:%d/hello_world", |
214 | port); | 217 | port); |
215 | start_timer (); | 218 | start_timer (); |
216 | for (i=0;i<ROUNDS;i++) | 219 | for (i = 0; i<ROUNDS; i++) |
220 | { | ||
221 | cbc.pos = 0; | ||
222 | c = curl_easy_init (); | ||
223 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
224 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
225 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
226 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
227 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
228 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
229 | if (oneone) | ||
230 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
231 | else | ||
232 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
233 | /* NOTE: use of CONNECTTIMEOUT without also | ||
234 | setting NOSIGNAL results in really weird | ||
235 | crashes on my system!*/ | ||
236 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
237 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
217 | { | 238 | { |
218 | cbc.pos = 0; | 239 | fprintf (stderr, |
219 | c = curl_easy_init (); | 240 | "curl_easy_perform failed: `%s'\n", |
220 | curl_easy_setopt (c, CURLOPT_URL, url); | 241 | curl_easy_strerror (errornum)); |
221 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
222 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
223 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
224 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
225 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
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 | /* NOTE: use of CONNECTTIMEOUT without also | ||
231 | setting NOSIGNAL results in really weird | ||
232 | crashes on my system!*/ | ||
233 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
234 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
235 | { | ||
236 | fprintf (stderr, | ||
237 | "curl_easy_perform failed: `%s'\n", | ||
238 | curl_easy_strerror (errornum)); | ||
239 | curl_easy_cleanup (c); | ||
240 | MHD_stop_daemon (d); | ||
241 | return 2; | ||
242 | } | ||
243 | curl_easy_cleanup (c); | 242 | curl_easy_cleanup (c); |
243 | MHD_stop_daemon (d); | ||
244 | return 2; | ||
244 | } | 245 | } |
246 | curl_easy_cleanup (c); | ||
247 | } | ||
245 | stop (poll_flag == MHD_USE_AUTO ? "internal thread with 'auto'" : | 248 | stop (poll_flag == MHD_USE_AUTO ? "internal thread with 'auto'" : |
246 | poll_flag == MHD_USE_POLL ? "internal thread with poll()" : | 249 | poll_flag == MHD_USE_POLL ? "internal thread with poll()" : |
247 | poll_flag == MHD_USE_EPOLL ? "internal thread with epoll" : "internal thread with select()"); | 250 | poll_flag == MHD_USE_EPOLL ? "internal thread with epoll" : |
251 | "internal thread with select()"); | ||
248 | MHD_stop_daemon (d); | 252 | MHD_stop_daemon (d); |
249 | if (cbc.pos != strlen ("/hello_world")) | 253 | if (cbc.pos != strlen ("/hello_world")) |
250 | return 4; | 254 | return 4; |
@@ -265,61 +269,68 @@ testMultithreadedGet (int port, int poll_flag) | |||
265 | unsigned int i; | 269 | unsigned int i; |
266 | char url[64]; | 270 | char url[64]; |
267 | 271 | ||
268 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 272 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
269 | port = 0; | 273 | port = 0; |
270 | 274 | ||
271 | cbc.buf = buf; | 275 | cbc.buf = buf; |
272 | cbc.size = 2048; | 276 | cbc.size = 2048; |
273 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 277 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
278 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | ||
279 | | poll_flag, | ||
274 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 280 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
275 | if (d == NULL) | 281 | if (d == NULL) |
276 | return 16; | 282 | return 16; |
277 | if (0 == port) | 283 | if (0 == port) |
284 | { | ||
285 | const union MHD_DaemonInfo *dinfo; | ||
286 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
287 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
278 | { | 288 | { |
279 | const union MHD_DaemonInfo *dinfo; | 289 | MHD_stop_daemon (d); return 32; |
280 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
281 | if (NULL == dinfo || 0 == dinfo->port) | ||
282 | { MHD_stop_daemon (d); return 32; } | ||
283 | port = (int)dinfo->port; | ||
284 | } | 290 | } |
291 | port = (int) dinfo->port; | ||
292 | } | ||
285 | snprintf (url, | 293 | snprintf (url, |
286 | sizeof (url), | 294 | sizeof (url), |
287 | "http://127.0.0.1:%d/hello_world", | 295 | "http://127.0.0.1:%d/hello_world", |
288 | port); | 296 | port); |
289 | start_timer (); | 297 | start_timer (); |
290 | for (i=0;i<ROUNDS;i++) | 298 | for (i = 0; i<ROUNDS; i++) |
299 | { | ||
300 | cbc.pos = 0; | ||
301 | c = curl_easy_init (); | ||
302 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
303 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
304 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
305 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
306 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
307 | if (oneone) | ||
308 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
309 | else | ||
310 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
311 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
312 | /* NOTE: use of CONNECTTIMEOUT without also | ||
313 | setting NOSIGNAL results in really weird | ||
314 | crashes on my system! */ | ||
315 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
316 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
291 | { | 317 | { |
292 | cbc.pos = 0; | 318 | fprintf (stderr, |
293 | c = curl_easy_init (); | 319 | "curl_easy_perform failed: `%s'\n", |
294 | curl_easy_setopt (c, CURLOPT_URL, url); | 320 | curl_easy_strerror (errornum)); |
295 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
296 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
297 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
298 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
299 | if (oneone) | ||
300 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
301 | else | ||
302 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
303 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
304 | /* NOTE: use of CONNECTTIMEOUT without also | ||
305 | setting NOSIGNAL results in really weird | ||
306 | crashes on my system! */ | ||
307 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
308 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
309 | { | ||
310 | fprintf (stderr, | ||
311 | "curl_easy_perform failed: `%s'\n", | ||
312 | curl_easy_strerror (errornum)); | ||
313 | curl_easy_cleanup (c); | ||
314 | MHD_stop_daemon (d); | ||
315 | return 32; | ||
316 | } | ||
317 | curl_easy_cleanup (c); | 321 | curl_easy_cleanup (c); |
322 | MHD_stop_daemon (d); | ||
323 | return 32; | ||
318 | } | 324 | } |
319 | stop ((poll_flag & MHD_USE_AUTO) ? "internal thread with 'auto' and thread per connection" : | 325 | curl_easy_cleanup (c); |
320 | (poll_flag & MHD_USE_POLL) ? "internal thread with poll() and thread per connection" : | 326 | } |
321 | (poll_flag & MHD_USE_EPOLL) ? "internal thread with epoll and thread per connection" : | 327 | stop ((poll_flag & MHD_USE_AUTO) ? |
322 | "internal thread with select() and thread per connection"); | 328 | "internal thread with 'auto' and thread per connection" : |
329 | (poll_flag & MHD_USE_POLL) ? | ||
330 | "internal thread with poll() and thread per connection" : | ||
331 | (poll_flag & MHD_USE_EPOLL) ? | ||
332 | "internal thread with epoll and thread per connection" : | ||
333 | "internal thread with select() and thread per connection"); | ||
323 | MHD_stop_daemon (d); | 334 | MHD_stop_daemon (d); |
324 | if (cbc.pos != strlen ("/hello_world")) | 335 | if (cbc.pos != strlen ("/hello_world")) |
325 | return 64; | 336 | return 64; |
@@ -339,61 +350,65 @@ testMultithreadedPoolGet (int port, int poll_flag) | |||
339 | unsigned int i; | 350 | unsigned int i; |
340 | char url[64]; | 351 | char url[64]; |
341 | 352 | ||
342 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 353 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
343 | port = 0; | 354 | port = 0; |
344 | 355 | ||
345 | cbc.buf = buf; | 356 | cbc.buf = buf; |
346 | cbc.size = 2048; | 357 | cbc.size = 2048; |
347 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 358 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
359 | | poll_flag, | ||
348 | port, NULL, NULL, &ahc_echo, "GET", | 360 | port, NULL, NULL, &ahc_echo, "GET", |
349 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); | 361 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); |
350 | if (d == NULL) | 362 | if (d == NULL) |
351 | return 16; | 363 | return 16; |
352 | if (0 == port) | 364 | if (0 == port) |
365 | { | ||
366 | const union MHD_DaemonInfo *dinfo; | ||
367 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
368 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
353 | { | 369 | { |
354 | const union MHD_DaemonInfo *dinfo; | 370 | MHD_stop_daemon (d); return 32; |
355 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
356 | if (NULL == dinfo || 0 == dinfo->port) | ||
357 | { MHD_stop_daemon (d); return 32; } | ||
358 | port = (int)dinfo->port; | ||
359 | } | 371 | } |
372 | port = (int) dinfo->port; | ||
373 | } | ||
360 | snprintf (url, | 374 | snprintf (url, |
361 | sizeof (url), | 375 | sizeof (url), |
362 | "http://127.0.0.1:%d/hello_world", | 376 | "http://127.0.0.1:%d/hello_world", |
363 | port); | 377 | port); |
364 | start_timer (); | 378 | start_timer (); |
365 | for (i=0;i<ROUNDS;i++) | 379 | for (i = 0; i<ROUNDS; i++) |
380 | { | ||
381 | cbc.pos = 0; | ||
382 | c = curl_easy_init (); | ||
383 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
384 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
385 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
386 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
387 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
388 | if (oneone) | ||
389 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
390 | else | ||
391 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
392 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
393 | /* NOTE: use of CONNECTTIMEOUT without also | ||
394 | setting NOSIGNAL results in really weird | ||
395 | crashes on my system!*/ | ||
396 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
397 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
366 | { | 398 | { |
367 | cbc.pos = 0; | 399 | fprintf (stderr, |
368 | c = curl_easy_init (); | 400 | "curl_easy_perform failed: `%s'\n", |
369 | curl_easy_setopt (c, CURLOPT_URL, url); | 401 | curl_easy_strerror (errornum)); |
370 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
371 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
372 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
373 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
374 | if (oneone) | ||
375 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
376 | else | ||
377 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
378 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
379 | /* NOTE: use of CONNECTTIMEOUT without also | ||
380 | setting NOSIGNAL results in really weird | ||
381 | crashes on my system!*/ | ||
382 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
383 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
384 | { | ||
385 | fprintf (stderr, | ||
386 | "curl_easy_perform failed: `%s'\n", | ||
387 | curl_easy_strerror (errornum)); | ||
388 | curl_easy_cleanup (c); | ||
389 | MHD_stop_daemon (d); | ||
390 | return 32; | ||
391 | } | ||
392 | curl_easy_cleanup (c); | 402 | curl_easy_cleanup (c); |
403 | MHD_stop_daemon (d); | ||
404 | return 32; | ||
393 | } | 405 | } |
406 | curl_easy_cleanup (c); | ||
407 | } | ||
394 | stop (0 != (poll_flag & MHD_USE_AUTO) ? "internal thread pool with 'auto'" : | 408 | stop (0 != (poll_flag & MHD_USE_AUTO) ? "internal thread pool with 'auto'" : |
395 | 0 != (poll_flag & MHD_USE_POLL) ? "internal thread pool with poll()" : | 409 | 0 != (poll_flag & MHD_USE_POLL) ? "internal thread pool with poll()" : |
396 | 0 != (poll_flag & MHD_USE_EPOLL) ? "internal thread pool with epoll" : "internal thread pool with select()"); | 410 | 0 != (poll_flag & MHD_USE_EPOLL) ? "internal thread pool with epoll" : |
411 | "internal thread pool with select()"); | ||
397 | MHD_stop_daemon (d); | 412 | MHD_stop_daemon (d); |
398 | if (cbc.pos != strlen ("/hello_world")) | 413 | if (cbc.pos != strlen ("/hello_world")) |
399 | return 64; | 414 | return 64; |
@@ -427,7 +442,7 @@ testExternalGet (int port) | |||
427 | unsigned int i; | 442 | unsigned int i; |
428 | char url[64]; | 443 | char url[64]; |
429 | 444 | ||
430 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 445 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
431 | port = 0; | 446 | port = 0; |
432 | 447 | ||
433 | multi = NULL; | 448 | multi = NULL; |
@@ -440,13 +455,15 @@ testExternalGet (int port) | |||
440 | if (NULL == d) | 455 | if (NULL == d) |
441 | return 256; | 456 | return 256; |
442 | if (0 == port) | 457 | if (0 == port) |
458 | { | ||
459 | const union MHD_DaemonInfo *dinfo; | ||
460 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
461 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
443 | { | 462 | { |
444 | const union MHD_DaemonInfo *dinfo; | 463 | MHD_stop_daemon (d); return 32; |
445 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
446 | if (NULL == dinfo || 0 == dinfo->port) | ||
447 | { MHD_stop_daemon (d); return 32; } | ||
448 | port = (int)dinfo->port; | ||
449 | } | 464 | } |
465 | port = (int) dinfo->port; | ||
466 | } | ||
450 | snprintf (url, | 467 | snprintf (url, |
451 | sizeof (url), | 468 | sizeof (url), |
452 | "http://127.0.0.1:%d/hello_world", | 469 | "http://127.0.0.1:%d/hello_world", |
@@ -454,116 +471,119 @@ testExternalGet (int port) | |||
454 | start_timer (); | 471 | start_timer (); |
455 | multi = curl_multi_init (); | 472 | multi = curl_multi_init (); |
456 | if (multi == NULL) | 473 | if (multi == NULL) |
474 | { | ||
475 | MHD_stop_daemon (d); | ||
476 | return 512; | ||
477 | } | ||
478 | for (i = 0; i<ROUNDS; i++) | ||
479 | { | ||
480 | cbc.pos = 0; | ||
481 | c = curl_easy_init (); | ||
482 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
483 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
484 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
485 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
486 | if (oneone) | ||
487 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
488 | else | ||
489 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
490 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
491 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
492 | /* NOTE: use of CONNECTTIMEOUT without also | ||
493 | setting NOSIGNAL results in really weird | ||
494 | crashes on my system! */ | ||
495 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
496 | mret = curl_multi_add_handle (multi, c); | ||
497 | if (mret != CURLM_OK) | ||
457 | { | 498 | { |
499 | curl_multi_cleanup (multi); | ||
500 | curl_easy_cleanup (c); | ||
458 | MHD_stop_daemon (d); | 501 | MHD_stop_daemon (d); |
459 | return 512; | 502 | return 1024; |
460 | } | 503 | } |
461 | for (i=0;i<ROUNDS;i++) | 504 | start = time (NULL); |
505 | while ((time (NULL) - start < 5) && (c != NULL)) | ||
462 | { | 506 | { |
463 | cbc.pos = 0; | 507 | maxsock = MHD_INVALID_SOCKET; |
464 | c = curl_easy_init (); | 508 | maxposixs = -1; |
465 | curl_easy_setopt (c, CURLOPT_URL, url); | 509 | FD_ZERO (&rs); |
466 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 510 | FD_ZERO (&ws); |
467 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 511 | FD_ZERO (&es); |
468 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 512 | curl_multi_perform (multi, &running); |
469 | if (oneone) | 513 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); |
470 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
471 | else | ||
472 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
473 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
474 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
475 | /* NOTE: use of CONNECTTIMEOUT without also | ||
476 | setting NOSIGNAL results in really weird | ||
477 | crashes on my system! */ | ||
478 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
479 | mret = curl_multi_add_handle (multi, c); | ||
480 | if (mret != CURLM_OK) | 514 | if (mret != CURLM_OK) |
481 | { | 515 | { |
482 | curl_multi_cleanup (multi); | 516 | curl_multi_remove_handle (multi, c); |
483 | curl_easy_cleanup (c); | 517 | curl_multi_cleanup (multi); |
484 | MHD_stop_daemon (d); | 518 | curl_easy_cleanup (c); |
485 | return 1024; | 519 | MHD_stop_daemon (d); |
486 | } | 520 | return 2048; |
487 | start = time (NULL); | 521 | } |
488 | while ((time (NULL) - start < 5) && (c != NULL)) | 522 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
489 | { | 523 | { |
490 | maxsock = MHD_INVALID_SOCKET; | 524 | curl_multi_remove_handle (multi, c); |
491 | maxposixs = -1; | 525 | curl_multi_cleanup (multi); |
492 | FD_ZERO (&rs); | 526 | curl_easy_cleanup (c); |
493 | FD_ZERO (&ws); | 527 | MHD_stop_daemon (d); |
494 | FD_ZERO (&es); | 528 | return 4096; |
495 | curl_multi_perform (multi, &running); | 529 | } |
496 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | 530 | tv.tv_sec = 0; |
497 | if (mret != CURLM_OK) | 531 | tv.tv_usec = 1000; |
498 | { | 532 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) |
499 | curl_multi_remove_handle (multi, c); | 533 | { |
500 | curl_multi_cleanup (multi); | ||
501 | curl_easy_cleanup (c); | ||
502 | MHD_stop_daemon (d); | ||
503 | return 2048; | ||
504 | } | ||
505 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
506 | { | ||
507 | curl_multi_remove_handle (multi, c); | ||
508 | curl_multi_cleanup (multi); | ||
509 | curl_easy_cleanup (c); | ||
510 | MHD_stop_daemon (d); | ||
511 | return 4096; | ||
512 | } | ||
513 | tv.tv_sec = 0; | ||
514 | tv.tv_usec = 1000; | ||
515 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
516 | { | ||
517 | #ifdef MHD_POSIX_SOCKETS | 534 | #ifdef MHD_POSIX_SOCKETS |
518 | if (EINTR != errno) | 535 | if (EINTR != errno) |
519 | abort (); | 536 | abort (); |
520 | #else | 537 | #else |
521 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 538 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
522 | abort (); | 539 | ws. |
523 | Sleep (1000); | 540 | fd_count) |
541 | ||(0 != es.fd_count) ) | ||
542 | abort (); | ||
543 | Sleep (1000); | ||
524 | #endif | 544 | #endif |
525 | } | 545 | } |
526 | curl_multi_perform (multi, &running); | 546 | curl_multi_perform (multi, &running); |
527 | if (running == 0) | 547 | if (running == 0) |
528 | { | 548 | { |
529 | msg = curl_multi_info_read (multi, &running); | 549 | msg = curl_multi_info_read (multi, &running); |
530 | if (msg == NULL) | 550 | if (msg == NULL) |
531 | break; | 551 | break; |
532 | if (msg->msg == CURLMSG_DONE) | 552 | if (msg->msg == CURLMSG_DONE) |
533 | { | 553 | { |
534 | if (msg->data.result != CURLE_OK) | 554 | if (msg->data.result != CURLE_OK) |
535 | printf ("%s failed at %s:%d: `%s'\n", | 555 | printf ("%s failed at %s:%d: `%s'\n", |
536 | "curl_multi_perform", | 556 | "curl_multi_perform", |
537 | __FILE__, | 557 | __FILE__, |
538 | __LINE__, curl_easy_strerror (msg->data.result)); | 558 | __LINE__, curl_easy_strerror (msg->data.result)); |
539 | curl_multi_remove_handle (multi, c); | 559 | curl_multi_remove_handle (multi, c); |
540 | curl_easy_cleanup (c); | 560 | curl_easy_cleanup (c); |
541 | c = NULL; | 561 | c = NULL; |
542 | } | 562 | } |
543 | } | 563 | } |
544 | /* two possibilities here; as select sets are | 564 | /* two possibilities here; as select sets are |
545 | tiny, this makes virtually no difference | 565 | tiny, this makes virtually no difference |
546 | in actual runtime right now, even though the | 566 | in actual runtime right now, even though the |
547 | number of select calls is virtually cut in half | 567 | number of select calls is virtually cut in half |
548 | (and 'select' is the most expensive of our system | 568 | (and 'select' is the most expensive of our system |
549 | calls according to 'strace') */ | 569 | calls according to 'strace') */ |
550 | if (0) | 570 | if (0) |
551 | MHD_run (d); | 571 | MHD_run (d); |
552 | else | 572 | else |
553 | MHD_run_from_select (d, &rs, &ws, &es); | 573 | MHD_run_from_select (d, &rs, &ws, &es); |
554 | } | ||
555 | if (NULL != c) | ||
556 | { | ||
557 | curl_multi_remove_handle (multi, c); | ||
558 | curl_easy_cleanup (c); | ||
559 | fprintf (stderr, "Timeout!?\n"); | ||
560 | } | ||
561 | } | 574 | } |
562 | stop ("external select"); | 575 | if (NULL != c) |
563 | if (multi != NULL) | ||
564 | { | 576 | { |
565 | curl_multi_cleanup (multi); | 577 | curl_multi_remove_handle (multi, c); |
578 | curl_easy_cleanup (c); | ||
579 | fprintf (stderr, "Timeout!?\n"); | ||
566 | } | 580 | } |
581 | } | ||
582 | stop ("external select"); | ||
583 | if (multi != NULL) | ||
584 | { | ||
585 | curl_multi_cleanup (multi); | ||
586 | } | ||
567 | MHD_stop_daemon (d); | 587 | MHD_stop_daemon (d); |
568 | if (cbc.pos != strlen ("/hello_world")) | 588 | if (cbc.pos != strlen ("/hello_world")) |
569 | return 8192; | 589 | return 8192; |
@@ -578,9 +598,9 @@ main (int argc, char *const *argv) | |||
578 | { | 598 | { |
579 | unsigned int errorCount = 0; | 599 | unsigned int errorCount = 0; |
580 | int port = 1130; | 600 | int port = 1130; |
581 | (void)argc; /* Unused. Silent compiler warning. */ | 601 | (void) argc; /* Unused. Silent compiler warning. */ |
582 | 602 | ||
583 | if (NULL == argv || 0 == argv[0]) | 603 | if ((NULL == argv)||(0 == argv[0])) |
584 | return 99; | 604 | return 99; |
585 | oneone = has_in_name (argv[0], "11"); | 605 | oneone = has_in_name (argv[0], "11"); |
586 | if (oneone) | 606 | if (oneone) |
@@ -588,29 +608,29 @@ main (int argc, char *const *argv) | |||
588 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 608 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
589 | return 2; | 609 | return 2; |
590 | response = MHD_create_response_from_buffer (strlen ("/hello_world"), | 610 | response = MHD_create_response_from_buffer (strlen ("/hello_world"), |
591 | "/hello_world", | 611 | "/hello_world", |
592 | MHD_RESPMEM_MUST_COPY); | 612 | MHD_RESPMEM_MUST_COPY); |
593 | errorCount += testExternalGet (port++); | 613 | errorCount += testExternalGet (port++); |
594 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 614 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
615 | { | ||
616 | errorCount += testInternalGet (port++, MHD_USE_AUTO); | ||
617 | errorCount += testMultithreadedGet (port++, MHD_USE_AUTO); | ||
618 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO); | ||
619 | errorCount += testInternalGet (port++, 0); | ||
620 | errorCount += testMultithreadedGet (port++, 0); | ||
621 | errorCount += testMultithreadedPoolGet (port++, 0); | ||
622 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL)) | ||
623 | { | ||
624 | errorCount += testInternalGet (port++, MHD_USE_POLL); | ||
625 | errorCount += testMultithreadedGet (port++, MHD_USE_POLL); | ||
626 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_POLL); | ||
627 | } | ||
628 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL)) | ||
595 | { | 629 | { |
596 | errorCount += testInternalGet (port++, MHD_USE_AUTO); | 630 | errorCount += testInternalGet (port++, MHD_USE_EPOLL); |
597 | errorCount += testMultithreadedGet (port++, MHD_USE_AUTO); | 631 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_EPOLL); |
598 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO); | ||
599 | errorCount += testInternalGet (port++, 0); | ||
600 | errorCount += testMultithreadedGet (port++, 0); | ||
601 | errorCount += testMultithreadedPoolGet (port++, 0); | ||
602 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL)) | ||
603 | { | ||
604 | errorCount += testInternalGet(port++, MHD_USE_POLL); | ||
605 | errorCount += testMultithreadedGet(port++, MHD_USE_POLL); | ||
606 | errorCount += testMultithreadedPoolGet(port++, MHD_USE_POLL); | ||
607 | } | ||
608 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL)) | ||
609 | { | ||
610 | errorCount += testInternalGet(port++, MHD_USE_EPOLL); | ||
611 | errorCount += testMultithreadedPoolGet(port++, MHD_USE_EPOLL); | ||
612 | } | ||
613 | } | 632 | } |
633 | } | ||
614 | MHD_destroy_response (response); | 634 | MHD_destroy_response (response); |
615 | if (errorCount != 0) | 635 | if (errorCount != 0) |
616 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 636 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/perf_get_concurrent.c b/src/testcurl/perf_get_concurrent.c index 336a1d1e..b4cd6d8d 100644 --- a/src/testcurl/perf_get_concurrent.c +++ b/src/testcurl/perf_get_concurrent.c | |||
@@ -43,10 +43,10 @@ | |||
43 | #include "gauger.h" | 43 | #include "gauger.h" |
44 | #include "mhd_has_in_name.h" | 44 | #include "mhd_has_in_name.h" |
45 | 45 | ||
46 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 46 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
47 | #undef CPU_COUNT | 47 | #undef CPU_COUNT |
48 | #endif | 48 | #endif |
49 | #if !defined(CPU_COUNT) | 49 | #if ! defined(CPU_COUNT) |
50 | #define CPU_COUNT 2 | 50 | #define CPU_COUNT 2 |
51 | #endif | 51 | #endif |
52 | 52 | ||
@@ -98,8 +98,8 @@ now () | |||
98 | struct timeval tv; | 98 | struct timeval tv; |
99 | 99 | ||
100 | gettimeofday (&tv, NULL); | 100 | gettimeofday (&tv, NULL); |
101 | return (((unsigned long long) tv.tv_sec * 1000LL) + | 101 | return (((unsigned long long) tv.tv_sec * 1000LL) |
102 | ((unsigned long long) tv.tv_usec / 1000LL)); | 102 | + ((unsigned long long) tv.tv_usec / 1000LL)); |
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
@@ -107,7 +107,7 @@ now () | |||
107 | * Start the timer. | 107 | * Start the timer. |
108 | */ | 108 | */ |
109 | static void | 109 | static void |
110 | start_timer() | 110 | start_timer () |
111 | { | 111 | { |
112 | start_time = now (); | 112 | start_time = now (); |
113 | } | 113 | } |
@@ -121,26 +121,27 @@ start_timer() | |||
121 | static void | 121 | static void |
122 | stop (const char *desc) | 122 | stop (const char *desc) |
123 | { | 123 | { |
124 | double rps = ((double) (PAR * ROUNDS * 1000)) / ((double) (now() - start_time)); | 124 | double rps = ((double) (PAR * ROUNDS * 1000)) / ((double) (now () |
125 | - start_time)); | ||
125 | 126 | ||
126 | fprintf (stderr, | 127 | fprintf (stderr, |
127 | "Parallel GETs using %s: %f %s\n", | 128 | "Parallel GETs using %s: %f %s\n", |
128 | desc, | 129 | desc, |
129 | rps, | 130 | rps, |
130 | "requests/s"); | 131 | "requests/s"); |
131 | GAUGER (desc, | 132 | GAUGER (desc, |
132 | "Parallel GETs", | 133 | "Parallel GETs", |
133 | rps, | 134 | rps, |
134 | "requests/s"); | 135 | "requests/s"); |
135 | } | 136 | } |
136 | 137 | ||
137 | 138 | ||
138 | static size_t | 139 | static size_t |
139 | copyBuffer (void *ptr, | 140 | copyBuffer (void *ptr, |
140 | size_t size, size_t nmemb, | 141 | size_t size, size_t nmemb, |
141 | void *ctx) | 142 | void *ctx) |
142 | { | 143 | { |
143 | (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ | 144 | (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */ |
144 | return size * nmemb; | 145 | return size * nmemb; |
145 | } | 146 | } |
146 | 147 | ||
@@ -157,16 +158,16 @@ ahc_echo (void *cls, | |||
157 | static int ptr; | 158 | static int ptr; |
158 | const char *me = cls; | 159 | const char *me = cls; |
159 | int ret; | 160 | int ret; |
160 | (void)url;(void)version; /* Unused. Silent compiler warning. */ | 161 | (void) url; (void) version; /* Unused. Silent compiler warning. */ |
161 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 162 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
162 | 163 | ||
163 | if (0 != strcmp (me, method)) | 164 | if (0 != strcmp (me, method)) |
164 | return MHD_NO; /* unexpected method */ | 165 | return MHD_NO; /* unexpected method */ |
165 | if (&ptr != *unused) | 166 | if (&ptr != *unused) |
166 | { | 167 | { |
167 | *unused = &ptr; | 168 | *unused = &ptr; |
168 | return MHD_YES; | 169 | return MHD_YES; |
169 | } | 170 | } |
170 | *unused = NULL; | 171 | *unused = NULL; |
171 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 172 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
172 | if (ret == MHD_NO) | 173 | if (ret == MHD_NO) |
@@ -181,7 +182,7 @@ thread_gets (void *param) | |||
181 | CURL *c; | 182 | CURL *c; |
182 | CURLcode errornum; | 183 | CURLcode errornum; |
183 | unsigned int i; | 184 | unsigned int i; |
184 | char * const url = (char*) param; | 185 | char *const url = (char*) param; |
185 | 186 | ||
186 | c = curl_easy_init (); | 187 | c = curl_easy_init (); |
187 | curl_easy_setopt (c, CURLOPT_URL, url); | 188 | curl_easy_setopt (c, CURLOPT_URL, url); |
@@ -198,17 +199,17 @@ thread_gets (void *param) | |||
198 | setting NOSIGNAL results in really weird | 199 | setting NOSIGNAL results in really weird |
199 | crashes on my system! */ | 200 | crashes on my system! */ |
200 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 201 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
201 | for (i=0;i<ROUNDS;i++) | 202 | for (i = 0; i<ROUNDS; i++) |
203 | { | ||
204 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
202 | { | 205 | { |
203 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 206 | fprintf (stderr, |
204 | { | 207 | "curl_easy_perform failed: `%s'\n", |
205 | fprintf (stderr, | 208 | curl_easy_strerror (errornum)); |
206 | "curl_easy_perform failed: `%s'\n", | 209 | curl_easy_cleanup (c); |
207 | curl_easy_strerror (errornum)); | 210 | return "curl error"; |
208 | curl_easy_cleanup (c); | ||
209 | return "curl error"; | ||
210 | } | ||
211 | } | 211 | } |
212 | } | ||
212 | curl_easy_cleanup (c); | 213 | curl_easy_cleanup (c); |
213 | 214 | ||
214 | return NULL; | 215 | return NULL; |
@@ -216,34 +217,34 @@ thread_gets (void *param) | |||
216 | 217 | ||
217 | 218 | ||
218 | static void * | 219 | static void * |
219 | do_gets (void * param) | 220 | do_gets (void *param) |
220 | { | 221 | { |
221 | int j; | 222 | int j; |
222 | pthread_t par[PAR]; | 223 | pthread_t par[PAR]; |
223 | char url[64]; | 224 | char url[64]; |
224 | int port = (int)(intptr_t)param; | 225 | int port = (int) (intptr_t) param; |
225 | char *err = NULL; | 226 | char *err = NULL; |
226 | 227 | ||
227 | snprintf (url, | 228 | snprintf (url, |
228 | sizeof (url), | 229 | sizeof (url), |
229 | "http://127.0.0.1:%d/hello_world", | 230 | "http://127.0.0.1:%d/hello_world", |
230 | port); | 231 | port); |
231 | for (j=0;j<PAR;j++) | 232 | for (j = 0; j<PAR; j++) |
232 | { | 233 | { |
233 | if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url)) | 234 | if (0 != pthread_create (&par[j], NULL, &thread_gets, (void*) url)) |
234 | { | ||
235 | for (j--; j >= 0; j--) | ||
236 | pthread_join(par[j], NULL); | ||
237 | return "pthread_create error"; | ||
238 | } | ||
239 | } | ||
240 | for (j=0;j<PAR;j++) | ||
241 | { | 235 | { |
242 | char *ret_val; | 236 | for (j--; j >= 0; j--) |
243 | if (0 != pthread_join(par[j], (void**)&ret_val) || | 237 | pthread_join (par[j], NULL); |
244 | NULL != ret_val) | 238 | return "pthread_create error"; |
245 | err = ret_val; | ||
246 | } | 239 | } |
240 | } | ||
241 | for (j = 0; j<PAR; j++) | ||
242 | { | ||
243 | char *ret_val; | ||
244 | if ((0 != pthread_join (par[j], (void**) &ret_val)) || | ||
245 | (NULL != ret_val) ) | ||
246 | err = ret_val; | ||
247 | } | ||
247 | signal_done = 1; | 248 | signal_done = 1; |
248 | return err; | 249 | return err; |
249 | } | 250 | } |
@@ -253,38 +254,45 @@ static int | |||
253 | testInternalGet (int port, int poll_flag) | 254 | testInternalGet (int port, int poll_flag) |
254 | { | 255 | { |
255 | struct MHD_Daemon *d; | 256 | struct MHD_Daemon *d; |
256 | const char * const test_desc = ((poll_flag & MHD_USE_AUTO) ? "internal thread with 'auto'" : | 257 | const char *const test_desc = ((poll_flag & MHD_USE_AUTO) ? |
257 | (poll_flag & MHD_USE_POLL) ? "internal thread with poll()" : | 258 | "internal thread with 'auto'" : |
258 | (poll_flag & MHD_USE_EPOLL) ? "internal thread with epoll" : "internal thread with select()"); | 259 | (poll_flag & MHD_USE_POLL) ? |
259 | const char * ret_val; | 260 | "internal thread with poll()" : |
260 | 261 | (poll_flag & MHD_USE_EPOLL) ? | |
261 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 262 | "internal thread with epoll" : |
263 | "internal thread with select()"); | ||
264 | const char *ret_val; | ||
265 | |||
266 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | ||
262 | port = 0; | 267 | port = 0; |
263 | 268 | ||
264 | signal_done = 0; | 269 | signal_done = 0; |
265 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 270 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
271 | | poll_flag, | ||
266 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 272 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
267 | if (d == NULL) | 273 | if (d == NULL) |
268 | return 1; | 274 | return 1; |
269 | if (0 == port) | 275 | if (0 == port) |
276 | { | ||
277 | const union MHD_DaemonInfo *dinfo; | ||
278 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
279 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
270 | { | 280 | { |
271 | const union MHD_DaemonInfo *dinfo; | 281 | MHD_stop_daemon (d); return 32; |
272 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
273 | if (NULL == dinfo || 0 == dinfo->port) | ||
274 | { MHD_stop_daemon (d); return 32; } | ||
275 | port = (int)dinfo->port; | ||
276 | } | 282 | } |
283 | port = (int) dinfo->port; | ||
284 | } | ||
277 | start_timer (); | 285 | start_timer (); |
278 | ret_val = do_gets ((void*)(intptr_t)port); | 286 | ret_val = do_gets ((void*) (intptr_t) port); |
279 | if (!ret_val) | 287 | if (! ret_val) |
280 | stop (test_desc); | 288 | stop (test_desc); |
281 | MHD_stop_daemon (d); | 289 | MHD_stop_daemon (d); |
282 | if (ret_val) | 290 | if (ret_val) |
283 | { | 291 | { |
284 | fprintf (stderr, | 292 | fprintf (stderr, |
285 | "Error performing %s test: %s\n", test_desc, ret_val); | 293 | "Error performing %s test: %s\n", test_desc, ret_val); |
286 | return 4; | 294 | return 4; |
287 | } | 295 | } |
288 | return 0; | 296 | return 0; |
289 | } | 297 | } |
290 | 298 | ||
@@ -293,39 +301,49 @@ static int | |||
293 | testMultithreadedGet (int port, int poll_flag) | 301 | testMultithreadedGet (int port, int poll_flag) |
294 | { | 302 | { |
295 | struct MHD_Daemon *d; | 303 | struct MHD_Daemon *d; |
296 | const char * const test_desc = ((poll_flag & MHD_USE_AUTO) ? "internal thread with 'auto' and thread per connection" : | 304 | const char *const test_desc = ((poll_flag & MHD_USE_AUTO) ? |
297 | (poll_flag & MHD_USE_POLL) ? "internal thread with poll() and thread per connection" : | 305 | "internal thread with 'auto' and thread per connection" |
298 | (poll_flag & MHD_USE_EPOLL) ? "internal thread with epoll and thread per connection" | 306 | : |
299 | : "internal thread with select() and thread per connection"); | 307 | (poll_flag & MHD_USE_POLL) ? |
300 | const char * ret_val; | 308 | "internal thread with poll() and thread per connection" |
301 | 309 | : | |
302 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 310 | (poll_flag & MHD_USE_EPOLL) ? |
311 | "internal thread with epoll and thread per connection" | ||
312 | : | ||
313 | "internal thread with select() and thread per connection"); | ||
314 | const char *ret_val; | ||
315 | |||
316 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | ||
303 | port = 0; | 317 | port = 0; |
304 | 318 | ||
305 | signal_done = 0; | 319 | signal_done = 0; |
306 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 320 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
321 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | ||
322 | | poll_flag, | ||
307 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 323 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
308 | if (d == NULL) | 324 | if (d == NULL) |
309 | return 16; | 325 | return 16; |
310 | if (0 == port) | 326 | if (0 == port) |
327 | { | ||
328 | const union MHD_DaemonInfo *dinfo; | ||
329 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
330 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
311 | { | 331 | { |
312 | const union MHD_DaemonInfo *dinfo; | 332 | MHD_stop_daemon (d); return 32; |
313 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
314 | if (NULL == dinfo || 0 == dinfo->port) | ||
315 | { MHD_stop_daemon (d); return 32; } | ||
316 | port = (int)dinfo->port; | ||
317 | } | 333 | } |
334 | port = (int) dinfo->port; | ||
335 | } | ||
318 | start_timer (); | 336 | start_timer (); |
319 | ret_val = do_gets ((void*)(intptr_t)port); | 337 | ret_val = do_gets ((void*) (intptr_t) port); |
320 | if (!ret_val) | 338 | if (! ret_val) |
321 | stop (test_desc); | 339 | stop (test_desc); |
322 | MHD_stop_daemon (d); | 340 | MHD_stop_daemon (d); |
323 | if (ret_val) | 341 | if (ret_val) |
324 | { | 342 | { |
325 | fprintf (stderr, | 343 | fprintf (stderr, |
326 | "Error performing %s test: %s\n", test_desc, ret_val); | 344 | "Error performing %s test: %s\n", test_desc, ret_val); |
327 | return 4; | 345 | return 4; |
328 | } | 346 | } |
329 | return 0; | 347 | return 0; |
330 | } | 348 | } |
331 | 349 | ||
@@ -334,39 +352,46 @@ static int | |||
334 | testMultithreadedPoolGet (int port, int poll_flag) | 352 | testMultithreadedPoolGet (int port, int poll_flag) |
335 | { | 353 | { |
336 | struct MHD_Daemon *d; | 354 | struct MHD_Daemon *d; |
337 | const char * const test_desc = ((poll_flag & MHD_USE_AUTO) ? "internal thread pool with 'auto'" : | 355 | const char *const test_desc = ((poll_flag & MHD_USE_AUTO) ? |
338 | (poll_flag & MHD_USE_POLL) ? "internal thread pool with poll()" : | 356 | "internal thread pool with 'auto'" : |
339 | (poll_flag & MHD_USE_EPOLL) ? "internal thread poll with epoll" : "internal thread pool with select()"); | 357 | (poll_flag & MHD_USE_POLL) ? |
340 | const char * ret_val; | 358 | "internal thread pool with poll()" : |
341 | 359 | (poll_flag & MHD_USE_EPOLL) ? | |
342 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 360 | "internal thread poll with epoll" : |
361 | "internal thread pool with select()"); | ||
362 | const char *ret_val; | ||
363 | |||
364 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | ||
343 | port = 0; | 365 | port = 0; |
344 | 366 | ||
345 | signal_done = 0 ; | 367 | signal_done = 0; |
346 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 368 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
369 | | poll_flag, | ||
347 | port, NULL, NULL, &ahc_echo, "GET", | 370 | port, NULL, NULL, &ahc_echo, "GET", |
348 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); | 371 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); |
349 | if (d == NULL) | 372 | if (d == NULL) |
350 | return 16; | 373 | return 16; |
351 | if (0 == port) | 374 | if (0 == port) |
375 | { | ||
376 | const union MHD_DaemonInfo *dinfo; | ||
377 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
378 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
352 | { | 379 | { |
353 | const union MHD_DaemonInfo *dinfo; | 380 | MHD_stop_daemon (d); return 32; |
354 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
355 | if (NULL == dinfo || 0 == dinfo->port) | ||
356 | { MHD_stop_daemon (d); return 32; } | ||
357 | port = (int)dinfo->port; | ||
358 | } | 381 | } |
382 | port = (int) dinfo->port; | ||
383 | } | ||
359 | start_timer (); | 384 | start_timer (); |
360 | ret_val = do_gets ((void*)(intptr_t)port); | 385 | ret_val = do_gets ((void*) (intptr_t) port); |
361 | if (!ret_val) | 386 | if (! ret_val) |
362 | stop (test_desc); | 387 | stop (test_desc); |
363 | MHD_stop_daemon (d); | 388 | MHD_stop_daemon (d); |
364 | if (ret_val) | 389 | if (ret_val) |
365 | { | 390 | { |
366 | fprintf (stderr, | 391 | fprintf (stderr, |
367 | "Error performing %s test: %s\n", test_desc, ret_val); | 392 | "Error performing %s test: %s\n", test_desc, ret_val); |
368 | return 4; | 393 | return 4; |
369 | } | 394 | } |
370 | return 0; | 395 | return 0; |
371 | } | 396 | } |
372 | 397 | ||
@@ -386,7 +411,7 @@ testExternalGet (int port) | |||
386 | char *ret_val; | 411 | char *ret_val; |
387 | int ret = 0; | 412 | int ret = 0; |
388 | 413 | ||
389 | if (MHD_NO != MHD_is_feature_supported(MHD_FEATURE_AUTODETECT_BIND_PORT)) | 414 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
390 | port = 0; | 415 | port = 0; |
391 | 416 | ||
392 | signal_done = 0; | 417 | signal_done = 0; |
@@ -395,66 +420,71 @@ testExternalGet (int port) | |||
395 | if (d == NULL) | 420 | if (d == NULL) |
396 | return 256; | 421 | return 256; |
397 | if (0 == port) | 422 | if (0 == port) |
423 | { | ||
424 | const union MHD_DaemonInfo *dinfo; | ||
425 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
426 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
398 | { | 427 | { |
399 | const union MHD_DaemonInfo *dinfo; | 428 | MHD_stop_daemon (d); return 32; |
400 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
401 | if (NULL == dinfo || 0 == dinfo->port) | ||
402 | { MHD_stop_daemon (d); return 32; } | ||
403 | port = (int)dinfo->port; | ||
404 | } | 429 | } |
430 | port = (int) dinfo->port; | ||
431 | } | ||
405 | if (0 != pthread_create (&pid, NULL, | 432 | if (0 != pthread_create (&pid, NULL, |
406 | &do_gets, (void*)(intptr_t)port)) | 433 | &do_gets, (void*) (intptr_t) port)) |
407 | { | 434 | { |
408 | MHD_stop_daemon(d); | 435 | MHD_stop_daemon (d); |
409 | return 512; | 436 | return 512; |
410 | } | 437 | } |
411 | start_timer (); | 438 | start_timer (); |
412 | 439 | ||
413 | while (0 == signal_done) | 440 | while (0 == signal_done) |
441 | { | ||
442 | max = 0; | ||
443 | FD_ZERO (&rs); | ||
444 | FD_ZERO (&ws); | ||
445 | FD_ZERO (&es); | ||
446 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
447 | { | ||
448 | MHD_stop_daemon (d); | ||
449 | return 4096; | ||
450 | } | ||
451 | tret = MHD_get_timeout (d, &tt); | ||
452 | if (MHD_YES != tret) | ||
453 | tt = 1; | ||
454 | tv.tv_sec = tt / 1000; | ||
455 | tv.tv_usec = 1000 * (tt % 1000); | ||
456 | if (-1 == select (max + 1, &rs, &ws, &es, &tv)) | ||
414 | { | 457 | { |
415 | max = 0; | ||
416 | FD_ZERO (&rs); | ||
417 | FD_ZERO (&ws); | ||
418 | FD_ZERO (&es); | ||
419 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
420 | { | ||
421 | MHD_stop_daemon (d); | ||
422 | return 4096; | ||
423 | } | ||
424 | tret = MHD_get_timeout (d, &tt); | ||
425 | if (MHD_YES != tret) tt = 1; | ||
426 | tv.tv_sec = tt / 1000; | ||
427 | tv.tv_usec = 1000 * (tt % 1000); | ||
428 | if (-1 == select (max + 1, &rs, &ws, &es, &tv)) | ||
429 | { | ||
430 | #ifdef MHD_POSIX_SOCKETS | 458 | #ifdef MHD_POSIX_SOCKETS |
431 | if (EINTR == errno) | 459 | if (EINTR == errno) |
432 | continue; | 460 | continue; |
433 | fprintf (stderr, | 461 | fprintf (stderr, |
434 | "select failed: %s\n", | 462 | "select failed: %s\n", |
435 | strerror (errno)); | 463 | strerror (errno)); |
436 | #else | 464 | #else |
437 | if (WSAEINVAL == WSAGetLastError() && 0 == rs.fd_count && 0 == ws.fd_count && 0 == es.fd_count) | 465 | if ((WSAEINVAL == WSAGetLastError ()) &&(0 == rs.fd_count) &&(0 == |
438 | { | 466 | ws.fd_count) |
439 | Sleep (1000); | 467 | &&(0 == es.fd_count) ) |
440 | continue; | 468 | { |
441 | } | 469 | Sleep (1000); |
470 | continue; | ||
471 | } | ||
442 | #endif | 472 | #endif |
443 | ret |= 1024; | 473 | ret |= 1024; |
444 | break; | 474 | break; |
445 | } | ||
446 | MHD_run_from_select(d, &rs, &ws, &es); | ||
447 | } | 475 | } |
476 | MHD_run_from_select (d, &rs, &ws, &es); | ||
477 | } | ||
448 | 478 | ||
449 | stop ("external select"); | 479 | stop ("external select"); |
450 | MHD_stop_daemon (d); | 480 | MHD_stop_daemon (d); |
451 | if (0 != pthread_join(pid, (void**)&ret_val) || | 481 | if ((0 != pthread_join (pid, (void**) &ret_val))|| |
452 | NULL != ret_val) | 482 | (NULL != ret_val) ) |
453 | { | 483 | { |
454 | fprintf (stderr, | 484 | fprintf (stderr, |
455 | "%s\n", ret_val); | 485 | "%s\n", ret_val); |
456 | ret |= 8; | 486 | ret |= 8; |
457 | } | 487 | } |
458 | if (ret) | 488 | if (ret) |
459 | fprintf (stderr, "Error performing test.\n"); | 489 | fprintf (stderr, "Error performing test.\n"); |
460 | return 0; | 490 | return 0; |
@@ -466,9 +496,9 @@ main (int argc, char *const *argv) | |||
466 | { | 496 | { |
467 | unsigned int errorCount = 0; | 497 | unsigned int errorCount = 0; |
468 | int port = 1100; | 498 | int port = 1100; |
469 | (void)argc; /* Unused. Silent compiler warning. */ | 499 | (void) argc; /* Unused. Silent compiler warning. */ |
470 | 500 | ||
471 | if (NULL == argv || 0 == argv[0]) | 501 | if ((NULL == argv)||(0 == argv[0])) |
472 | return 99; | 502 | return 99; |
473 | oneone = has_in_name (argv[0], "11"); | 503 | oneone = has_in_name (argv[0], "11"); |
474 | if (oneone) | 504 | if (oneone) |
@@ -476,8 +506,8 @@ main (int argc, char *const *argv) | |||
476 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 506 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
477 | return 2; | 507 | return 2; |
478 | response = MHD_create_response_from_buffer (strlen ("/hello_world"), | 508 | response = MHD_create_response_from_buffer (strlen ("/hello_world"), |
479 | "/hello_world", | 509 | "/hello_world", |
480 | MHD_RESPMEM_MUST_COPY); | 510 | MHD_RESPMEM_MUST_COPY); |
481 | errorCount += testInternalGet (port++, 0); | 511 | errorCount += testInternalGet (port++, 0); |
482 | errorCount += testMultithreadedGet (port++, 0); | 512 | errorCount += testMultithreadedGet (port++, 0); |
483 | errorCount += testMultithreadedPoolGet (port++, 0); | 513 | errorCount += testMultithreadedPoolGet (port++, 0); |
@@ -485,17 +515,17 @@ main (int argc, char *const *argv) | |||
485 | errorCount += testInternalGet (port++, MHD_USE_AUTO); | 515 | errorCount += testInternalGet (port++, MHD_USE_AUTO); |
486 | errorCount += testMultithreadedGet (port++, MHD_USE_AUTO); | 516 | errorCount += testMultithreadedGet (port++, MHD_USE_AUTO); |
487 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO); | 517 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO); |
488 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL)) | 518 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL)) |
489 | { | 519 | { |
490 | errorCount += testInternalGet (port++, MHD_USE_POLL); | 520 | errorCount += testInternalGet (port++, MHD_USE_POLL); |
491 | errorCount += testMultithreadedGet (port++, MHD_USE_POLL); | 521 | errorCount += testMultithreadedGet (port++, MHD_USE_POLL); |
492 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_POLL); | 522 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_POLL); |
493 | } | 523 | } |
494 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL)) | 524 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL)) |
495 | { | 525 | { |
496 | errorCount += testInternalGet (port++, MHD_USE_EPOLL); | 526 | errorCount += testInternalGet (port++, MHD_USE_EPOLL); |
497 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_EPOLL); | 527 | errorCount += testMultithreadedPoolGet (port++, MHD_USE_EPOLL); |
498 | } | 528 | } |
499 | MHD_destroy_response (response); | 529 | MHD_destroy_response (response); |
500 | if (errorCount != 0) | 530 | if (errorCount != 0) |
501 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 531 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c index 5b1062fe..a0480932 100644 --- a/src/testcurl/test_callback.c +++ b/src/testcurl/test_callback.c | |||
@@ -35,56 +35,56 @@ struct callback_closure | |||
35 | 35 | ||
36 | 36 | ||
37 | static ssize_t | 37 | static ssize_t |
38 | called_twice(void *cls, uint64_t pos, char *buf, size_t max) | 38 | called_twice (void *cls, uint64_t pos, char *buf, size_t max) |
39 | { | 39 | { |
40 | struct callback_closure *cls2 = cls; | 40 | struct callback_closure *cls2 = cls; |
41 | 41 | ||
42 | (void) pos; /* Unused. Silence compiler warning. */ | 42 | (void) pos; /* Unused. Silence compiler warning. */ |
43 | (void) max; | 43 | (void) max; |
44 | if (cls2->called == 0) | 44 | if (cls2->called == 0) |
45 | { | 45 | { |
46 | memcpy(buf, "test", 5); | 46 | memcpy (buf, "test", 5); |
47 | cls2->called = 1; | 47 | cls2->called = 1; |
48 | return strlen(buf); | 48 | return strlen (buf); |
49 | } | 49 | } |
50 | if (cls2->called == 1) | 50 | if (cls2->called == 1) |
51 | { | 51 | { |
52 | cls2->called = 2; | 52 | cls2->called = 2; |
53 | return MHD_CONTENT_READER_END_OF_STREAM; | 53 | return MHD_CONTENT_READER_END_OF_STREAM; |
54 | } | 54 | } |
55 | fprintf(stderr, | 55 | fprintf (stderr, |
56 | "Handler called after returning END_OF_STREAM!\n"); | 56 | "Handler called after returning END_OF_STREAM!\n"); |
57 | return MHD_CONTENT_READER_END_WITH_ERROR; | 57 | return MHD_CONTENT_READER_END_WITH_ERROR; |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | static int | 61 | static int |
62 | callback(void *cls, | 62 | callback (void *cls, |
63 | struct MHD_Connection *connection, | 63 | struct MHD_Connection *connection, |
64 | const char *url, | 64 | const char *url, |
65 | const char *method, | 65 | const char *method, |
66 | const char *version, | 66 | const char *version, |
67 | const char *upload_data, | 67 | const char *upload_data, |
68 | size_t *upload_data_size, | 68 | size_t *upload_data_size, |
69 | void **con_cls) | 69 | void **con_cls) |
70 | { | 70 | { |
71 | struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure)); | 71 | struct callback_closure *cbc = calloc (1, sizeof(struct callback_closure)); |
72 | struct MHD_Response *r; | 72 | struct MHD_Response *r; |
73 | int ret; | 73 | int ret; |
74 | 74 | ||
75 | (void)cls; | 75 | (void) cls; |
76 | (void)url; /* Unused. Silent compiler warning. */ | 76 | (void) url; /* Unused. Silent compiler warning. */ |
77 | (void)method; | 77 | (void) method; |
78 | (void)version; | 78 | (void) version; |
79 | (void)upload_data; /* Unused. Silent compiler warning. */ | 79 | (void) upload_data; /* Unused. Silent compiler warning. */ |
80 | (void)upload_data_size; | 80 | (void) upload_data_size; |
81 | (void)con_cls; /* Unused. Silent compiler warning. */ | 81 | (void) con_cls; /* Unused. Silent compiler warning. */ |
82 | 82 | ||
83 | if (NULL == cbc) | 83 | if (NULL == cbc) |
84 | return MHD_NO; | 84 | return MHD_NO; |
85 | r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, | 85 | r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, |
86 | &called_twice, cbc, | 86 | &called_twice, cbc, |
87 | &free); | 87 | &free); |
88 | if (NULL == r) | 88 | if (NULL == r) |
89 | { | 89 | { |
90 | free (cbc); | 90 | free (cbc); |
@@ -104,13 +104,13 @@ discard_buffer (void *ptr, | |||
104 | size_t nmemb, | 104 | size_t nmemb, |
105 | void *ctx) | 105 | void *ctx) |
106 | { | 106 | { |
107 | (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ | 107 | (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */ |
108 | return size * nmemb; | 108 | return size * nmemb; |
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
112 | int | 112 | int |
113 | main(int argc, char **argv) | 113 | main (int argc, char **argv) |
114 | { | 114 | { |
115 | struct MHD_Daemon *d; | 115 | struct MHD_Daemon *d; |
116 | fd_set rs; | 116 | fd_set rs; |
@@ -130,33 +130,35 @@ main(int argc, char **argv) | |||
130 | struct timeval tv; | 130 | struct timeval tv; |
131 | int extra; | 131 | int extra; |
132 | int port; | 132 | int port; |
133 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 133 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
134 | 134 | ||
135 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 135 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
136 | port = 0; | 136 | port = 0; |
137 | else | 137 | else |
138 | port = 1140; | 138 | port = 1140; |
139 | 139 | ||
140 | d = MHD_start_daemon(0, | 140 | d = MHD_start_daemon (0, |
141 | port, | 141 | port, |
142 | NULL, | 142 | NULL, |
143 | NULL, | 143 | NULL, |
144 | &callback, | 144 | &callback, |
145 | NULL, | 145 | NULL, |
146 | MHD_OPTION_END); | 146 | MHD_OPTION_END); |
147 | if (d == NULL) | 147 | if (d == NULL) |
148 | return 32; | 148 | return 32; |
149 | if (0 == port) | 149 | if (0 == port) |
150 | { | ||
151 | const union MHD_DaemonInfo *dinfo; | ||
152 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
153 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
150 | { | 154 | { |
151 | const union MHD_DaemonInfo *dinfo; | 155 | MHD_stop_daemon (d); return 48; |
152 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
153 | if (NULL == dinfo || 0 == dinfo->port) | ||
154 | { MHD_stop_daemon (d); return 48; } | ||
155 | port = (int)dinfo->port; | ||
156 | } | 156 | } |
157 | port = (int) dinfo->port; | ||
158 | } | ||
157 | c = curl_easy_init (); | 159 | c = curl_easy_init (); |
158 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); | 160 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); |
159 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 161 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
160 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &discard_buffer); | 162 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &discard_buffer); |
161 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 163 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
162 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | 164 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
@@ -165,87 +167,89 @@ main(int argc, char **argv) | |||
165 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 167 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
166 | multi = curl_multi_init (); | 168 | multi = curl_multi_init (); |
167 | if (multi == NULL) | 169 | if (multi == NULL) |
168 | { | 170 | { |
169 | curl_easy_cleanup (c); | 171 | curl_easy_cleanup (c); |
170 | MHD_stop_daemon (d); | 172 | MHD_stop_daemon (d); |
171 | return 1; | 173 | return 1; |
172 | } | 174 | } |
173 | mret = curl_multi_add_handle (multi, c); | 175 | mret = curl_multi_add_handle (multi, c); |
174 | if (mret != CURLM_OK) | 176 | if (mret != CURLM_OK) |
177 | { | ||
178 | curl_multi_cleanup (multi); | ||
179 | curl_easy_cleanup (c); | ||
180 | MHD_stop_daemon (d); | ||
181 | return 2; | ||
182 | } | ||
183 | extra = 10; | ||
184 | while ( (c != NULL) || (--extra > 0) ) | ||
185 | { | ||
186 | maxsock = MHD_INVALID_SOCKET; | ||
187 | maxposixs = -1; | ||
188 | FD_ZERO (&ws); | ||
189 | FD_ZERO (&rs); | ||
190 | FD_ZERO (&es); | ||
191 | curl_multi_perform (multi, &running); | ||
192 | if (NULL != multi) | ||
193 | { | ||
194 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
195 | if (mret != CURLM_OK) | ||
196 | { | ||
197 | curl_multi_remove_handle (multi, c); | ||
198 | curl_multi_cleanup (multi); | ||
199 | curl_easy_cleanup (c); | ||
200 | MHD_stop_daemon (d); | ||
201 | return 3; | ||
202 | } | ||
203 | } | ||
204 | if (MHD_YES != | ||
205 | MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
175 | { | 206 | { |
207 | curl_multi_remove_handle (multi, c); | ||
176 | curl_multi_cleanup (multi); | 208 | curl_multi_cleanup (multi); |
177 | curl_easy_cleanup (c); | 209 | curl_easy_cleanup (c); |
178 | MHD_stop_daemon (d); | 210 | MHD_stop_daemon (d); |
179 | return 2; | 211 | return 4; |
180 | } | 212 | } |
181 | extra = 10; | 213 | tv.tv_sec = 0; |
182 | while ( (c != NULL) || (--extra > 0) ) | 214 | tv.tv_usec = 1000; |
215 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
216 | { | ||
217 | #ifdef MHD_POSIX_SOCKETS | ||
218 | if (EINTR != errno) | ||
219 | abort (); | ||
220 | #else | ||
221 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != | ||
222 | ws.fd_count) | ||
223 | ||(0 != es.fd_count) ) | ||
224 | abort (); | ||
225 | Sleep (1000); | ||
226 | #endif | ||
227 | } | ||
228 | if (NULL != multi) | ||
183 | { | 229 | { |
184 | maxsock = MHD_INVALID_SOCKET; | ||
185 | maxposixs = -1; | ||
186 | FD_ZERO(&ws); | ||
187 | FD_ZERO(&rs); | ||
188 | FD_ZERO(&es); | ||
189 | curl_multi_perform (multi, &running); | 230 | curl_multi_perform (multi, &running); |
190 | if (NULL != multi) | 231 | if (running == 0) |
191 | { | 232 | { |
192 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | 233 | msg = curl_multi_info_read (multi, &running); |
193 | if (mret != CURLM_OK) | 234 | if (msg == NULL) |
194 | { | 235 | break; |
195 | curl_multi_remove_handle (multi, c); | 236 | if (msg->msg == CURLMSG_DONE) |
196 | curl_multi_cleanup (multi); | 237 | { |
197 | curl_easy_cleanup (c); | 238 | if (msg->data.result != CURLE_OK) |
198 | MHD_stop_daemon (d); | 239 | printf ("%s failed at %s:%d: `%s'\n", |
199 | return 3; | 240 | "curl_multi_perform", |
200 | } | 241 | __FILE__, |
201 | } | 242 | __LINE__, curl_easy_strerror (msg->data.result)); |
202 | if (MHD_YES != | ||
203 | MHD_get_fdset(d, &rs, &ws, &es, &maxsock)) | ||
204 | { | ||
205 | curl_multi_remove_handle (multi, c); | 243 | curl_multi_remove_handle (multi, c); |
206 | curl_multi_cleanup (multi); | 244 | curl_multi_cleanup (multi); |
207 | curl_easy_cleanup (c); | 245 | curl_easy_cleanup (c); |
208 | MHD_stop_daemon (d); | 246 | c = NULL; |
209 | return 4; | 247 | multi = NULL; |
210 | } | ||
211 | tv.tv_sec = 0; | ||
212 | tv.tv_usec = 1000; | ||
213 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
214 | { | ||
215 | #ifdef MHD_POSIX_SOCKETS | ||
216 | if (EINTR != errno) | ||
217 | abort (); | ||
218 | #else | ||
219 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | ||
220 | abort (); | ||
221 | Sleep (1000); | ||
222 | #endif | ||
223 | } | 248 | } |
224 | if (NULL != multi) | 249 | } |
225 | { | ||
226 | curl_multi_perform (multi, &running); | ||
227 | if (running == 0) | ||
228 | { | ||
229 | msg = curl_multi_info_read (multi, &running); | ||
230 | if (msg == NULL) | ||
231 | break; | ||
232 | if (msg->msg == CURLMSG_DONE) | ||
233 | { | ||
234 | if (msg->data.result != CURLE_OK) | ||
235 | printf ("%s failed at %s:%d: `%s'\n", | ||
236 | "curl_multi_perform", | ||
237 | __FILE__, | ||
238 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
239 | curl_multi_remove_handle (multi, c); | ||
240 | curl_multi_cleanup (multi); | ||
241 | curl_easy_cleanup (c); | ||
242 | c = NULL; | ||
243 | multi = NULL; | ||
244 | } | ||
245 | } | ||
246 | } | ||
247 | MHD_run(d); | ||
248 | } | 250 | } |
249 | MHD_stop_daemon(d); | 251 | MHD_run (d); |
252 | } | ||
253 | MHD_stop_daemon (d); | ||
250 | return 0; | 254 | return 0; |
251 | } | 255 | } |
diff --git a/src/testcurl/test_concurrent_stop.c b/src/testcurl/test_concurrent_stop.c index 71202add..02f4fffd 100644 --- a/src/testcurl/test_concurrent_stop.c +++ b/src/testcurl/test_concurrent_stop.c | |||
@@ -33,10 +33,10 @@ | |||
33 | #include <pthread.h> | 33 | #include <pthread.h> |
34 | #include "gauger.h" | 34 | #include "gauger.h" |
35 | 35 | ||
36 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 36 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
37 | #undef CPU_COUNT | 37 | #undef CPU_COUNT |
38 | #endif | 38 | #endif |
39 | #if !defined(CPU_COUNT) | 39 | #if ! defined(CPU_COUNT) |
40 | #define CPU_COUNT 2 | 40 | #define CPU_COUNT 2 |
41 | #endif | 41 | #endif |
42 | 42 | ||
@@ -81,50 +81,52 @@ thread_watchdog (void *param) | |||
81 | 81 | ||
82 | seconds_passed = 0; | 82 | seconds_passed = 0; |
83 | while (watchdog_continue) /* Poor threads sync, but works for testing. */ | 83 | while (watchdog_continue) /* Poor threads sync, but works for testing. */ |
84 | { | ||
85 | if (0 == sleep (1)) /* Poor accuracy, but enough for testing. */ | ||
86 | seconds_passed++; | ||
87 | if (timeout_val < seconds_passed) | ||
84 | { | 88 | { |
85 | if (0 == sleep (1)) /* Poor accuracy, but enough for testing. */ | 89 | fprintf (stderr, "%s timeout expired.\n", watchdog_obj ? watchdog_obj : |
86 | seconds_passed++; | 90 | "Watchdog"); |
87 | if (timeout_val < seconds_passed) | 91 | fflush (stderr); |
88 | { | 92 | _exit (16); |
89 | fprintf (stderr, "%s timeout expired.\n", watchdog_obj ? watchdog_obj : "Watchdog"); | ||
90 | fflush (stderr); | ||
91 | _exit(16); | ||
92 | } | ||
93 | } | 93 | } |
94 | } | ||
94 | return NULL; | 95 | return NULL; |
95 | } | 96 | } |
96 | 97 | ||
97 | pthread_t watchdog_tid; | 98 | pthread_t watchdog_tid; |
98 | 99 | ||
99 | static void | 100 | static void |
100 | start_watchdog(int timeout, const char *obj_name) | 101 | start_watchdog (int timeout, const char *obj_name) |
101 | { | 102 | { |
102 | watchdog_continue = 1; | 103 | watchdog_continue = 1; |
103 | watchdog_obj = obj_name; | 104 | watchdog_obj = obj_name; |
104 | if (0 != pthread_create(&watchdog_tid, NULL, &thread_watchdog, (void*)(intptr_t)timeout)) | 105 | if (0 != pthread_create (&watchdog_tid, NULL, &thread_watchdog, |
105 | { | 106 | (void*) (intptr_t) timeout)) |
106 | fprintf(stderr, "Failed to start watchdog.\n"); | 107 | { |
107 | _exit (99); | 108 | fprintf (stderr, "Failed to start watchdog.\n"); |
108 | } | 109 | _exit (99); |
110 | } | ||
109 | } | 111 | } |
110 | 112 | ||
111 | static void | 113 | static void |
112 | stop_watchdog(void) | 114 | stop_watchdog (void) |
113 | { | 115 | { |
114 | watchdog_continue = 0; | 116 | watchdog_continue = 0; |
115 | if (0 != pthread_join (watchdog_tid, NULL)) | 117 | if (0 != pthread_join (watchdog_tid, NULL)) |
116 | { | 118 | { |
117 | fprintf(stderr, "Failed to stop watchdog.\n"); | 119 | fprintf (stderr, "Failed to stop watchdog.\n"); |
118 | _exit (99); | 120 | _exit (99); |
119 | } | 121 | } |
120 | } | 122 | } |
121 | 123 | ||
122 | static size_t | 124 | static size_t |
123 | copyBuffer (void *ptr, | 125 | copyBuffer (void *ptr, |
124 | size_t size, size_t nmemb, | 126 | size_t size, size_t nmemb, |
125 | void *ctx) | 127 | void *ctx) |
126 | { | 128 | { |
127 | (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ | 129 | (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */ |
128 | return size * nmemb; | 130 | return size * nmemb; |
129 | } | 131 | } |
130 | 132 | ||
@@ -142,16 +144,16 @@ ahc_echo (void *cls, | |||
142 | static int ptr; | 144 | static int ptr; |
143 | const char *me = cls; | 145 | const char *me = cls; |
144 | int ret; | 146 | int ret; |
145 | (void)url;(void)version; /* Unused. Silent compiler warning. */ | 147 | (void) url; (void) version; /* Unused. Silent compiler warning. */ |
146 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 148 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
147 | 149 | ||
148 | if (0 != strcmp (me, method)) | 150 | if (0 != strcmp (me, method)) |
149 | return MHD_NO; /* unexpected method */ | 151 | return MHD_NO; /* unexpected method */ |
150 | if (&ptr != *unused) | 152 | if (&ptr != *unused) |
151 | { | 153 | { |
152 | *unused = &ptr; | 154 | *unused = &ptr; |
153 | return MHD_YES; | 155 | return MHD_YES; |
154 | } | 156 | } |
155 | *unused = NULL; | 157 | *unused = NULL; |
156 | ret = MHD_queue_response (connection, | 158 | ret = MHD_queue_response (connection, |
157 | MHD_HTTP_OK, | 159 | MHD_HTTP_OK, |
@@ -166,15 +168,15 @@ thread_gets (void *param) | |||
166 | { | 168 | { |
167 | CURL *c; | 169 | CURL *c; |
168 | CURLcode errornum; | 170 | CURLcode errornum; |
169 | char * const url = (char*) param; | 171 | char *const url = (char*) param; |
170 | 172 | ||
171 | c = NULL; | 173 | c = NULL; |
172 | c = curl_easy_init (); | 174 | c = curl_easy_init (); |
173 | if (NULL == c) | 175 | if (NULL == c) |
174 | { | 176 | { |
175 | fprintf(stderr, "curl_easy_init failed.\n"); | 177 | fprintf (stderr, "curl_easy_init failed.\n"); |
176 | _exit(99); | 178 | _exit (99); |
177 | } | 179 | } |
178 | curl_easy_setopt (c, CURLOPT_URL, url); | 180 | curl_easy_setopt (c, CURLOPT_URL, url); |
179 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 181 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
180 | curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL); | 182 | curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL); |
@@ -190,62 +192,62 @@ thread_gets (void *param) | |||
190 | crashes on my system! */ | 192 | crashes on my system! */ |
191 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 193 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
192 | while (continue_requesting) | 194 | while (continue_requesting) |
195 | { | ||
196 | errornum = curl_easy_perform (c); | ||
197 | if (CURLE_OK != errornum) | ||
193 | { | 198 | { |
194 | errornum = curl_easy_perform (c); | 199 | curl_easy_cleanup (c); |
195 | if (CURLE_OK != errornum) | 200 | return NULL; |
196 | { | ||
197 | curl_easy_cleanup (c); | ||
198 | return NULL; | ||
199 | } | ||
200 | } | 201 | } |
202 | } | ||
201 | curl_easy_cleanup (c); | 203 | curl_easy_cleanup (c); |
202 | return NULL; | 204 | return NULL; |
203 | } | 205 | } |
204 | 206 | ||
205 | static void * | 207 | static void * |
206 | do_gets (void * param) | 208 | do_gets (void *param) |
207 | { | 209 | { |
208 | int j; | 210 | int j; |
209 | pthread_t par[PAR]; | 211 | pthread_t par[PAR]; |
210 | char url[64]; | 212 | char url[64]; |
211 | int port = (int)(intptr_t)param; | 213 | int port = (int) (intptr_t) param; |
212 | 214 | ||
213 | snprintf (url, | 215 | snprintf (url, |
214 | sizeof (url), | 216 | sizeof (url), |
215 | "http://127.0.0.1:%d/hello_world", | 217 | "http://127.0.0.1:%d/hello_world", |
216 | port); | 218 | port); |
217 | 219 | ||
218 | for (j=0;j<PAR;j++) | 220 | for (j = 0; j<PAR; j++) |
219 | { | 221 | { |
220 | if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url)) | 222 | if (0 != pthread_create (&par[j], NULL, &thread_gets, (void*) url)) |
221 | { | ||
222 | fprintf(stderr, "pthread_create failed.\n"); | ||
223 | continue_requesting = 0; | ||
224 | for (j--; j >= 0; j--) | ||
225 | { | ||
226 | pthread_join(par[j], NULL); | ||
227 | } | ||
228 | _exit(99); | ||
229 | } | ||
230 | } | ||
231 | (void)sleep (1); | ||
232 | for (j=0;j<PAR;j++) | ||
233 | { | 223 | { |
234 | pthread_join(par[j], NULL); | 224 | fprintf (stderr, "pthread_create failed.\n"); |
225 | continue_requesting = 0; | ||
226 | for (j--; j >= 0; j--) | ||
227 | { | ||
228 | pthread_join (par[j], NULL); | ||
229 | } | ||
230 | _exit (99); | ||
235 | } | 231 | } |
232 | } | ||
233 | (void) sleep (1); | ||
234 | for (j = 0; j<PAR; j++) | ||
235 | { | ||
236 | pthread_join (par[j], NULL); | ||
237 | } | ||
236 | return NULL; | 238 | return NULL; |
237 | } | 239 | } |
238 | 240 | ||
239 | 241 | ||
240 | pthread_t start_gets(int port) | 242 | pthread_t start_gets (int port) |
241 | { | 243 | { |
242 | pthread_t tid; | 244 | pthread_t tid; |
243 | continue_requesting = 1; | 245 | continue_requesting = 1; |
244 | if (0 != pthread_create(&tid, NULL, &do_gets, (void*)(intptr_t)port)) | 246 | if (0 != pthread_create (&tid, NULL, &do_gets, (void*) (intptr_t) port)) |
245 | { | 247 | { |
246 | fprintf(stderr, "pthread_create failed.\n"); | 248 | fprintf (stderr, "pthread_create failed.\n"); |
247 | _exit(99); | 249 | _exit (99); |
248 | } | 250 | } |
249 | return tid; | 251 | return tid; |
250 | } | 252 | } |
251 | 253 | ||
@@ -257,7 +259,9 @@ testMultithreadedGet (int port, | |||
257 | struct MHD_Daemon *d; | 259 | struct MHD_Daemon *d; |
258 | pthread_t p; | 260 | pthread_t p; |
259 | 261 | ||
260 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 262 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
263 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | ||
264 | | poll_flag, | ||
261 | port, | 265 | port, |
262 | NULL, NULL, | 266 | NULL, NULL, |
263 | &ahc_echo, "GET", | 267 | &ahc_echo, "GET", |
@@ -265,18 +269,20 @@ testMultithreadedGet (int port, | |||
265 | if (d == NULL) | 269 | if (d == NULL) |
266 | return 16; | 270 | return 16; |
267 | if (0 == port) | 271 | if (0 == port) |
272 | { | ||
273 | const union MHD_DaemonInfo *dinfo; | ||
274 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
275 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
268 | { | 276 | { |
269 | const union MHD_DaemonInfo *dinfo; | 277 | MHD_stop_daemon (d); return 32; |
270 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
271 | if (NULL == dinfo || 0 == dinfo->port) | ||
272 | { MHD_stop_daemon (d); return 32; } | ||
273 | port = (int)dinfo->port; | ||
274 | } | 278 | } |
279 | port = (int) dinfo->port; | ||
280 | } | ||
275 | p = start_gets (port); | 281 | p = start_gets (port); |
276 | (void)sleep (1); | 282 | (void) sleep (1); |
277 | start_watchdog(10, "daemon_stop() in testMultithreadedGet"); | 283 | start_watchdog (10, "daemon_stop() in testMultithreadedGet"); |
278 | MHD_stop_daemon (d); | 284 | MHD_stop_daemon (d); |
279 | stop_watchdog(); | 285 | stop_watchdog (); |
280 | continue_requesting = 0; | 286 | continue_requesting = 0; |
281 | pthread_join (p, NULL); | 287 | pthread_join (p, NULL); |
282 | return 0; | 288 | return 0; |
@@ -290,7 +296,8 @@ testMultithreadedPoolGet (int port, | |||
290 | struct MHD_Daemon *d; | 296 | struct MHD_Daemon *d; |
291 | pthread_t p; | 297 | pthread_t p; |
292 | 298 | ||
293 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 299 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
300 | | poll_flag, | ||
294 | port, | 301 | port, |
295 | NULL, NULL, | 302 | NULL, NULL, |
296 | &ahc_echo, "GET", | 303 | &ahc_echo, "GET", |
@@ -299,18 +306,20 @@ testMultithreadedPoolGet (int port, | |||
299 | if (d == NULL) | 306 | if (d == NULL) |
300 | return 16; | 307 | return 16; |
301 | if (0 == port) | 308 | if (0 == port) |
309 | { | ||
310 | const union MHD_DaemonInfo *dinfo; | ||
311 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
312 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
302 | { | 313 | { |
303 | const union MHD_DaemonInfo *dinfo; | 314 | MHD_stop_daemon (d); return 32; |
304 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
305 | if (NULL == dinfo || 0 == dinfo->port) | ||
306 | { MHD_stop_daemon (d); return 32; } | ||
307 | port = (int)dinfo->port; | ||
308 | } | 315 | } |
316 | port = (int) dinfo->port; | ||
317 | } | ||
309 | p = start_gets (port); | 318 | p = start_gets (port); |
310 | (void)sleep (1); | 319 | (void) sleep (1); |
311 | start_watchdog(10, "daemon_stop() in testMultithreadedPoolGet"); | 320 | start_watchdog (10, "daemon_stop() in testMultithreadedPoolGet"); |
312 | MHD_stop_daemon (d); | 321 | MHD_stop_daemon (d); |
313 | stop_watchdog(); | 322 | stop_watchdog (); |
314 | continue_requesting = 0; | 323 | continue_requesting = 0; |
315 | pthread_join (p, NULL); | 324 | pthread_join (p, NULL); |
316 | return 0; | 325 | return 0; |
@@ -322,8 +331,8 @@ main (int argc, char *const *argv) | |||
322 | { | 331 | { |
323 | unsigned int errorCount = 0; | 332 | unsigned int errorCount = 0; |
324 | int port; | 333 | int port; |
325 | (void)argc; /* Unused. Silent compiler warning. */ | 334 | (void) argc; /* Unused. Silent compiler warning. */ |
326 | (void)argv; /* Unused. Silent compiler warning. */ | 335 | (void) argv; /* Unused. Silent compiler warning. */ |
327 | 336 | ||
328 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 337 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
329 | port = 0; | 338 | port = 0; |
@@ -333,15 +342,16 @@ main (int argc, char *const *argv) | |||
333 | /* Do reuse connection, otherwise all available local ports may exhausted. */ | 342 | /* Do reuse connection, otherwise all available local ports may exhausted. */ |
334 | oneone = 1; | 343 | oneone = 1; |
335 | 344 | ||
336 | if (0 != port && oneone) | 345 | if ((0 != port)&& oneone) |
337 | port += 5; | 346 | port += 5; |
338 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 347 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
339 | return 2; | 348 | return 2; |
340 | response = MHD_create_response_from_buffer (strlen ("/hello_world"), | 349 | response = MHD_create_response_from_buffer (strlen ("/hello_world"), |
341 | "/hello_world", | 350 | "/hello_world", |
342 | MHD_RESPMEM_MUST_COPY); | 351 | MHD_RESPMEM_MUST_COPY); |
343 | errorCount += testMultithreadedGet (port, 0); | 352 | errorCount += testMultithreadedGet (port, 0); |
344 | if (0 != port) port++; | 353 | if (0 != port) |
354 | port++; | ||
345 | errorCount += testMultithreadedPoolGet (port, 0); | 355 | errorCount += testMultithreadedPoolGet (port, 0); |
346 | MHD_destroy_response (response); | 356 | MHD_destroy_response (response); |
347 | if (errorCount != 0) | 357 | if (errorCount != 0) |
diff --git a/src/testcurl/test_delete.c b/src/testcurl/test_delete.c index 35e9dc62..a3d14661 100644 --- a/src/testcurl/test_delete.c +++ b/src/testcurl/test_delete.c | |||
@@ -37,10 +37,10 @@ | |||
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 40 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
41 | #undef CPU_COUNT | 41 | #undef CPU_COUNT |
42 | #endif | 42 | #endif |
43 | #if !defined(CPU_COUNT) | 43 | #if ! defined(CPU_COUNT) |
44 | #define CPU_COUNT 2 | 44 | #define CPU_COUNT 2 |
45 | #endif | 45 | #endif |
46 | 46 | ||
@@ -91,28 +91,28 @@ ahc_echo (void *cls, | |||
91 | int *done = cls; | 91 | int *done = cls; |
92 | struct MHD_Response *response; | 92 | struct MHD_Response *response; |
93 | int ret; | 93 | int ret; |
94 | (void)version;(void)unused; /* Unused. Silent compiler warning. */ | 94 | (void) version; (void) unused; /* Unused. Silent compiler warning. */ |
95 | 95 | ||
96 | if (0 != strcasecmp ("DELETE", method)) | 96 | if (0 != strcasecmp ("DELETE", method)) |
97 | return MHD_NO; /* unexpected method */ | 97 | return MHD_NO; /* unexpected method */ |
98 | if ((*done) == 0) | 98 | if ((*done) == 0) |
99 | { | ||
100 | if (*upload_data_size != 8) | ||
101 | return MHD_YES; /* not yet ready */ | ||
102 | if (0 == memcmp (upload_data, "Hello123", 8)) | ||
99 | { | 103 | { |
100 | if (*upload_data_size != 8) | 104 | *upload_data_size = 0; |
101 | return MHD_YES; /* not yet ready */ | ||
102 | if (0 == memcmp (upload_data, "Hello123", 8)) | ||
103 | { | ||
104 | *upload_data_size = 0; | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | printf ("Invalid upload data `%8s'!\n", upload_data); | ||
109 | return MHD_NO; | ||
110 | } | ||
111 | *done = 1; | ||
112 | return MHD_YES; | ||
113 | } | 105 | } |
106 | else | ||
107 | { | ||
108 | printf ("Invalid upload data `%8s'!\n", upload_data); | ||
109 | return MHD_NO; | ||
110 | } | ||
111 | *done = 1; | ||
112 | return MHD_YES; | ||
113 | } | ||
114 | response = MHD_create_response_from_buffer (strlen (url), (void*) url, | 114 | response = MHD_create_response_from_buffer (strlen (url), (void*) url, |
115 | MHD_RESPMEM_MUST_COPY); | 115 | MHD_RESPMEM_MUST_COPY); |
116 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 116 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
117 | MHD_destroy_response (response); | 117 | MHD_destroy_response (response); |
118 | return ret; | 118 | return ret; |
@@ -145,16 +145,18 @@ testInternalDelete () | |||
145 | if (d == NULL) | 145 | if (d == NULL) |
146 | return 1; | 146 | return 1; |
147 | if (0 == port) | 147 | if (0 == port) |
148 | { | ||
149 | const union MHD_DaemonInfo *dinfo; | ||
150 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
151 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
148 | { | 152 | { |
149 | const union MHD_DaemonInfo *dinfo; | 153 | MHD_stop_daemon (d); return 32; |
150 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
151 | if (NULL == dinfo || 0 == dinfo->port) | ||
152 | { MHD_stop_daemon (d); return 32; } | ||
153 | port = (int)dinfo->port; | ||
154 | } | 154 | } |
155 | port = (int) dinfo->port; | ||
156 | } | ||
155 | c = curl_easy_init (); | 157 | c = curl_easy_init (); |
156 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 158 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
157 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 159 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
158 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 160 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
159 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 161 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
160 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 162 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -174,14 +176,14 @@ testInternalDelete () | |||
174 | * crashes on my system! */ | 176 | * crashes on my system! */ |
175 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 177 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
176 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 178 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
177 | { | 179 | { |
178 | fprintf (stderr, | 180 | fprintf (stderr, |
179 | "curl_easy_perform failed: `%s'\n", | 181 | "curl_easy_perform failed: `%s'\n", |
180 | curl_easy_strerror (errornum)); | 182 | curl_easy_strerror (errornum)); |
181 | curl_easy_cleanup (c); | 183 | curl_easy_cleanup (c); |
182 | MHD_stop_daemon (d); | 184 | MHD_stop_daemon (d); |
183 | return 2; | 185 | return 2; |
184 | } | 186 | } |
185 | curl_easy_cleanup (c); | 187 | curl_easy_cleanup (c); |
186 | MHD_stop_daemon (d); | 188 | MHD_stop_daemon (d); |
187 | if (cbc.pos != strlen ("/hello_world")) | 189 | if (cbc.pos != strlen ("/hello_world")) |
@@ -212,22 +214,25 @@ testMultithreadedDelete () | |||
212 | cbc.buf = buf; | 214 | cbc.buf = buf; |
213 | cbc.size = 2048; | 215 | cbc.size = 2048; |
214 | cbc.pos = 0; | 216 | cbc.pos = 0; |
215 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 217 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
218 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
216 | port, | 219 | port, |
217 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); | 220 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); |
218 | if (d == NULL) | 221 | if (d == NULL) |
219 | return 16; | 222 | return 16; |
220 | if (0 == port) | 223 | if (0 == port) |
224 | { | ||
225 | const union MHD_DaemonInfo *dinfo; | ||
226 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
227 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
221 | { | 228 | { |
222 | const union MHD_DaemonInfo *dinfo; | 229 | MHD_stop_daemon (d); return 32; |
223 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
224 | if (NULL == dinfo || 0 == dinfo->port) | ||
225 | { MHD_stop_daemon (d); return 32; } | ||
226 | port = (int)dinfo->port; | ||
227 | } | 230 | } |
231 | port = (int) dinfo->port; | ||
232 | } | ||
228 | c = curl_easy_init (); | 233 | c = curl_easy_init (); |
229 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 234 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
230 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 235 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
231 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 236 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
232 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 237 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
233 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 238 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -247,14 +252,14 @@ testMultithreadedDelete () | |||
247 | * crashes on my system! */ | 252 | * crashes on my system! */ |
248 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 253 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
249 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 254 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
250 | { | 255 | { |
251 | fprintf (stderr, | 256 | fprintf (stderr, |
252 | "curl_easy_perform failed: `%s'\n", | 257 | "curl_easy_perform failed: `%s'\n", |
253 | curl_easy_strerror (errornum)); | 258 | curl_easy_strerror (errornum)); |
254 | curl_easy_cleanup (c); | 259 | curl_easy_cleanup (c); |
255 | MHD_stop_daemon (d); | 260 | MHD_stop_daemon (d); |
256 | return 32; | 261 | return 32; |
257 | } | 262 | } |
258 | curl_easy_cleanup (c); | 263 | curl_easy_cleanup (c); |
259 | MHD_stop_daemon (d); | 264 | MHD_stop_daemon (d); |
260 | if (cbc.pos != strlen ("/hello_world")) | 265 | if (cbc.pos != strlen ("/hello_world")) |
@@ -292,16 +297,18 @@ testMultithreadedPoolDelete () | |||
292 | if (d == NULL) | 297 | if (d == NULL) |
293 | return 16; | 298 | return 16; |
294 | if (0 == port) | 299 | if (0 == port) |
300 | { | ||
301 | const union MHD_DaemonInfo *dinfo; | ||
302 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
303 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
295 | { | 304 | { |
296 | const union MHD_DaemonInfo *dinfo; | 305 | MHD_stop_daemon (d); return 32; |
297 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
298 | if (NULL == dinfo || 0 == dinfo->port) | ||
299 | { MHD_stop_daemon (d); return 32; } | ||
300 | port = (int)dinfo->port; | ||
301 | } | 306 | } |
307 | port = (int) dinfo->port; | ||
308 | } | ||
302 | c = curl_easy_init (); | 309 | c = curl_easy_init (); |
303 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 310 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
304 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 311 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
305 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 312 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
306 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 313 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
307 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 314 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -321,14 +328,14 @@ testMultithreadedPoolDelete () | |||
321 | * crashes on my system! */ | 328 | * crashes on my system! */ |
322 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 329 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
323 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 330 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
324 | { | 331 | { |
325 | fprintf (stderr, | 332 | fprintf (stderr, |
326 | "curl_easy_perform failed: `%s'\n", | 333 | "curl_easy_perform failed: `%s'\n", |
327 | curl_easy_strerror (errornum)); | 334 | curl_easy_strerror (errornum)); |
328 | curl_easy_cleanup (c); | 335 | curl_easy_cleanup (c); |
329 | MHD_stop_daemon (d); | 336 | MHD_stop_daemon (d); |
330 | return 32; | 337 | return 32; |
331 | } | 338 | } |
332 | curl_easy_cleanup (c); | 339 | curl_easy_cleanup (c); |
333 | MHD_stop_daemon (d); | 340 | MHD_stop_daemon (d); |
334 | if (cbc.pos != strlen ("/hello_world")) | 341 | if (cbc.pos != strlen ("/hello_world")) |
@@ -381,16 +388,18 @@ testExternalDelete () | |||
381 | if (d == NULL) | 388 | if (d == NULL) |
382 | return 256; | 389 | return 256; |
383 | if (0 == port) | 390 | if (0 == port) |
391 | { | ||
392 | const union MHD_DaemonInfo *dinfo; | ||
393 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
394 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
384 | { | 395 | { |
385 | const union MHD_DaemonInfo *dinfo; | 396 | MHD_stop_daemon (d); return 32; |
386 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
387 | if (NULL == dinfo || 0 == dinfo->port) | ||
388 | { MHD_stop_daemon (d); return 32; } | ||
389 | port = (int)dinfo->port; | ||
390 | } | 397 | } |
398 | port = (int) dinfo->port; | ||
399 | } | ||
391 | c = curl_easy_init (); | 400 | c = curl_easy_init (); |
392 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 401 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
393 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 402 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
394 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 403 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
395 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 404 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
396 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 405 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -413,86 +422,88 @@ testExternalDelete () | |||
413 | 422 | ||
414 | multi = curl_multi_init (); | 423 | multi = curl_multi_init (); |
415 | if (multi == NULL) | 424 | if (multi == NULL) |
425 | { | ||
426 | curl_easy_cleanup (c); | ||
427 | MHD_stop_daemon (d); | ||
428 | return 512; | ||
429 | } | ||
430 | mret = curl_multi_add_handle (multi, c); | ||
431 | if (mret != CURLM_OK) | ||
432 | { | ||
433 | curl_multi_cleanup (multi); | ||
434 | curl_easy_cleanup (c); | ||
435 | MHD_stop_daemon (d); | ||
436 | return 1024; | ||
437 | } | ||
438 | start = time (NULL); | ||
439 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
440 | { | ||
441 | maxsock = MHD_INVALID_SOCKET; | ||
442 | maxposixs = -1; | ||
443 | FD_ZERO (&rs); | ||
444 | FD_ZERO (&ws); | ||
445 | FD_ZERO (&es); | ||
446 | curl_multi_perform (multi, &running); | ||
447 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
448 | if (mret != CURLM_OK) | ||
416 | { | 449 | { |
450 | curl_multi_remove_handle (multi, c); | ||
451 | curl_multi_cleanup (multi); | ||
417 | curl_easy_cleanup (c); | 452 | curl_easy_cleanup (c); |
418 | MHD_stop_daemon (d); | 453 | MHD_stop_daemon (d); |
419 | return 512; | 454 | return 2048; |
420 | } | 455 | } |
421 | mret = curl_multi_add_handle (multi, c); | 456 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
422 | if (mret != CURLM_OK) | ||
423 | { | 457 | { |
458 | curl_multi_remove_handle (multi, c); | ||
424 | curl_multi_cleanup (multi); | 459 | curl_multi_cleanup (multi); |
425 | curl_easy_cleanup (c); | 460 | curl_easy_cleanup (c); |
426 | MHD_stop_daemon (d); | 461 | MHD_stop_daemon (d); |
427 | return 1024; | 462 | return 4096; |
428 | } | 463 | } |
429 | start = time (NULL); | 464 | tv.tv_sec = 0; |
430 | while ((time (NULL) - start < 5) && (multi != NULL)) | 465 | tv.tv_usec = 1000; |
466 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
431 | { | 467 | { |
432 | maxsock = MHD_INVALID_SOCKET; | ||
433 | maxposixs = -1; | ||
434 | FD_ZERO (&rs); | ||
435 | FD_ZERO (&ws); | ||
436 | FD_ZERO (&es); | ||
437 | curl_multi_perform (multi, &running); | ||
438 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
439 | if (mret != CURLM_OK) | ||
440 | { | ||
441 | curl_multi_remove_handle (multi, c); | ||
442 | curl_multi_cleanup (multi); | ||
443 | curl_easy_cleanup (c); | ||
444 | MHD_stop_daemon (d); | ||
445 | return 2048; | ||
446 | } | ||
447 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
448 | { | ||
449 | curl_multi_remove_handle (multi, c); | ||
450 | curl_multi_cleanup (multi); | ||
451 | curl_easy_cleanup (c); | ||
452 | MHD_stop_daemon (d); | ||
453 | return 4096; | ||
454 | } | ||
455 | tv.tv_sec = 0; | ||
456 | tv.tv_usec = 1000; | ||
457 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
458 | { | ||
459 | #ifdef MHD_POSIX_SOCKETS | 468 | #ifdef MHD_POSIX_SOCKETS |
460 | if (EINTR != errno) | 469 | if (EINTR != errno) |
461 | abort (); | 470 | abort (); |
462 | #else | 471 | #else |
463 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 472 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
464 | abort (); | 473 | ws.fd_count) |
465 | Sleep (1000); | 474 | ||(0 != es.fd_count) ) |
475 | abort (); | ||
476 | Sleep (1000); | ||
466 | #endif | 477 | #endif |
467 | } | ||
468 | curl_multi_perform (multi, &running); | ||
469 | if (running == 0) | ||
470 | { | ||
471 | msg = curl_multi_info_read (multi, &running); | ||
472 | if (msg == NULL) | ||
473 | break; | ||
474 | if (msg->msg == CURLMSG_DONE) | ||
475 | { | ||
476 | if (msg->data.result != CURLE_OK) | ||
477 | printf ("%s failed at %s:%d: `%s'\n", | ||
478 | "curl_multi_perform", | ||
479 | __FILE__, | ||
480 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
481 | curl_multi_remove_handle (multi, c); | ||
482 | curl_multi_cleanup (multi); | ||
483 | curl_easy_cleanup (c); | ||
484 | c = NULL; | ||
485 | multi = NULL; | ||
486 | } | ||
487 | } | ||
488 | MHD_run (d); | ||
489 | } | 478 | } |
490 | if (multi != NULL) | 479 | curl_multi_perform (multi, &running); |
480 | if (running == 0) | ||
491 | { | 481 | { |
492 | curl_multi_remove_handle (multi, c); | 482 | msg = curl_multi_info_read (multi, &running); |
493 | curl_easy_cleanup (c); | 483 | if (msg == NULL) |
494 | curl_multi_cleanup (multi); | 484 | break; |
485 | if (msg->msg == CURLMSG_DONE) | ||
486 | { | ||
487 | if (msg->data.result != CURLE_OK) | ||
488 | printf ("%s failed at %s:%d: `%s'\n", | ||
489 | "curl_multi_perform", | ||
490 | __FILE__, | ||
491 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
492 | curl_multi_remove_handle (multi, c); | ||
493 | curl_multi_cleanup (multi); | ||
494 | curl_easy_cleanup (c); | ||
495 | c = NULL; | ||
496 | multi = NULL; | ||
497 | } | ||
495 | } | 498 | } |
499 | MHD_run (d); | ||
500 | } | ||
501 | if (multi != NULL) | ||
502 | { | ||
503 | curl_multi_remove_handle (multi, c); | ||
504 | curl_easy_cleanup (c); | ||
505 | curl_multi_cleanup (multi); | ||
506 | } | ||
496 | MHD_stop_daemon (d); | 507 | MHD_stop_daemon (d); |
497 | if (cbc.pos != strlen ("/hello_world")) | 508 | if (cbc.pos != strlen ("/hello_world")) |
498 | return 8192; | 509 | return 8192; |
@@ -507,19 +518,19 @@ int | |||
507 | main (int argc, char *const *argv) | 518 | main (int argc, char *const *argv) |
508 | { | 519 | { |
509 | unsigned int errorCount = 0; | 520 | unsigned int errorCount = 0; |
510 | (void)argc; /* Unused. Silent compiler warning. */ | 521 | (void) argc; /* Unused. Silent compiler warning. */ |
511 | 522 | ||
512 | if (NULL == argv || 0 == argv[0]) | 523 | if ((NULL == argv)||(0 == argv[0])) |
513 | return 99; | 524 | return 99; |
514 | oneone = has_in_name (argv[0], "11"); | 525 | oneone = has_in_name (argv[0], "11"); |
515 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 526 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
516 | return 2; | 527 | return 2; |
517 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 528 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
518 | { | 529 | { |
519 | errorCount += testInternalDelete (); | 530 | errorCount += testInternalDelete (); |
520 | errorCount += testMultithreadedDelete (); | 531 | errorCount += testMultithreadedDelete (); |
521 | errorCount += testMultithreadedPoolDelete (); | 532 | errorCount += testMultithreadedPoolDelete (); |
522 | } | 533 | } |
523 | errorCount += testExternalDelete (); | 534 | errorCount += testExternalDelete (); |
524 | if (errorCount != 0) | 535 | if (errorCount != 0) |
525 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 536 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c index b0a39bf7..4de006b7 100644 --- a/src/testcurl/test_digestauth.c +++ b/src/testcurl/test_digestauth.c | |||
@@ -44,9 +44,11 @@ | |||
44 | #include <wincrypt.h> | 44 | #include <wincrypt.h> |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" | 47 | #define PAGE \ |
48 | "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" | ||
48 | 49 | ||
49 | #define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" | 50 | #define DENIED \ |
51 | "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" | ||
50 | 52 | ||
51 | #define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" | 53 | #define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" |
52 | 54 | ||
@@ -89,48 +91,49 @@ ahc_echo (void *cls, | |||
89 | const char *password = "testpass"; | 91 | const char *password = "testpass"; |
90 | const char *realm = "test@example.com"; | 92 | const char *realm = "test@example.com"; |
91 | int ret; | 93 | int ret; |
92 | (void)cls;(void)url; /* Unused. Silent compiler warning. */ | 94 | (void) cls; (void) url; /* Unused. Silent compiler warning. */ |
93 | (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ | 95 | (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ |
94 | (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ | 96 | (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ |
95 | 97 | ||
96 | username = MHD_digest_auth_get_username (connection); | 98 | username = MHD_digest_auth_get_username (connection); |
97 | if ( (username == NULL) || | 99 | if ( (username == NULL) || |
98 | (0 != strcmp (username, "testuser")) ) | 100 | (0 != strcmp (username, "testuser")) ) |
99 | { | 101 | { |
100 | response = MHD_create_response_from_buffer (strlen (DENIED), | 102 | response = MHD_create_response_from_buffer (strlen (DENIED), |
101 | DENIED, | 103 | DENIED, |
102 | MHD_RESPMEM_PERSISTENT); | 104 | MHD_RESPMEM_PERSISTENT); |
103 | ret = MHD_queue_auth_fail_response (connection, | 105 | ret = MHD_queue_auth_fail_response (connection, |
104 | realm, | 106 | realm, |
105 | MY_OPAQUE, | 107 | MY_OPAQUE, |
106 | response, | 108 | response, |
107 | MHD_NO); | 109 | MHD_NO); |
108 | MHD_destroy_response(response); | 110 | MHD_destroy_response (response); |
109 | return ret; | 111 | return ret; |
110 | } | 112 | } |
111 | ret = MHD_digest_auth_check (connection, | 113 | ret = MHD_digest_auth_check (connection, |
112 | realm, | 114 | realm, |
113 | username, | 115 | username, |
114 | password, | 116 | password, |
115 | 300); | 117 | 300); |
116 | free (username); | 118 | free (username); |
117 | if ( (ret == MHD_INVALID_NONCE) || | 119 | if ( (ret == MHD_INVALID_NONCE) || |
118 | (ret == MHD_NO) ) | 120 | (ret == MHD_NO) ) |
119 | { | 121 | { |
120 | response = MHD_create_response_from_buffer (strlen (DENIED), | 122 | response = MHD_create_response_from_buffer (strlen (DENIED), |
121 | DENIED, | 123 | DENIED, |
122 | MHD_RESPMEM_PERSISTENT); | 124 | MHD_RESPMEM_PERSISTENT); |
123 | if (NULL == response) | 125 | if (NULL == response) |
124 | return MHD_NO; | 126 | return MHD_NO; |
125 | ret = MHD_queue_auth_fail_response (connection, | 127 | ret = MHD_queue_auth_fail_response (connection, |
126 | realm, | 128 | realm, |
127 | MY_OPAQUE, | 129 | MY_OPAQUE, |
128 | response, | 130 | response, |
129 | (MHD_INVALID_NONCE == ret) ? MHD_YES : MHD_NO); | 131 | (MHD_INVALID_NONCE == ret) ? MHD_YES : |
130 | MHD_destroy_response(response); | 132 | MHD_NO); |
131 | return ret; | 133 | MHD_destroy_response (response); |
132 | } | 134 | return ret; |
133 | response = MHD_create_response_from_buffer (strlen(PAGE), | 135 | } |
136 | response = MHD_create_response_from_buffer (strlen (PAGE), | ||
134 | PAGE, | 137 | PAGE, |
135 | MHD_RESPMEM_PERSISTENT); | 138 | MHD_RESPMEM_PERSISTENT); |
136 | ret = MHD_queue_response (connection, | 139 | ret = MHD_queue_response (connection, |
@@ -170,30 +173,30 @@ testDigestAuth () | |||
170 | fd = open ("/dev/urandom", | 173 | fd = open ("/dev/urandom", |
171 | O_RDONLY); | 174 | O_RDONLY); |
172 | if (-1 == fd) | 175 | if (-1 == fd) |
176 | { | ||
177 | fprintf (stderr, | ||
178 | "Failed to open `%s': %s\n", | ||
179 | "/dev/urandom", | ||
180 | strerror (errno)); | ||
181 | return 1; | ||
182 | } | ||
183 | while (off < 8) | ||
184 | { | ||
185 | len = read (fd, | ||
186 | rnd, | ||
187 | 8); | ||
188 | if (len == (size_t) -1) | ||
173 | { | 189 | { |
174 | fprintf (stderr, | 190 | fprintf (stderr, |
175 | "Failed to open `%s': %s\n", | 191 | "Failed to read `%s': %s\n", |
176 | "/dev/urandom", | 192 | "/dev/urandom", |
177 | strerror(errno)); | 193 | strerror (errno)); |
194 | (void) close (fd); | ||
178 | return 1; | 195 | return 1; |
179 | } | 196 | } |
180 | while (off < 8) | 197 | off += len; |
181 | { | 198 | } |
182 | len = read (fd, | 199 | (void) close (fd); |
183 | rnd, | ||
184 | 8); | ||
185 | if (len == (size_t)-1) | ||
186 | { | ||
187 | fprintf (stderr, | ||
188 | "Failed to read `%s': %s\n", | ||
189 | "/dev/urandom", | ||
190 | strerror(errno)); | ||
191 | (void) close(fd); | ||
192 | return 1; | ||
193 | } | ||
194 | off += len; | ||
195 | } | ||
196 | (void) close(fd); | ||
197 | #else | 200 | #else |
198 | { | 201 | { |
199 | HCRYPTPROV cc; | 202 | HCRYPTPROV cc; |
@@ -211,7 +214,7 @@ testDigestAuth () | |||
211 | GetLastError ()); | 214 | GetLastError ()); |
212 | return 1; | 215 | return 1; |
213 | } | 216 | } |
214 | b = CryptGenRandom (cc, 8, (BYTE*)rnd); | 217 | b = CryptGenRandom (cc, 8, (BYTE*) rnd); |
215 | if (b == 0) | 218 | if (b == 0) |
216 | { | 219 | { |
217 | fprintf (stderr, | 220 | fprintf (stderr, |
@@ -226,25 +229,25 @@ testDigestAuth () | |||
226 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 229 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
227 | port, NULL, NULL, | 230 | port, NULL, NULL, |
228 | &ahc_echo, PAGE, | 231 | &ahc_echo, PAGE, |
229 | MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, | 232 | MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, |
230 | MHD_OPTION_NONCE_NC_SIZE, 300, | 233 | MHD_OPTION_NONCE_NC_SIZE, 300, |
231 | MHD_OPTION_END); | 234 | MHD_OPTION_END); |
232 | if (d == NULL) | 235 | if (d == NULL) |
233 | return 1; | 236 | return 1; |
234 | if (0 == port) | 237 | if (0 == port) |
235 | { | 238 | { |
236 | const union MHD_DaemonInfo *dinfo; | 239 | const union MHD_DaemonInfo *dinfo; |
237 | 240 | ||
238 | dinfo = MHD_get_daemon_info (d, | 241 | dinfo = MHD_get_daemon_info (d, |
239 | MHD_DAEMON_INFO_BIND_PORT); | 242 | MHD_DAEMON_INFO_BIND_PORT); |
240 | if ( (NULL == dinfo) || | 243 | if ( (NULL == dinfo) || |
241 | (0 == dinfo->port) ) | 244 | (0 == dinfo->port) ) |
242 | { | 245 | { |
243 | MHD_stop_daemon (d); | 246 | MHD_stop_daemon (d); |
244 | return 32; | 247 | return 32; |
245 | } | ||
246 | port = (int)dinfo->port; | ||
247 | } | 248 | } |
249 | port = (int) dinfo->port; | ||
250 | } | ||
248 | snprintf (url, | 251 | snprintf (url, |
249 | sizeof (url), | 252 | sizeof (url), |
250 | "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue", | 253 | "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue", |
@@ -264,14 +267,14 @@ testDigestAuth () | |||
264 | crashes on my system!*/ | 267 | crashes on my system!*/ |
265 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 268 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
266 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 269 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
267 | { | 270 | { |
268 | fprintf (stderr, | 271 | fprintf (stderr, |
269 | "curl_easy_perform failed: `%s'\n", | 272 | "curl_easy_perform failed: `%s'\n", |
270 | curl_easy_strerror (errornum)); | 273 | curl_easy_strerror (errornum)); |
271 | curl_easy_cleanup (c); | 274 | curl_easy_cleanup (c); |
272 | MHD_stop_daemon (d); | 275 | MHD_stop_daemon (d); |
273 | return 2; | 276 | return 2; |
274 | } | 277 | } |
275 | curl_easy_cleanup (c); | 278 | curl_easy_cleanup (c); |
276 | MHD_stop_daemon (d); | 279 | MHD_stop_daemon (d); |
277 | if (cbc.pos != strlen (PAGE)) | 280 | if (cbc.pos != strlen (PAGE)) |
@@ -286,7 +289,7 @@ int | |||
286 | main (int argc, char *const *argv) | 289 | main (int argc, char *const *argv) |
287 | { | 290 | { |
288 | unsigned int errorCount = 0; | 291 | unsigned int errorCount = 0; |
289 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 292 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
290 | 293 | ||
291 | #ifdef MHD_HTTPS_REQUIRE_GRYPT | 294 | #ifdef MHD_HTTPS_REQUIRE_GRYPT |
292 | #ifdef HAVE_GCRYPT_H | 295 | #ifdef HAVE_GCRYPT_H |
@@ -296,7 +299,7 @@ main (int argc, char *const *argv) | |||
296 | #endif | 299 | #endif |
297 | #endif | 300 | #endif |
298 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 301 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
299 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 302 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
300 | return 2; | 303 | return 2; |
301 | errorCount += testDigestAuth (); | 304 | errorCount += testDigestAuth (); |
302 | if (errorCount != 0) | 305 | if (errorCount != 0) |
diff --git a/src/testcurl/test_digestauth_sha256.c b/src/testcurl/test_digestauth_sha256.c index c3430283..3482d14d 100644 --- a/src/testcurl/test_digestauth_sha256.c +++ b/src/testcurl/test_digestauth_sha256.c | |||
@@ -45,9 +45,11 @@ | |||
45 | #include <wincrypt.h> | 45 | #include <wincrypt.h> |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" | 48 | #define PAGE \ |
49 | "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" | ||
49 | 50 | ||
50 | #define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" | 51 | #define DENIED \ |
52 | "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" | ||
51 | 53 | ||
52 | #define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" | 54 | #define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" |
53 | 55 | ||
@@ -90,26 +92,26 @@ ahc_echo (void *cls, | |||
90 | const char *password = "testpass"; | 92 | const char *password = "testpass"; |
91 | const char *realm = "test@example.com"; | 93 | const char *realm = "test@example.com"; |
92 | int ret; | 94 | int ret; |
93 | (void)cls;(void)url; /* Unused. Silent compiler warning. */ | 95 | (void) cls; (void) url; /* Unused. Silent compiler warning. */ |
94 | (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ | 96 | (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ |
95 | (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ | 97 | (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ |
96 | 98 | ||
97 | username = MHD_digest_auth_get_username (connection); | 99 | username = MHD_digest_auth_get_username (connection); |
98 | if ( (username == NULL) || | 100 | if ( (username == NULL) || |
99 | (0 != strcmp (username, "testuser")) ) | 101 | (0 != strcmp (username, "testuser")) ) |
100 | { | 102 | { |
101 | response = MHD_create_response_from_buffer (strlen (DENIED), | 103 | response = MHD_create_response_from_buffer (strlen (DENIED), |
102 | DENIED, | 104 | DENIED, |
103 | MHD_RESPMEM_PERSISTENT); | 105 | MHD_RESPMEM_PERSISTENT); |
104 | ret = MHD_queue_auth_fail_response2 (connection, | 106 | ret = MHD_queue_auth_fail_response2 (connection, |
105 | realm, | 107 | realm, |
106 | MY_OPAQUE, | 108 | MY_OPAQUE, |
107 | response, | 109 | response, |
108 | MHD_NO, | 110 | MHD_NO, |
109 | MHD_DIGEST_ALG_SHA256); | 111 | MHD_DIGEST_ALG_SHA256); |
110 | MHD_destroy_response(response); | 112 | MHD_destroy_response (response); |
111 | return ret; | 113 | return ret; |
112 | } | 114 | } |
113 | ret = MHD_digest_auth_check2 (connection, | 115 | ret = MHD_digest_auth_check2 (connection, |
114 | realm, | 116 | realm, |
115 | username, | 117 | username, |
@@ -119,22 +121,23 @@ ahc_echo (void *cls, | |||
119 | free (username); | 121 | free (username); |
120 | if ( (ret == MHD_INVALID_NONCE) || | 122 | if ( (ret == MHD_INVALID_NONCE) || |
121 | (ret == MHD_NO) ) | 123 | (ret == MHD_NO) ) |
122 | { | 124 | { |
123 | response = MHD_create_response_from_buffer (strlen (DENIED), | 125 | response = MHD_create_response_from_buffer (strlen (DENIED), |
124 | DENIED, | 126 | DENIED, |
125 | MHD_RESPMEM_PERSISTENT); | 127 | MHD_RESPMEM_PERSISTENT); |
126 | if (NULL == response) | 128 | if (NULL == response) |
127 | return MHD_NO; | 129 | return MHD_NO; |
128 | ret = MHD_queue_auth_fail_response2 (connection, | 130 | ret = MHD_queue_auth_fail_response2 (connection, |
129 | realm, | 131 | realm, |
130 | MY_OPAQUE, | 132 | MY_OPAQUE, |
131 | response, | 133 | response, |
132 | (MHD_INVALID_NONCE == ret) ? MHD_YES : MHD_NO, | 134 | (MHD_INVALID_NONCE == ret) ? MHD_YES : |
133 | MHD_DIGEST_ALG_SHA256); | 135 | MHD_NO, |
134 | MHD_destroy_response(response); | 136 | MHD_DIGEST_ALG_SHA256); |
135 | return ret; | 137 | MHD_destroy_response (response); |
136 | } | 138 | return ret; |
137 | response = MHD_create_response_from_buffer (strlen(PAGE), | 139 | } |
140 | response = MHD_create_response_from_buffer (strlen (PAGE), | ||
138 | PAGE, | 141 | PAGE, |
139 | MHD_RESPMEM_PERSISTENT); | 142 | MHD_RESPMEM_PERSISTENT); |
140 | ret = MHD_queue_response (connection, | 143 | ret = MHD_queue_response (connection, |
@@ -174,30 +177,30 @@ testDigestAuth () | |||
174 | fd = open ("/dev/urandom", | 177 | fd = open ("/dev/urandom", |
175 | O_RDONLY); | 178 | O_RDONLY); |
176 | if (-1 == fd) | 179 | if (-1 == fd) |
180 | { | ||
181 | fprintf (stderr, | ||
182 | "Failed to open `%s': %s\n", | ||
183 | "/dev/urandom", | ||
184 | strerror (errno)); | ||
185 | return 1; | ||
186 | } | ||
187 | while (off < 8) | ||
188 | { | ||
189 | len = read (fd, | ||
190 | rnd, | ||
191 | 8); | ||
192 | if (len == (size_t) -1) | ||
177 | { | 193 | { |
178 | fprintf (stderr, | 194 | fprintf (stderr, |
179 | "Failed to open `%s': %s\n", | 195 | "Failed to read `%s': %s\n", |
180 | "/dev/urandom", | 196 | "/dev/urandom", |
181 | strerror(errno)); | 197 | strerror (errno)); |
198 | (void) close (fd); | ||
182 | return 1; | 199 | return 1; |
183 | } | 200 | } |
184 | while (off < 8) | 201 | off += len; |
185 | { | 202 | } |
186 | len = read (fd, | 203 | (void) close (fd); |
187 | rnd, | ||
188 | 8); | ||
189 | if (len == (size_t)-1) | ||
190 | { | ||
191 | fprintf (stderr, | ||
192 | "Failed to read `%s': %s\n", | ||
193 | "/dev/urandom", | ||
194 | strerror(errno)); | ||
195 | (void) close(fd); | ||
196 | return 1; | ||
197 | } | ||
198 | off += len; | ||
199 | } | ||
200 | (void) close(fd); | ||
201 | #else | 204 | #else |
202 | { | 205 | { |
203 | HCRYPTPROV cc; | 206 | HCRYPTPROV cc; |
@@ -215,7 +218,7 @@ testDigestAuth () | |||
215 | GetLastError ()); | 218 | GetLastError ()); |
216 | return 1; | 219 | return 1; |
217 | } | 220 | } |
218 | b = CryptGenRandom (cc, 8, (BYTE*)rnd); | 221 | b = CryptGenRandom (cc, 8, (BYTE*) rnd); |
219 | if (b == 0) | 222 | if (b == 0) |
220 | { | 223 | { |
221 | fprintf (stderr, | 224 | fprintf (stderr, |
@@ -230,25 +233,25 @@ testDigestAuth () | |||
230 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 233 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
231 | port, NULL, NULL, | 234 | port, NULL, NULL, |
232 | &ahc_echo, PAGE, | 235 | &ahc_echo, PAGE, |
233 | MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, | 236 | MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, |
234 | MHD_OPTION_NONCE_NC_SIZE, 300, | 237 | MHD_OPTION_NONCE_NC_SIZE, 300, |
235 | MHD_OPTION_END); | 238 | MHD_OPTION_END); |
236 | if (d == NULL) | 239 | if (d == NULL) |
237 | return 1; | 240 | return 1; |
238 | if (0 == port) | 241 | if (0 == port) |
239 | { | 242 | { |
240 | const union MHD_DaemonInfo *dinfo; | 243 | const union MHD_DaemonInfo *dinfo; |
241 | 244 | ||
242 | dinfo = MHD_get_daemon_info (d, | 245 | dinfo = MHD_get_daemon_info (d, |
243 | MHD_DAEMON_INFO_BIND_PORT); | 246 | MHD_DAEMON_INFO_BIND_PORT); |
244 | if ( (NULL == dinfo) || | 247 | if ( (NULL == dinfo) || |
245 | (0 == dinfo->port) ) | 248 | (0 == dinfo->port) ) |
246 | { | 249 | { |
247 | MHD_stop_daemon (d); | 250 | MHD_stop_daemon (d); |
248 | return 32; | 251 | return 32; |
249 | } | ||
250 | port = (int)dinfo->port; | ||
251 | } | 252 | } |
253 | port = (int) dinfo->port; | ||
254 | } | ||
252 | snprintf (url, | 255 | snprintf (url, |
253 | sizeof (url), | 256 | sizeof (url), |
254 | "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue", | 257 | "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue", |
@@ -268,14 +271,14 @@ testDigestAuth () | |||
268 | crashes on my system!*/ | 271 | crashes on my system!*/ |
269 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 272 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
270 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 273 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
271 | { | 274 | { |
272 | fprintf (stderr, | 275 | fprintf (stderr, |
273 | "curl_easy_perform failed: `%s'\n", | 276 | "curl_easy_perform failed: `%s'\n", |
274 | curl_easy_strerror (errornum)); | 277 | curl_easy_strerror (errornum)); |
275 | curl_easy_cleanup (c); | 278 | curl_easy_cleanup (c); |
276 | MHD_stop_daemon (d); | 279 | MHD_stop_daemon (d); |
277 | return 2; | 280 | return 2; |
278 | } | 281 | } |
279 | curl_easy_cleanup (c); | 282 | curl_easy_cleanup (c); |
280 | MHD_stop_daemon (d); | 283 | MHD_stop_daemon (d); |
281 | if (cbc.pos != strlen (PAGE)) | 284 | if (cbc.pos != strlen (PAGE)) |
@@ -291,7 +294,7 @@ main (int argc, char *const *argv) | |||
291 | { | 294 | { |
292 | unsigned int errorCount = 0; | 295 | unsigned int errorCount = 0; |
293 | curl_version_info_data *d = curl_version_info (CURLVERSION_NOW); | 296 | curl_version_info_data *d = curl_version_info (CURLVERSION_NOW); |
294 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 297 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
295 | 298 | ||
296 | /* curl added SHA256 support in 7.57 = 7.0x39 */ | 299 | /* curl added SHA256 support in 7.57 = 7.0x39 */ |
297 | if (d->version_num < 0x073900) | 300 | if (d->version_num < 0x073900) |
@@ -304,7 +307,7 @@ main (int argc, char *const *argv) | |||
304 | #endif | 307 | #endif |
305 | #endif | 308 | #endif |
306 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 309 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
307 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 310 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
308 | return 2; | 311 | return 2; |
309 | errorCount += testDigestAuth (); | 312 | errorCount += testDigestAuth (); |
310 | if (errorCount != 0) | 313 | if (errorCount != 0) |
diff --git a/src/testcurl/test_digestauth_with_arguments.c b/src/testcurl/test_digestauth_with_arguments.c index 3f2852c0..5bacdc76 100644 --- a/src/testcurl/test_digestauth_with_arguments.c +++ b/src/testcurl/test_digestauth_with_arguments.c | |||
@@ -43,9 +43,11 @@ | |||
43 | #include <wincrypt.h> | 43 | #include <wincrypt.h> |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" | 46 | #define PAGE \ |
47 | "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>" | ||
47 | 48 | ||
48 | #define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" | 49 | #define DENIED \ |
50 | "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>" | ||
49 | 51 | ||
50 | #define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" | 52 | #define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" |
51 | 53 | ||
@@ -82,48 +84,49 @@ ahc_echo (void *cls, | |||
82 | const char *password = "testpass"; | 84 | const char *password = "testpass"; |
83 | const char *realm = "test@example.com"; | 85 | const char *realm = "test@example.com"; |
84 | int ret; | 86 | int ret; |
85 | (void)cls;(void)url; /* Unused. Silent compiler warning. */ | 87 | (void) cls; (void) url; /* Unused. Silent compiler warning. */ |
86 | (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ | 88 | (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ |
87 | (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ | 89 | (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ |
88 | 90 | ||
89 | username = MHD_digest_auth_get_username(connection); | 91 | username = MHD_digest_auth_get_username (connection); |
90 | if ( (username == NULL) || | 92 | if ( (username == NULL) || |
91 | (0 != strcmp (username, "testuser")) ) | 93 | (0 != strcmp (username, "testuser")) ) |
92 | { | 94 | { |
93 | response = MHD_create_response_from_buffer(strlen (DENIED), | 95 | response = MHD_create_response_from_buffer (strlen (DENIED), |
94 | DENIED, | 96 | DENIED, |
95 | MHD_RESPMEM_PERSISTENT); | 97 | MHD_RESPMEM_PERSISTENT); |
96 | ret = MHD_queue_auth_fail_response(connection, realm, | 98 | ret = MHD_queue_auth_fail_response (connection, realm, |
97 | MY_OPAQUE, | 99 | MY_OPAQUE, |
98 | response, | 100 | response, |
99 | MHD_NO); | 101 | MHD_NO); |
100 | MHD_destroy_response(response); | 102 | MHD_destroy_response (response); |
101 | return ret; | 103 | return ret; |
102 | } | 104 | } |
103 | ret = MHD_digest_auth_check(connection, realm, | 105 | ret = MHD_digest_auth_check (connection, realm, |
104 | username, | 106 | username, |
105 | password, | 107 | password, |
106 | 300); | 108 | 300); |
107 | free(username); | 109 | free (username); |
108 | if ( (ret == MHD_INVALID_NONCE) || | 110 | if ( (ret == MHD_INVALID_NONCE) || |
109 | (ret == MHD_NO) ) | 111 | (ret == MHD_NO) ) |
110 | { | 112 | { |
111 | response = MHD_create_response_from_buffer(strlen (DENIED), | 113 | response = MHD_create_response_from_buffer (strlen (DENIED), |
112 | DENIED, | 114 | DENIED, |
113 | MHD_RESPMEM_PERSISTENT); | 115 | MHD_RESPMEM_PERSISTENT); |
114 | if (NULL == response) | 116 | if (NULL == response) |
115 | return MHD_NO; | 117 | return MHD_NO; |
116 | ret = MHD_queue_auth_fail_response(connection, realm, | 118 | ret = MHD_queue_auth_fail_response (connection, realm, |
117 | MY_OPAQUE, | 119 | MY_OPAQUE, |
118 | response, | 120 | response, |
119 | (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); | 121 | (ret == MHD_INVALID_NONCE) ? MHD_YES : |
120 | MHD_destroy_response(response); | 122 | MHD_NO); |
121 | return ret; | 123 | MHD_destroy_response (response); |
122 | } | 124 | return ret; |
123 | response = MHD_create_response_from_buffer(strlen(PAGE), PAGE, | 125 | } |
124 | MHD_RESPMEM_PERSISTENT); | 126 | response = MHD_create_response_from_buffer (strlen (PAGE), PAGE, |
125 | ret = MHD_queue_response(connection, MHD_HTTP_OK, response); | 127 | MHD_RESPMEM_PERSISTENT); |
126 | MHD_destroy_response(response); | 128 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
129 | MHD_destroy_response (response); | ||
127 | return ret; | 130 | return ret; |
128 | } | 131 | } |
129 | 132 | ||
@@ -154,45 +157,46 @@ testDigestAuth () | |||
154 | cbc.size = 2048; | 157 | cbc.size = 2048; |
155 | cbc.pos = 0; | 158 | cbc.pos = 0; |
156 | #ifndef WINDOWS | 159 | #ifndef WINDOWS |
157 | fd = open("/dev/urandom", O_RDONLY); | 160 | fd = open ("/dev/urandom", O_RDONLY); |
158 | if (-1 == fd) | 161 | if (-1 == fd) |
159 | { | 162 | { |
160 | fprintf(stderr, "Failed to open `%s': %s\n", | 163 | fprintf (stderr, "Failed to open `%s': %s\n", |
161 | "/dev/urandom", | 164 | "/dev/urandom", |
162 | strerror(errno)); | 165 | strerror (errno)); |
163 | return 1; | 166 | return 1; |
164 | } | 167 | } |
165 | while (off < 8) | 168 | while (off < 8) |
169 | { | ||
170 | len = read (fd, rnd, 8); | ||
171 | if (len == (size_t) -1) | ||
166 | { | 172 | { |
167 | len = read(fd, rnd, 8); | 173 | fprintf (stderr, |
168 | if (len == (size_t)-1) | 174 | "Failed to read `%s': %s\n", |
169 | { | 175 | "/dev/urandom", |
170 | fprintf(stderr, | 176 | strerror (errno)); |
171 | "Failed to read `%s': %s\n", | 177 | (void) close (fd); |
172 | "/dev/urandom", | 178 | return 1; |
173 | strerror(errno)); | ||
174 | (void) close(fd); | ||
175 | return 1; | ||
176 | } | ||
177 | off += len; | ||
178 | } | 179 | } |
179 | (void) close(fd); | 180 | off += len; |
181 | } | ||
182 | (void) close (fd); | ||
180 | #else | 183 | #else |
181 | { | 184 | { |
182 | HCRYPTPROV cc; | 185 | HCRYPTPROV cc; |
183 | BOOL b; | 186 | BOOL b; |
184 | b = CryptAcquireContext (&cc, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); | 187 | b = CryptAcquireContext (&cc, NULL, NULL, PROV_RSA_FULL, |
188 | CRYPT_VERIFYCONTEXT); | ||
185 | if (b == 0) | 189 | if (b == 0) |
186 | { | 190 | { |
187 | fprintf (stderr, "Failed to acquire crypto provider context: %lu\n", | 191 | fprintf (stderr, "Failed to acquire crypto provider context: %lu\n", |
188 | GetLastError ()); | 192 | GetLastError ()); |
189 | return 1; | 193 | return 1; |
190 | } | 194 | } |
191 | b = CryptGenRandom (cc, 8, (BYTE*)rnd); | 195 | b = CryptGenRandom (cc, 8, (BYTE*) rnd); |
192 | if (b == 0) | 196 | if (b == 0) |
193 | { | 197 | { |
194 | fprintf (stderr, "Failed to generate 8 random bytes: %lu\n", | 198 | fprintf (stderr, "Failed to generate 8 random bytes: %lu\n", |
195 | GetLastError ()); | 199 | GetLastError ()); |
196 | } | 200 | } |
197 | CryptReleaseContext (cc, 0); | 201 | CryptReleaseContext (cc, 0); |
198 | if (b == 0) | 202 | if (b == 0) |
@@ -201,19 +205,21 @@ testDigestAuth () | |||
201 | #endif | 205 | #endif |
202 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 206 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
203 | port, NULL, NULL, &ahc_echo, PAGE, | 207 | port, NULL, NULL, &ahc_echo, PAGE, |
204 | MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, | 208 | MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd, |
205 | MHD_OPTION_NONCE_NC_SIZE, 300, | 209 | MHD_OPTION_NONCE_NC_SIZE, 300, |
206 | MHD_OPTION_END); | 210 | MHD_OPTION_END); |
207 | if (d == NULL) | 211 | if (d == NULL) |
208 | return 1; | 212 | return 1; |
209 | if (0 == port) | 213 | if (0 == port) |
214 | { | ||
215 | const union MHD_DaemonInfo *dinfo; | ||
216 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
217 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
210 | { | 218 | { |
211 | const union MHD_DaemonInfo *dinfo; | 219 | MHD_stop_daemon (d); return 32; |
212 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
213 | if (NULL == dinfo || 0 == dinfo->port) | ||
214 | { MHD_stop_daemon (d); return 32; } | ||
215 | port = (int)dinfo->port; | ||
216 | } | 220 | } |
221 | port = (int) dinfo->port; | ||
222 | } | ||
217 | snprintf (url, | 223 | snprintf (url, |
218 | sizeof (url), | 224 | sizeof (url), |
219 | "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue", | 225 | "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue", |
@@ -233,14 +239,14 @@ testDigestAuth () | |||
233 | crashes on my system!*/ | 239 | crashes on my system!*/ |
234 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 240 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
235 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 241 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
236 | { | 242 | { |
237 | fprintf (stderr, | 243 | fprintf (stderr, |
238 | "curl_easy_perform failed: `%s'\n", | 244 | "curl_easy_perform failed: `%s'\n", |
239 | curl_easy_strerror (errornum)); | 245 | curl_easy_strerror (errornum)); |
240 | curl_easy_cleanup (c); | 246 | curl_easy_cleanup (c); |
241 | MHD_stop_daemon (d); | 247 | MHD_stop_daemon (d); |
242 | return 2; | 248 | return 2; |
243 | } | 249 | } |
244 | curl_easy_cleanup (c); | 250 | curl_easy_cleanup (c); |
245 | MHD_stop_daemon (d); | 251 | MHD_stop_daemon (d); |
246 | if (cbc.pos != strlen (PAGE)) | 252 | if (cbc.pos != strlen (PAGE)) |
@@ -255,7 +261,7 @@ int | |||
255 | main (int argc, char *const *argv) | 261 | main (int argc, char *const *argv) |
256 | { | 262 | { |
257 | unsigned int errorCount = 0; | 263 | unsigned int errorCount = 0; |
258 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 264 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
259 | 265 | ||
260 | #ifdef MHD_HTTPS_REQUIRE_GRYPT | 266 | #ifdef MHD_HTTPS_REQUIRE_GRYPT |
261 | #ifdef HAVE_GCRYPT_H | 267 | #ifdef HAVE_GCRYPT_H |
diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c index 567b0787..dee5a9c1 100644 --- a/src/testcurl/test_get.c +++ b/src/testcurl/test_get.c | |||
@@ -48,10 +48,10 @@ | |||
48 | #include <sys/socket.h> | 48 | #include <sys/socket.h> |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 51 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
52 | #undef CPU_COUNT | 52 | #undef CPU_COUNT |
53 | #endif | 53 | #endif |
54 | #if !defined(CPU_COUNT) | 54 | #if ! defined(CPU_COUNT) |
55 | #define CPU_COUNT 2 | 55 | #define CPU_COUNT 2 |
56 | #endif | 56 | #endif |
57 | 57 | ||
@@ -88,12 +88,12 @@ log_cb (void *cls, | |||
88 | (void) con; | 88 | (void) con; |
89 | if (0 != strcmp (uri, | 89 | if (0 != strcmp (uri, |
90 | EXPECTED_URI_PATH)) | 90 | EXPECTED_URI_PATH)) |
91 | { | 91 | { |
92 | fprintf (stderr, | 92 | fprintf (stderr, |
93 | "Wrong URI: `%s'\n", | 93 | "Wrong URI: `%s'\n", |
94 | uri); | 94 | uri); |
95 | _exit (22); | 95 | _exit (22); |
96 | } | 96 | } |
97 | return NULL; | 97 | return NULL; |
98 | } | 98 | } |
99 | 99 | ||
@@ -119,10 +119,10 @@ ahc_echo (void *cls, | |||
119 | if (0 != strcasecmp (me, method)) | 119 | if (0 != strcasecmp (me, method)) |
120 | return MHD_NO; /* unexpected method */ | 120 | return MHD_NO; /* unexpected method */ |
121 | if (&ptr != *unused) | 121 | if (&ptr != *unused) |
122 | { | 122 | { |
123 | *unused = &ptr; | 123 | *unused = &ptr; |
124 | return MHD_YES; | 124 | return MHD_YES; |
125 | } | 125 | } |
126 | *unused = NULL; | 126 | *unused = NULL; |
127 | v = MHD_lookup_connection_value (connection, | 127 | v = MHD_lookup_connection_value (connection, |
128 | MHD_GET_ARGUMENT_KIND, | 128 | MHD_GET_ARGUMENT_KIND, |
@@ -130,11 +130,11 @@ ahc_echo (void *cls, | |||
130 | if ( (NULL == v) || | 130 | if ( (NULL == v) || |
131 | (0 != strcmp ("&", | 131 | (0 != strcmp ("&", |
132 | v)) ) | 132 | v)) ) |
133 | { | 133 | { |
134 | fprintf (stderr, "Found while looking for 'a=&': 'a=%s'\n", | 134 | fprintf (stderr, "Found while looking for 'a=&': 'a=%s'\n", |
135 | NULL == v ? "NULL" : v); | 135 | NULL == v ? "NULL" : v); |
136 | _exit (17); | 136 | _exit (17); |
137 | } | 137 | } |
138 | v = NULL; | 138 | v = NULL; |
139 | if (MHD_YES != MHD_lookup_connection_value_n (connection, | 139 | if (MHD_YES != MHD_lookup_connection_value_n (connection, |
140 | MHD_GET_ARGUMENT_KIND, | 140 | MHD_GET_ARGUMENT_KIND, |
@@ -142,30 +142,30 @@ ahc_echo (void *cls, | |||
142 | 1, | 142 | 1, |
143 | &v, | 143 | &v, |
144 | NULL)) | 144 | NULL)) |
145 | { | 145 | { |
146 | fprintf (stderr, "Not found 'b' GET argument.\n"); | 146 | fprintf (stderr, "Not found 'b' GET argument.\n"); |
147 | _exit (18); | 147 | _exit (18); |
148 | } | 148 | } |
149 | if ( (NULL == v) || | 149 | if ( (NULL == v) || |
150 | (0 != strcmp ("c", | 150 | (0 != strcmp ("c", |
151 | v)) ) | 151 | v)) ) |
152 | { | 152 | { |
153 | fprintf (stderr, "Found while looking for 'b=c': 'b=%s'\n", | 153 | fprintf (stderr, "Found while looking for 'b=c': 'b=%s'\n", |
154 | NULL == v ? "NULL" : v); | 154 | NULL == v ? "NULL" : v); |
155 | _exit (19); | 155 | _exit (19); |
156 | } | 156 | } |
157 | response = MHD_create_response_from_buffer (strlen (url), | 157 | response = MHD_create_response_from_buffer (strlen (url), |
158 | (void *) url, | 158 | (void *) url, |
159 | MHD_RESPMEM_MUST_COPY); | 159 | MHD_RESPMEM_MUST_COPY); |
160 | ret = MHD_queue_response (connection, | 160 | ret = MHD_queue_response (connection, |
161 | MHD_HTTP_OK, | 161 | MHD_HTTP_OK, |
162 | response); | 162 | response); |
163 | MHD_destroy_response (response); | 163 | MHD_destroy_response (response); |
164 | if (ret == MHD_NO) | 164 | if (ret == MHD_NO) |
165 | { | 165 | { |
166 | fprintf (stderr, "Failed to queue response.\n"); | 166 | fprintf (stderr, "Failed to queue response.\n"); |
167 | _exit (19); | 167 | _exit (19); |
168 | } | 168 | } |
169 | return ret; | 169 | return ret; |
170 | } | 170 | } |
171 | 171 | ||
@@ -181,16 +181,17 @@ testInternalGet (int poll_flag) | |||
181 | 181 | ||
182 | if ( (0 == global_port) && | 182 | if ( (0 == global_port) && |
183 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) | 183 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) |
184 | { | 184 | { |
185 | global_port = 1220; | 185 | global_port = 1220; |
186 | if (oneone) | 186 | if (oneone) |
187 | global_port += 20; | 187 | global_port += 20; |
188 | } | 188 | } |
189 | 189 | ||
190 | cbc.buf = buf; | 190 | cbc.buf = buf; |
191 | cbc.size = 2048; | 191 | cbc.size = 2048; |
192 | cbc.pos = 0; | 192 | cbc.pos = 0; |
193 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 193 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
194 | | poll_flag, | ||
194 | global_port, NULL, NULL, | 195 | global_port, NULL, NULL, |
195 | &ahc_echo, "GET", | 196 | &ahc_echo, "GET", |
196 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | 197 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, |
@@ -198,16 +199,18 @@ testInternalGet (int poll_flag) | |||
198 | if (d == NULL) | 199 | if (d == NULL) |
199 | return 1; | 200 | return 1; |
200 | if (0 == global_port) | 201 | if (0 == global_port) |
202 | { | ||
203 | const union MHD_DaemonInfo *dinfo; | ||
204 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
205 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
201 | { | 206 | { |
202 | const union MHD_DaemonInfo *dinfo; | 207 | MHD_stop_daemon (d); return 32; |
203 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
204 | if (NULL == dinfo || 0 == dinfo->port) | ||
205 | { MHD_stop_daemon (d); return 32; } | ||
206 | global_port = (int)dinfo->port; | ||
207 | } | 208 | } |
209 | global_port = (int) dinfo->port; | ||
210 | } | ||
208 | c = curl_easy_init (); | 211 | c = curl_easy_init (); |
209 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); | 212 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
210 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 213 | curl_easy_setopt (c, CURLOPT_PORT, (long) global_port); |
211 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 214 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
212 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 215 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
213 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 216 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -222,14 +225,14 @@ testInternalGet (int poll_flag) | |||
222 | crashes on my system!*/ | 225 | crashes on my system!*/ |
223 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 226 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
224 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 227 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
225 | { | 228 | { |
226 | fprintf (stderr, | 229 | fprintf (stderr, |
227 | "curl_easy_perform failed: `%s'\n", | 230 | "curl_easy_perform failed: `%s'\n", |
228 | curl_easy_strerror (errornum)); | 231 | curl_easy_strerror (errornum)); |
229 | curl_easy_cleanup (c); | 232 | curl_easy_cleanup (c); |
230 | MHD_stop_daemon (d); | 233 | MHD_stop_daemon (d); |
231 | return 2; | 234 | return 2; |
232 | } | 235 | } |
233 | curl_easy_cleanup (c); | 236 | curl_easy_cleanup (c); |
234 | MHD_stop_daemon (d); | 237 | MHD_stop_daemon (d); |
235 | if (cbc.pos != strlen ("/hello_world")) | 238 | if (cbc.pos != strlen ("/hello_world")) |
@@ -251,16 +254,18 @@ testMultithreadedGet (int poll_flag) | |||
251 | 254 | ||
252 | if ( (0 == global_port) && | 255 | if ( (0 == global_port) && |
253 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) | 256 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) |
254 | { | 257 | { |
255 | global_port = 1221; | 258 | global_port = 1221; |
256 | if (oneone) | 259 | if (oneone) |
257 | global_port += 20; | 260 | global_port += 20; |
258 | } | 261 | } |
259 | 262 | ||
260 | cbc.buf = buf; | 263 | cbc.buf = buf; |
261 | cbc.size = 2048; | 264 | cbc.size = 2048; |
262 | cbc.pos = 0; | 265 | cbc.pos = 0; |
263 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 266 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
267 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | ||
268 | | poll_flag, | ||
264 | global_port, NULL, NULL, | 269 | global_port, NULL, NULL, |
265 | &ahc_echo, "GET", | 270 | &ahc_echo, "GET", |
266 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | 271 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, |
@@ -268,16 +273,18 @@ testMultithreadedGet (int poll_flag) | |||
268 | if (d == NULL) | 273 | if (d == NULL) |
269 | return 16; | 274 | return 16; |
270 | if (0 == global_port) | 275 | if (0 == global_port) |
276 | { | ||
277 | const union MHD_DaemonInfo *dinfo; | ||
278 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
279 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
271 | { | 280 | { |
272 | const union MHD_DaemonInfo *dinfo; | 281 | MHD_stop_daemon (d); return 32; |
273 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
274 | if (NULL == dinfo || 0 == dinfo->port) | ||
275 | { MHD_stop_daemon (d); return 32; } | ||
276 | global_port = (int)dinfo->port; | ||
277 | } | 282 | } |
283 | global_port = (int) dinfo->port; | ||
284 | } | ||
278 | c = curl_easy_init (); | 285 | c = curl_easy_init (); |
279 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); | 286 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
280 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 287 | curl_easy_setopt (c, CURLOPT_PORT, (long) global_port); |
281 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 288 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
282 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 289 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
283 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 290 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -292,14 +299,14 @@ testMultithreadedGet (int poll_flag) | |||
292 | crashes on my system! */ | 299 | crashes on my system! */ |
293 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 300 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
294 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 301 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
295 | { | 302 | { |
296 | fprintf (stderr, | 303 | fprintf (stderr, |
297 | "curl_easy_perform failed: `%s'\n", | 304 | "curl_easy_perform failed: `%s'\n", |
298 | curl_easy_strerror (errornum)); | 305 | curl_easy_strerror (errornum)); |
299 | curl_easy_cleanup (c); | 306 | curl_easy_cleanup (c); |
300 | MHD_stop_daemon (d); | 307 | MHD_stop_daemon (d); |
301 | return 32; | 308 | return 32; |
302 | } | 309 | } |
303 | curl_easy_cleanup (c); | 310 | curl_easy_cleanup (c); |
304 | MHD_stop_daemon (d); | 311 | MHD_stop_daemon (d); |
305 | if (cbc.pos != strlen ("/hello_world")) | 312 | if (cbc.pos != strlen ("/hello_world")) |
@@ -321,16 +328,17 @@ testMultithreadedPoolGet (int poll_flag) | |||
321 | 328 | ||
322 | if ( (0 == global_port) && | 329 | if ( (0 == global_port) && |
323 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) | 330 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) |
324 | { | 331 | { |
325 | global_port = 1222; | 332 | global_port = 1222; |
326 | if (oneone) | 333 | if (oneone) |
327 | global_port += 20; | 334 | global_port += 20; |
328 | } | 335 | } |
329 | 336 | ||
330 | cbc.buf = buf; | 337 | cbc.buf = buf; |
331 | cbc.size = 2048; | 338 | cbc.size = 2048; |
332 | cbc.pos = 0; | 339 | cbc.pos = 0; |
333 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 340 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
341 | | poll_flag, | ||
334 | global_port, NULL, NULL, | 342 | global_port, NULL, NULL, |
335 | &ahc_echo, "GET", | 343 | &ahc_echo, "GET", |
336 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, | 344 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, |
@@ -339,16 +347,18 @@ testMultithreadedPoolGet (int poll_flag) | |||
339 | if (d == NULL) | 347 | if (d == NULL) |
340 | return 16; | 348 | return 16; |
341 | if (0 == global_port) | 349 | if (0 == global_port) |
350 | { | ||
351 | const union MHD_DaemonInfo *dinfo; | ||
352 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
353 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
342 | { | 354 | { |
343 | const union MHD_DaemonInfo *dinfo; | 355 | MHD_stop_daemon (d); return 32; |
344 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
345 | if (NULL == dinfo || 0 == dinfo->port) | ||
346 | { MHD_stop_daemon (d); return 32; } | ||
347 | global_port = (int)dinfo->port; | ||
348 | } | 356 | } |
357 | global_port = (int) dinfo->port; | ||
358 | } | ||
349 | c = curl_easy_init (); | 359 | c = curl_easy_init (); |
350 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); | 360 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
351 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 361 | curl_easy_setopt (c, CURLOPT_PORT, (long) global_port); |
352 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 362 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
353 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 363 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
354 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 364 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -363,14 +373,14 @@ testMultithreadedPoolGet (int poll_flag) | |||
363 | crashes on my system!*/ | 373 | crashes on my system!*/ |
364 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 374 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
365 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 375 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
366 | { | 376 | { |
367 | fprintf (stderr, | 377 | fprintf (stderr, |
368 | "curl_easy_perform failed: `%s'\n", | 378 | "curl_easy_perform failed: `%s'\n", |
369 | curl_easy_strerror (errornum)); | 379 | curl_easy_strerror (errornum)); |
370 | curl_easy_cleanup (c); | 380 | curl_easy_cleanup (c); |
371 | MHD_stop_daemon (d); | 381 | MHD_stop_daemon (d); |
372 | return 32; | 382 | return 32; |
373 | } | 383 | } |
374 | curl_easy_cleanup (c); | 384 | curl_easy_cleanup (c); |
375 | MHD_stop_daemon (d); | 385 | MHD_stop_daemon (d); |
376 | if (cbc.pos != strlen ("/hello_world")) | 386 | if (cbc.pos != strlen ("/hello_world")) |
@@ -394,7 +404,7 @@ testExternalGet () | |||
394 | fd_set ws; | 404 | fd_set ws; |
395 | fd_set es; | 405 | fd_set es; |
396 | MHD_socket maxsock; | 406 | MHD_socket maxsock; |
397 | int maxposixs; | 407 | int maxposixs; |
398 | int running; | 408 | int running; |
399 | struct CURLMsg *msg; | 409 | struct CURLMsg *msg; |
400 | time_t start; | 410 | time_t start; |
@@ -402,11 +412,11 @@ testExternalGet () | |||
402 | 412 | ||
403 | if ( (0 == global_port) && | 413 | if ( (0 == global_port) && |
404 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) | 414 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) |
405 | { | 415 | { |
406 | global_port = 1223; | 416 | global_port = 1223; |
407 | if (oneone) | 417 | if (oneone) |
408 | global_port += 20; | 418 | global_port += 20; |
409 | } | 419 | } |
410 | 420 | ||
411 | multi = NULL; | 421 | multi = NULL; |
412 | cbc.buf = buf; | 422 | cbc.buf = buf; |
@@ -420,16 +430,18 @@ testExternalGet () | |||
420 | if (d == NULL) | 430 | if (d == NULL) |
421 | return 256; | 431 | return 256; |
422 | if (0 == global_port) | 432 | if (0 == global_port) |
433 | { | ||
434 | const union MHD_DaemonInfo *dinfo; | ||
435 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
436 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
423 | { | 437 | { |
424 | const union MHD_DaemonInfo *dinfo; | 438 | MHD_stop_daemon (d); return 32; |
425 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
426 | if (NULL == dinfo || 0 == dinfo->port) | ||
427 | { MHD_stop_daemon (d); return 32; } | ||
428 | global_port = (int)dinfo->port; | ||
429 | } | 439 | } |
440 | global_port = (int) dinfo->port; | ||
441 | } | ||
430 | c = curl_easy_init (); | 442 | c = curl_easy_init (); |
431 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); | 443 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
432 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 444 | curl_easy_setopt (c, CURLOPT_PORT, (long) global_port); |
433 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 445 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
434 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 446 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
435 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 447 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -447,90 +459,92 @@ testExternalGet () | |||
447 | 459 | ||
448 | multi = curl_multi_init (); | 460 | multi = curl_multi_init (); |
449 | if (multi == NULL) | 461 | if (multi == NULL) |
462 | { | ||
463 | curl_easy_cleanup (c); | ||
464 | MHD_stop_daemon (d); | ||
465 | return 512; | ||
466 | } | ||
467 | mret = curl_multi_add_handle (multi, c); | ||
468 | if (mret != CURLM_OK) | ||
469 | { | ||
470 | curl_multi_cleanup (multi); | ||
471 | curl_easy_cleanup (c); | ||
472 | MHD_stop_daemon (d); | ||
473 | return 1024; | ||
474 | } | ||
475 | start = time (NULL); | ||
476 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
477 | { | ||
478 | maxsock = MHD_INVALID_SOCKET; | ||
479 | maxposixs = -1; | ||
480 | FD_ZERO (&rs); | ||
481 | FD_ZERO (&ws); | ||
482 | FD_ZERO (&es); | ||
483 | curl_multi_perform (multi, &running); | ||
484 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
485 | if (mret != CURLM_OK) | ||
450 | { | 486 | { |
487 | curl_multi_remove_handle (multi, c); | ||
488 | curl_multi_cleanup (multi); | ||
451 | curl_easy_cleanup (c); | 489 | curl_easy_cleanup (c); |
452 | MHD_stop_daemon (d); | 490 | MHD_stop_daemon (d); |
453 | return 512; | 491 | return 2048; |
454 | } | 492 | } |
455 | mret = curl_multi_add_handle (multi, c); | 493 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
456 | if (mret != CURLM_OK) | ||
457 | { | 494 | { |
495 | curl_multi_remove_handle (multi, c); | ||
458 | curl_multi_cleanup (multi); | 496 | curl_multi_cleanup (multi); |
459 | curl_easy_cleanup (c); | 497 | curl_easy_cleanup (c); |
460 | MHD_stop_daemon (d); | 498 | MHD_stop_daemon (d); |
461 | return 1024; | 499 | return 4096; |
462 | } | 500 | } |
463 | start = time (NULL); | 501 | tv.tv_sec = 0; |
464 | while ((time (NULL) - start < 5) && (multi != NULL)) | 502 | tv.tv_usec = 1000; |
465 | { | ||
466 | maxsock = MHD_INVALID_SOCKET; | ||
467 | maxposixs = -1; | ||
468 | FD_ZERO (&rs); | ||
469 | FD_ZERO (&ws); | ||
470 | FD_ZERO (&es); | ||
471 | curl_multi_perform (multi, &running); | ||
472 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
473 | if (mret != CURLM_OK) | ||
474 | { | ||
475 | curl_multi_remove_handle (multi, c); | ||
476 | curl_multi_cleanup (multi); | ||
477 | curl_easy_cleanup (c); | ||
478 | MHD_stop_daemon (d); | ||
479 | return 2048; | ||
480 | } | ||
481 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
482 | { | ||
483 | curl_multi_remove_handle (multi, c); | ||
484 | curl_multi_cleanup (multi); | ||
485 | curl_easy_cleanup (c); | ||
486 | MHD_stop_daemon (d); | ||
487 | return 4096; | ||
488 | } | ||
489 | tv.tv_sec = 0; | ||
490 | tv.tv_usec = 1000; | ||
491 | #ifdef MHD_POSIX_SOCKETS | 503 | #ifdef MHD_POSIX_SOCKETS |
492 | if (maxsock > maxposixs) | 504 | if (maxsock > maxposixs) |
493 | maxposixs = maxsock; | 505 | maxposixs = maxsock; |
494 | #endif /* MHD_POSIX_SOCKETS */ | 506 | #endif /* MHD_POSIX_SOCKETS */ |
495 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | 507 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) |
496 | { | 508 | { |
497 | #ifdef MHD_POSIX_SOCKETS | 509 | #ifdef MHD_POSIX_SOCKETS |
498 | if (EINTR != errno) | 510 | if (EINTR != errno) |
499 | abort (); | 511 | abort (); |
500 | #else | 512 | #else |
501 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 513 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
502 | _exit (99); | 514 | ws.fd_count) |
503 | Sleep (1000); | 515 | ||(0 != es.fd_count) ) |
516 | _exit (99); | ||
517 | Sleep (1000); | ||
504 | #endif | 518 | #endif |
505 | } | ||
506 | curl_multi_perform (multi, &running); | ||
507 | if (running == 0) | ||
508 | { | ||
509 | msg = curl_multi_info_read (multi, &running); | ||
510 | if (msg == NULL) | ||
511 | break; | ||
512 | if (msg->msg == CURLMSG_DONE) | ||
513 | { | ||
514 | if (msg->data.result != CURLE_OK) | ||
515 | printf ("%s failed at %s:%d: `%s'\n", | ||
516 | "curl_multi_perform", | ||
517 | __FILE__, | ||
518 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
519 | curl_multi_remove_handle (multi, c); | ||
520 | curl_multi_cleanup (multi); | ||
521 | curl_easy_cleanup (c); | ||
522 | c = NULL; | ||
523 | multi = NULL; | ||
524 | } | ||
525 | } | ||
526 | MHD_run (d); | ||
527 | } | 519 | } |
528 | if (multi != NULL) | 520 | curl_multi_perform (multi, &running); |
521 | if (running == 0) | ||
529 | { | 522 | { |
530 | curl_multi_remove_handle (multi, c); | 523 | msg = curl_multi_info_read (multi, &running); |
531 | curl_easy_cleanup (c); | 524 | if (msg == NULL) |
532 | curl_multi_cleanup (multi); | 525 | break; |
526 | if (msg->msg == CURLMSG_DONE) | ||
527 | { | ||
528 | if (msg->data.result != CURLE_OK) | ||
529 | printf ("%s failed at %s:%d: `%s'\n", | ||
530 | "curl_multi_perform", | ||
531 | __FILE__, | ||
532 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
533 | curl_multi_remove_handle (multi, c); | ||
534 | curl_multi_cleanup (multi); | ||
535 | curl_easy_cleanup (c); | ||
536 | c = NULL; | ||
537 | multi = NULL; | ||
538 | } | ||
533 | } | 539 | } |
540 | MHD_run (d); | ||
541 | } | ||
542 | if (multi != NULL) | ||
543 | { | ||
544 | curl_multi_remove_handle (multi, c); | ||
545 | curl_easy_cleanup (c); | ||
546 | curl_multi_cleanup (multi); | ||
547 | } | ||
534 | MHD_stop_daemon (d); | 548 | MHD_stop_daemon (d); |
535 | if (cbc.pos != strlen ("/hello_world")) | 549 | if (cbc.pos != strlen ("/hello_world")) |
536 | return 8192; | 550 | return 8192; |
@@ -553,7 +567,7 @@ testUnknownPortGet (int poll_flag) | |||
553 | 567 | ||
554 | struct sockaddr_in addr; | 568 | struct sockaddr_in addr; |
555 | socklen_t addr_len = sizeof(addr); | 569 | socklen_t addr_len = sizeof(addr); |
556 | memset(&addr, 0, sizeof(addr)); | 570 | memset (&addr, 0, sizeof(addr)); |
557 | addr.sin_family = AF_INET; | 571 | addr.sin_family = AF_INET; |
558 | addr.sin_port = 0; | 572 | addr.sin_port = 0; |
559 | addr.sin_addr.s_addr = INADDR_ANY; | 573 | addr.sin_addr.s_addr = INADDR_ANY; |
@@ -561,38 +575,41 @@ testUnknownPortGet (int poll_flag) | |||
561 | cbc.buf = buf; | 575 | cbc.buf = buf; |
562 | cbc.size = 2048; | 576 | cbc.size = 2048; |
563 | cbc.pos = 0; | 577 | cbc.pos = 0; |
564 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 578 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
579 | | poll_flag, | ||
565 | 0, NULL, NULL, &ahc_echo, "GET", | 580 | 0, NULL, NULL, &ahc_echo, "GET", |
566 | MHD_OPTION_SOCK_ADDR, &addr, | 581 | MHD_OPTION_SOCK_ADDR, &addr, |
567 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | 582 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, |
568 | MHD_OPTION_END); | 583 | MHD_OPTION_END); |
569 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 584 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
570 | { | 585 | { |
571 | di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD); | 586 | di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD); |
572 | if (di == NULL) | 587 | if (di == NULL) |
573 | return 65536; | 588 | return 65536; |
574 | 589 | ||
575 | if (0 != getsockname(di->listen_fd, (struct sockaddr *) &addr, &addr_len)) | 590 | if (0 != getsockname (di->listen_fd, (struct sockaddr *) &addr, &addr_len)) |
576 | return 131072; | 591 | return 131072; |
577 | 592 | ||
578 | if (addr.sin_family != AF_INET) | 593 | if (addr.sin_family != AF_INET) |
579 | return 26214; | 594 | return 26214; |
580 | port = (int)ntohs(addr.sin_port); | 595 | port = (int) ntohs (addr.sin_port); |
581 | } | 596 | } |
582 | else | 597 | else |
598 | { | ||
599 | const union MHD_DaemonInfo *dinfo; | ||
600 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
601 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
583 | { | 602 | { |
584 | const union MHD_DaemonInfo *dinfo; | 603 | MHD_stop_daemon (d); return 32; |
585 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
586 | if (NULL == dinfo || 0 == dinfo->port) | ||
587 | { MHD_stop_daemon (d); return 32; } | ||
588 | port = (int)dinfo->port; | ||
589 | } | 604 | } |
605 | port = (int) dinfo->port; | ||
606 | } | ||
590 | 607 | ||
591 | snprintf(buf, | 608 | snprintf (buf, |
592 | sizeof(buf), | 609 | sizeof(buf), |
593 | "http://127.0.0.1:%d%s", | 610 | "http://127.0.0.1:%d%s", |
594 | port, | 611 | port, |
595 | EXPECTED_URI_PATH); | 612 | EXPECTED_URI_PATH); |
596 | 613 | ||
597 | c = curl_easy_init (); | 614 | c = curl_easy_init (); |
598 | curl_easy_setopt (c, CURLOPT_URL, buf); | 615 | curl_easy_setopt (c, CURLOPT_URL, buf); |
@@ -610,14 +627,14 @@ testUnknownPortGet (int poll_flag) | |||
610 | crashes on my system! */ | 627 | crashes on my system! */ |
611 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 628 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
612 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 629 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
613 | { | 630 | { |
614 | fprintf (stderr, | 631 | fprintf (stderr, |
615 | "curl_easy_perform failed: `%s'\n", | 632 | "curl_easy_perform failed: `%s'\n", |
616 | curl_easy_strerror (errornum)); | 633 | curl_easy_strerror (errornum)); |
617 | curl_easy_cleanup (c); | 634 | curl_easy_cleanup (c); |
618 | MHD_stop_daemon (d); | 635 | MHD_stop_daemon (d); |
619 | return 524288; | 636 | return 524288; |
620 | } | 637 | } |
621 | curl_easy_cleanup (c); | 638 | curl_easy_cleanup (c); |
622 | MHD_stop_daemon (d); | 639 | MHD_stop_daemon (d); |
623 | if (cbc.pos != strlen ("/hello_world")) | 640 | if (cbc.pos != strlen ("/hello_world")) |
@@ -631,115 +648,120 @@ testUnknownPortGet (int poll_flag) | |||
631 | static int | 648 | static int |
632 | testStopRace (int poll_flag) | 649 | testStopRace (int poll_flag) |
633 | { | 650 | { |
634 | struct sockaddr_in sin; | 651 | struct sockaddr_in sin; |
635 | MHD_socket fd; | 652 | MHD_socket fd; |
636 | struct MHD_Daemon *d; | 653 | struct MHD_Daemon *d; |
637 | |||
638 | if ( (0 == global_port) && | ||
639 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) | ||
640 | { | ||
641 | global_port = 1224; | ||
642 | if (oneone) | ||
643 | global_port += 20; | ||
644 | } | ||
645 | |||
646 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | ||
647 | global_port, NULL, NULL, | ||
648 | &ahc_echo, "GET", | ||
649 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | ||
650 | MHD_OPTION_END); | ||
651 | if (d == NULL) | ||
652 | return 16; | ||
653 | if (0 == global_port) | ||
654 | { | ||
655 | const union MHD_DaemonInfo *dinfo; | ||
656 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
657 | if (NULL == dinfo || 0 == dinfo->port) | ||
658 | { MHD_stop_daemon (d); return 32; } | ||
659 | global_port = (int)dinfo->port; | ||
660 | } | ||
661 | 654 | ||
662 | fd = socket (PF_INET, SOCK_STREAM, 0); | 655 | if ( (0 == global_port) && |
663 | if (fd == MHD_INVALID_SOCKET) | 656 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) |
657 | { | ||
658 | global_port = 1224; | ||
659 | if (oneone) | ||
660 | global_port += 20; | ||
661 | } | ||
662 | |||
663 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | ||
664 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | ||
665 | | poll_flag, | ||
666 | global_port, NULL, NULL, | ||
667 | &ahc_echo, "GET", | ||
668 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | ||
669 | MHD_OPTION_END); | ||
670 | if (d == NULL) | ||
671 | return 16; | ||
672 | if (0 == global_port) | ||
673 | { | ||
674 | const union MHD_DaemonInfo *dinfo; | ||
675 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
676 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
664 | { | 677 | { |
665 | fprintf(stderr, "socket error\n"); | 678 | MHD_stop_daemon (d); return 32; |
666 | return 256; | ||
667 | } | 679 | } |
680 | global_port = (int) dinfo->port; | ||
681 | } | ||
668 | 682 | ||
669 | memset(&sin, 0, sizeof(sin)); | 683 | fd = socket (PF_INET, SOCK_STREAM, 0); |
670 | sin.sin_family = AF_INET; | 684 | if (fd == MHD_INVALID_SOCKET) |
671 | sin.sin_port = htons(global_port); | 685 | { |
672 | sin.sin_addr.s_addr = htonl(0x7f000001); | 686 | fprintf (stderr, "socket error\n"); |
687 | return 256; | ||
688 | } | ||
673 | 689 | ||
674 | if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0) | 690 | memset (&sin, 0, sizeof(sin)); |
675 | { | 691 | sin.sin_family = AF_INET; |
676 | fprintf(stderr, "connect error\n"); | 692 | sin.sin_port = htons (global_port); |
677 | MHD_socket_close_chk_ (fd); | 693 | sin.sin_addr.s_addr = htonl (0x7f000001); |
678 | return 512; | ||
679 | } | ||
680 | 694 | ||
681 | /* printf("Waiting\n"); */ | 695 | if (connect (fd, (struct sockaddr *) (&sin), sizeof(sin)) < 0) |
682 | /* Let the thread get going. */ | 696 | { |
683 | usleep(500000); | 697 | fprintf (stderr, "connect error\n"); |
698 | MHD_socket_close_chk_ (fd); | ||
699 | return 512; | ||
700 | } | ||
684 | 701 | ||
685 | /* printf("Stopping daemon\n"); */ | 702 | /* printf("Waiting\n"); */ |
686 | MHD_stop_daemon (d); | 703 | /* Let the thread get going. */ |
704 | usleep (500000); | ||
687 | 705 | ||
688 | MHD_socket_close_chk_ (fd); | 706 | /* printf("Stopping daemon\n"); */ |
707 | MHD_stop_daemon (d); | ||
708 | |||
709 | MHD_socket_close_chk_ (fd); | ||
689 | 710 | ||
690 | /* printf("good\n"); */ | 711 | /* printf("good\n"); */ |
691 | return 0; | 712 | return 0; |
692 | } | 713 | } |
693 | 714 | ||
694 | 715 | ||
695 | static int | 716 | static int |
696 | ahc_empty (void *cls, | 717 | ahc_empty (void *cls, |
697 | struct MHD_Connection *connection, | 718 | struct MHD_Connection *connection, |
698 | const char *url, | 719 | const char *url, |
699 | const char *method, | 720 | const char *method, |
700 | const char *version, | 721 | const char *version, |
701 | const char *upload_data, size_t *upload_data_size, | 722 | const char *upload_data, size_t *upload_data_size, |
702 | void **unused) | 723 | void **unused) |
703 | { | 724 | { |
704 | static int ptr; | 725 | static int ptr; |
705 | struct MHD_Response *response; | 726 | struct MHD_Response *response; |
706 | int ret; | 727 | int ret; |
707 | (void)cls;(void)url;(void)url;(void)version; /* Unused. Silent compiler warning. */ | 728 | (void) cls; (void) url; (void) url; (void) version; /* Unused. Silent compiler warning. */ |
708 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 729 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
709 | 730 | ||
710 | if (0 != strcasecmp ("GET", method)) | 731 | if (0 != strcasecmp ("GET", method)) |
711 | return MHD_NO; /* unexpected method */ | 732 | return MHD_NO; /* unexpected method */ |
712 | if (&ptr != *unused) | 733 | if (&ptr != *unused) |
713 | { | 734 | { |
714 | *unused = &ptr; | 735 | *unused = &ptr; |
715 | return MHD_YES; | 736 | return MHD_YES; |
716 | } | 737 | } |
717 | *unused = NULL; | 738 | *unused = NULL; |
718 | response = MHD_create_response_from_buffer (0, | 739 | response = MHD_create_response_from_buffer (0, |
719 | NULL, | 740 | NULL, |
720 | MHD_RESPMEM_PERSISTENT); | 741 | MHD_RESPMEM_PERSISTENT); |
721 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 742 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
722 | MHD_destroy_response (response); | 743 | MHD_destroy_response (response); |
723 | if (ret == MHD_NO) | 744 | if (ret == MHD_NO) |
724 | { | 745 | { |
725 | fprintf (stderr, "Failed to queue response.\n"); | 746 | fprintf (stderr, "Failed to queue response.\n"); |
726 | _exit (20); | 747 | _exit (20); |
727 | } | 748 | } |
728 | return ret; | 749 | return ret; |
729 | } | 750 | } |
730 | 751 | ||
731 | 752 | ||
732 | static int | 753 | static int |
733 | curlExcessFound(CURL *c, curl_infotype type, char *data, size_t size, void *cls) | 754 | curlExcessFound (CURL *c, curl_infotype type, char *data, size_t size, |
755 | void *cls) | ||
734 | { | 756 | { |
735 | static const char *excess_found = "Excess found"; | 757 | static const char *excess_found = "Excess found"; |
736 | const size_t str_size = strlen (excess_found); | 758 | const size_t str_size = strlen (excess_found); |
737 | (void)c; /* Unused. Silent compiler warning. */ | 759 | (void) c; /* Unused. Silent compiler warning. */ |
738 | 760 | ||
739 | if (CURLINFO_TEXT == type | 761 | if ((CURLINFO_TEXT == type) |
740 | && size >= str_size | 762 | &&(size >= str_size) |
741 | && 0 == strncmp(excess_found, data, str_size)) | 763 | &&(0 == strncmp (excess_found, data, str_size))) |
742 | *(int *)cls = 1; | 764 | *(int *) cls = 1; |
743 | return 0; | 765 | return 0; |
744 | } | 766 | } |
745 | 767 | ||
@@ -756,16 +778,17 @@ testEmptyGet (int poll_flag) | |||
756 | 778 | ||
757 | if ( (0 == global_port) && | 779 | if ( (0 == global_port) && |
758 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) | 780 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) |
759 | { | 781 | { |
760 | global_port = 1225; | 782 | global_port = 1225; |
761 | if (oneone) | 783 | if (oneone) |
762 | global_port += 20; | 784 | global_port += 20; |
763 | } | 785 | } |
764 | 786 | ||
765 | cbc.buf = buf; | 787 | cbc.buf = buf; |
766 | cbc.size = 2048; | 788 | cbc.size = 2048; |
767 | cbc.pos = 0; | 789 | cbc.pos = 0; |
768 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 790 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
791 | | poll_flag, | ||
769 | global_port, NULL, NULL, | 792 | global_port, NULL, NULL, |
770 | &ahc_empty, NULL, | 793 | &ahc_empty, NULL, |
771 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | 794 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, |
@@ -773,16 +796,18 @@ testEmptyGet (int poll_flag) | |||
773 | if (d == NULL) | 796 | if (d == NULL) |
774 | return 4194304; | 797 | return 4194304; |
775 | if (0 == global_port) | 798 | if (0 == global_port) |
799 | { | ||
800 | const union MHD_DaemonInfo *dinfo; | ||
801 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
802 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
776 | { | 803 | { |
777 | const union MHD_DaemonInfo *dinfo; | 804 | MHD_stop_daemon (d); return 32; |
778 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
779 | if (NULL == dinfo || 0 == dinfo->port) | ||
780 | { MHD_stop_daemon (d); return 32; } | ||
781 | global_port = (int)dinfo->port; | ||
782 | } | 805 | } |
806 | global_port = (int) dinfo->port; | ||
807 | } | ||
783 | c = curl_easy_init (); | 808 | c = curl_easy_init (); |
784 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); | 809 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
785 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 810 | curl_easy_setopt (c, CURLOPT_PORT, (long) global_port); |
786 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 811 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
787 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 812 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
788 | curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound); | 813 | curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound); |
@@ -800,14 +825,14 @@ testEmptyGet (int poll_flag) | |||
800 | crashes on my system!*/ | 825 | crashes on my system!*/ |
801 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 826 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
802 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 827 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
803 | { | 828 | { |
804 | fprintf (stderr, | 829 | fprintf (stderr, |
805 | "curl_easy_perform failed: `%s'\n", | 830 | "curl_easy_perform failed: `%s'\n", |
806 | curl_easy_strerror (errornum)); | 831 | curl_easy_strerror (errornum)); |
807 | curl_easy_cleanup (c); | 832 | curl_easy_cleanup (c); |
808 | MHD_stop_daemon (d); | 833 | MHD_stop_daemon (d); |
809 | return 8388608; | 834 | return 8388608; |
810 | } | 835 | } |
811 | curl_easy_cleanup (c); | 836 | curl_easy_cleanup (c); |
812 | MHD_stop_daemon (d); | 837 | MHD_stop_daemon (d); |
813 | if (cbc.pos != 0) | 838 | if (cbc.pos != 0) |
@@ -825,7 +850,7 @@ main (int argc, char *const *argv) | |||
825 | unsigned int test_result = 0; | 850 | unsigned int test_result = 0; |
826 | int verbose = 0; | 851 | int verbose = 0; |
827 | 852 | ||
828 | if (NULL == argv || 0 == argv[0]) | 853 | if ((NULL == argv)||(0 == argv[0])) |
829 | return 99; | 854 | return 99; |
830 | oneone = has_in_name (argv[0], "11"); | 855 | oneone = has_in_name (argv[0], "11"); |
831 | verbose = has_param (argc, argv, "-v") || has_param (argc, argv, "--verbose"); | 856 | verbose = has_param (argc, argv, "-v") || has_param (argc, argv, "--verbose"); |
@@ -838,115 +863,128 @@ main (int argc, char *const *argv) | |||
838 | else if (verbose) | 863 | else if (verbose) |
839 | printf ("PASSED: testExternalGet ().\n"); | 864 | printf ("PASSED: testExternalGet ().\n"); |
840 | errorCount += test_result; | 865 | errorCount += test_result; |
841 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 866 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
842 | { | 867 | { |
843 | test_result += testInternalGet (0); | 868 | test_result += testInternalGet (0); |
869 | if (test_result) | ||
870 | fprintf (stderr, "FAILED: testInternalGet (0) - %u.\n", test_result); | ||
871 | else if (verbose) | ||
872 | printf ("PASSED: testInternalGet (0).\n"); | ||
873 | errorCount += test_result; | ||
874 | test_result += testMultithreadedGet (0); | ||
875 | if (test_result) | ||
876 | fprintf (stderr, "FAILED: testMultithreadedGet (0) - %u.\n", test_result); | ||
877 | else if (verbose) | ||
878 | printf ("PASSED: testMultithreadedGet (0).\n"); | ||
879 | errorCount += test_result; | ||
880 | test_result += testMultithreadedPoolGet (0); | ||
881 | if (test_result) | ||
882 | fprintf (stderr, "FAILED: testMultithreadedPoolGet (0) - %u.\n", | ||
883 | test_result); | ||
884 | else if (verbose) | ||
885 | printf ("PASSED: testMultithreadedPoolGet (0).\n"); | ||
886 | errorCount += test_result; | ||
887 | test_result += testUnknownPortGet (0); | ||
888 | if (test_result) | ||
889 | fprintf (stderr, "FAILED: testUnknownPortGet (0) - %u.\n", test_result); | ||
890 | else if (verbose) | ||
891 | printf ("PASSED: testUnknownPortGet (0).\n"); | ||
892 | errorCount += test_result; | ||
893 | test_result += testStopRace (0); | ||
894 | if (test_result) | ||
895 | fprintf (stderr, "FAILED: testStopRace (0) - %u.\n", test_result); | ||
896 | else if (verbose) | ||
897 | printf ("PASSED: testStopRace (0).\n"); | ||
898 | errorCount += test_result; | ||
899 | test_result += testEmptyGet (0); | ||
900 | if (test_result) | ||
901 | fprintf (stderr, "FAILED: testEmptyGet (0) - %u.\n", test_result); | ||
902 | else if (verbose) | ||
903 | printf ("PASSED: testEmptyGet (0).\n"); | ||
904 | errorCount += test_result; | ||
905 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL)) | ||
906 | { | ||
907 | test_result += testInternalGet (MHD_USE_POLL); | ||
908 | if (test_result) | ||
909 | fprintf (stderr, "FAILED: testInternalGet (MHD_USE_POLL) - %u.\n", | ||
910 | test_result); | ||
911 | else if (verbose) | ||
912 | printf ("PASSED: testInternalGet (MHD_USE_POLL).\n"); | ||
913 | errorCount += test_result; | ||
914 | test_result += testMultithreadedGet (MHD_USE_POLL); | ||
915 | if (test_result) | ||
916 | fprintf (stderr, "FAILED: testMultithreadedGet (MHD_USE_POLL) - %u.\n", | ||
917 | test_result); | ||
918 | else if (verbose) | ||
919 | printf ("PASSED: testMultithreadedGet (MHD_USE_POLL).\n"); | ||
920 | errorCount += test_result; | ||
921 | test_result += testMultithreadedPoolGet (MHD_USE_POLL); | ||
844 | if (test_result) | 922 | if (test_result) |
845 | fprintf (stderr, "FAILED: testInternalGet (0) - %u.\n", test_result); | 923 | fprintf (stderr, |
924 | "FAILED: testMultithreadedPoolGet (MHD_USE_POLL) - %u.\n", | ||
925 | test_result); | ||
846 | else if (verbose) | 926 | else if (verbose) |
847 | printf ("PASSED: testInternalGet (0).\n"); | 927 | printf ("PASSED: testMultithreadedPoolGet (MHD_USE_POLL).\n"); |
848 | errorCount += test_result; | 928 | errorCount += test_result; |
849 | test_result += testMultithreadedGet (0); | 929 | test_result += testUnknownPortGet (MHD_USE_POLL); |
850 | if (test_result) | 930 | if (test_result) |
851 | fprintf (stderr, "FAILED: testMultithreadedGet (0) - %u.\n", test_result); | 931 | fprintf (stderr, "FAILED: testUnknownPortGet (MHD_USE_POLL) - %u.\n", |
932 | test_result); | ||
852 | else if (verbose) | 933 | else if (verbose) |
853 | printf ("PASSED: testMultithreadedGet (0).\n"); | 934 | printf ("PASSED: testUnknownPortGet (MHD_USE_POLL).\n"); |
854 | errorCount += test_result; | 935 | errorCount += test_result; |
855 | test_result += testMultithreadedPoolGet (0); | 936 | test_result += testStopRace (MHD_USE_POLL); |
937 | if (test_result) | ||
938 | fprintf (stderr, "FAILED: testStopRace (MHD_USE_POLL) - %u.\n", | ||
939 | test_result); | ||
940 | else if (verbose) | ||
941 | printf ("PASSED: testStopRace (MHD_USE_POLL).\n"); | ||
942 | errorCount += test_result; | ||
943 | test_result += testEmptyGet (MHD_USE_POLL); | ||
944 | if (test_result) | ||
945 | fprintf (stderr, "FAILED: testEmptyGet (MHD_USE_POLL) - %u.\n", | ||
946 | test_result); | ||
947 | else if (verbose) | ||
948 | printf ("PASSED: testEmptyGet (MHD_USE_POLL).\n"); | ||
949 | errorCount += test_result; | ||
950 | } | ||
951 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL)) | ||
952 | { | ||
953 | test_result += testInternalGet (MHD_USE_EPOLL); | ||
856 | if (test_result) | 954 | if (test_result) |
857 | fprintf (stderr, "FAILED: testMultithreadedPoolGet (0) - %u.\n", test_result); | 955 | fprintf (stderr, "FAILED: testInternalGet (MHD_USE_EPOLL) - %u.\n", |
956 | test_result); | ||
858 | else if (verbose) | 957 | else if (verbose) |
859 | printf ("PASSED: testMultithreadedPoolGet (0).\n"); | 958 | printf ("PASSED: testInternalGet (MHD_USE_EPOLL).\n"); |
860 | errorCount += test_result; | 959 | errorCount += test_result; |
861 | test_result += testUnknownPortGet (0); | 960 | test_result += testMultithreadedPoolGet (MHD_USE_EPOLL); |
862 | if (test_result) | 961 | if (test_result) |
863 | fprintf (stderr, "FAILED: testUnknownPortGet (0) - %u.\n", test_result); | 962 | fprintf (stderr, |
963 | "FAILED: testMultithreadedPoolGet (MHD_USE_EPOLL) - %u.\n", | ||
964 | test_result); | ||
864 | else if (verbose) | 965 | else if (verbose) |
865 | printf ("PASSED: testUnknownPortGet (0).\n"); | 966 | printf ("PASSED: testMultithreadedPoolGet (MHD_USE_EPOLL).\n"); |
866 | errorCount += test_result; | 967 | errorCount += test_result; |
867 | test_result += testStopRace (0); | 968 | test_result += testUnknownPortGet (MHD_USE_EPOLL); |
868 | if (test_result) | 969 | if (test_result) |
869 | fprintf (stderr, "FAILED: testStopRace (0) - %u.\n", test_result); | 970 | fprintf (stderr, "FAILED: testUnknownPortGet (MHD_USE_EPOLL) - %u.\n", |
971 | test_result); | ||
870 | else if (verbose) | 972 | else if (verbose) |
871 | printf ("PASSED: testStopRace (0).\n"); | 973 | printf ("PASSED: testUnknownPortGet (MHD_USE_EPOLL).\n"); |
872 | errorCount += test_result; | 974 | errorCount += test_result; |
873 | test_result += testEmptyGet (0); | 975 | test_result += testEmptyGet (MHD_USE_EPOLL); |
874 | if (test_result) | 976 | if (test_result) |
875 | fprintf (stderr, "FAILED: testEmptyGet (0) - %u.\n", test_result); | 977 | fprintf (stderr, "FAILED: testEmptyGet (MHD_USE_EPOLL) - %u.\n", |
978 | test_result); | ||
876 | else if (verbose) | 979 | else if (verbose) |
877 | printf ("PASSED: testEmptyGet (0).\n"); | 980 | printf ("PASSED: testEmptyGet (MHD_USE_EPOLL).\n"); |
878 | errorCount += test_result; | 981 | errorCount += test_result; |
879 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL)) | ||
880 | { | ||
881 | test_result += testInternalGet(MHD_USE_POLL); | ||
882 | if (test_result) | ||
883 | fprintf (stderr, "FAILED: testInternalGet (MHD_USE_POLL) - %u.\n", test_result); | ||
884 | else if (verbose) | ||
885 | printf ("PASSED: testInternalGet (MHD_USE_POLL).\n"); | ||
886 | errorCount += test_result; | ||
887 | test_result += testMultithreadedGet(MHD_USE_POLL); | ||
888 | if (test_result) | ||
889 | fprintf (stderr, "FAILED: testMultithreadedGet (MHD_USE_POLL) - %u.\n", test_result); | ||
890 | else if (verbose) | ||
891 | printf ("PASSED: testMultithreadedGet (MHD_USE_POLL).\n"); | ||
892 | errorCount += test_result; | ||
893 | test_result += testMultithreadedPoolGet(MHD_USE_POLL); | ||
894 | if (test_result) | ||
895 | fprintf (stderr, "FAILED: testMultithreadedPoolGet (MHD_USE_POLL) - %u.\n", test_result); | ||
896 | else if (verbose) | ||
897 | printf ("PASSED: testMultithreadedPoolGet (MHD_USE_POLL).\n"); | ||
898 | errorCount += test_result; | ||
899 | test_result += testUnknownPortGet(MHD_USE_POLL); | ||
900 | if (test_result) | ||
901 | fprintf (stderr, "FAILED: testUnknownPortGet (MHD_USE_POLL) - %u.\n", test_result); | ||
902 | else if (verbose) | ||
903 | printf ("PASSED: testUnknownPortGet (MHD_USE_POLL).\n"); | ||
904 | errorCount += test_result; | ||
905 | test_result += testStopRace(MHD_USE_POLL); | ||
906 | if (test_result) | ||
907 | fprintf (stderr, "FAILED: testStopRace (MHD_USE_POLL) - %u.\n", test_result); | ||
908 | else if (verbose) | ||
909 | printf ("PASSED: testStopRace (MHD_USE_POLL).\n"); | ||
910 | errorCount += test_result; | ||
911 | test_result += testEmptyGet(MHD_USE_POLL); | ||
912 | if (test_result) | ||
913 | fprintf (stderr, "FAILED: testEmptyGet (MHD_USE_POLL) - %u.\n", test_result); | ||
914 | else if (verbose) | ||
915 | printf ("PASSED: testEmptyGet (MHD_USE_POLL).\n"); | ||
916 | errorCount += test_result; | ||
917 | } | ||
918 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL)) | ||
919 | { | ||
920 | test_result += testInternalGet(MHD_USE_EPOLL); | ||
921 | if (test_result) | ||
922 | fprintf (stderr, "FAILED: testInternalGet (MHD_USE_EPOLL) - %u.\n", test_result); | ||
923 | else if (verbose) | ||
924 | printf ("PASSED: testInternalGet (MHD_USE_EPOLL).\n"); | ||
925 | errorCount += test_result; | ||
926 | test_result += testMultithreadedPoolGet(MHD_USE_EPOLL); | ||
927 | if (test_result) | ||
928 | fprintf (stderr, "FAILED: testMultithreadedPoolGet (MHD_USE_EPOLL) - %u.\n", test_result); | ||
929 | else if (verbose) | ||
930 | printf ("PASSED: testMultithreadedPoolGet (MHD_USE_EPOLL).\n"); | ||
931 | errorCount += test_result; | ||
932 | test_result += testUnknownPortGet(MHD_USE_EPOLL); | ||
933 | if (test_result) | ||
934 | fprintf (stderr, "FAILED: testUnknownPortGet (MHD_USE_EPOLL) - %u.\n", test_result); | ||
935 | else if (verbose) | ||
936 | printf ("PASSED: testUnknownPortGet (MHD_USE_EPOLL).\n"); | ||
937 | errorCount += test_result; | ||
938 | test_result += testEmptyGet(MHD_USE_EPOLL); | ||
939 | if (test_result) | ||
940 | fprintf (stderr, "FAILED: testEmptyGet (MHD_USE_EPOLL) - %u.\n", test_result); | ||
941 | else if (verbose) | ||
942 | printf ("PASSED: testEmptyGet (MHD_USE_EPOLL).\n"); | ||
943 | errorCount += test_result; | ||
944 | } | ||
945 | } | 982 | } |
983 | } | ||
946 | if (0 != errorCount) | 984 | if (0 != errorCount) |
947 | fprintf (stderr, | 985 | fprintf (stderr, |
948 | "Error (code: %u)\n", | 986 | "Error (code: %u)\n", |
949 | errorCount); | 987 | errorCount); |
950 | else if (verbose) | 988 | else if (verbose) |
951 | printf ("All tests passed.\n"); | 989 | printf ("All tests passed.\n"); |
952 | curl_global_cleanup (); | 990 | curl_global_cleanup (); |
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c index c7be5c83..9916a902 100644 --- a/src/testcurl/test_get_chunked.c +++ b/src/testcurl/test_get_chunked.c | |||
@@ -40,10 +40,10 @@ | |||
40 | #include <unistd.h> | 40 | #include <unistd.h> |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 43 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
44 | #undef CPU_COUNT | 44 | #undef CPU_COUNT |
45 | #endif | 45 | #endif |
46 | #if !defined(CPU_COUNT) | 46 | #if ! defined(CPU_COUNT) |
47 | #define CPU_COUNT 2 | 47 | #define CPU_COUNT 2 |
48 | #endif | 48 | #endif |
49 | 49 | ||
@@ -120,19 +120,19 @@ ahc_echo (void *cls, | |||
120 | struct MHD_Response **responseptr; | 120 | struct MHD_Response **responseptr; |
121 | int ret; | 121 | int ret; |
122 | 122 | ||
123 | (void)url; | 123 | (void) url; |
124 | (void)version; /* Unused. Silent compiler warning. */ | 124 | (void) version; /* Unused. Silent compiler warning. */ |
125 | (void)upload_data; | 125 | (void) upload_data; |
126 | (void)upload_data_size; /* Unused. Silent compiler warning. */ | 126 | (void) upload_data_size; /* Unused. Silent compiler warning. */ |
127 | 127 | ||
128 | if (0 != strcmp (me, method)) | 128 | if (0 != strcmp (me, method)) |
129 | return MHD_NO; /* unexpected method */ | 129 | return MHD_NO; /* unexpected method */ |
130 | if (&aptr != *ptr) | 130 | if (&aptr != *ptr) |
131 | { | 131 | { |
132 | /* do never respond on first call */ | 132 | /* do never respond on first call */ |
133 | *ptr = &aptr; | 133 | *ptr = &aptr; |
134 | return MHD_YES; | 134 | return MHD_YES; |
135 | } | 135 | } |
136 | responseptr = malloc (sizeof (struct MHD_Response *)); | 136 | responseptr = malloc (sizeof (struct MHD_Response *)); |
137 | if (NULL == responseptr) | 137 | if (NULL == responseptr) |
138 | return MHD_NO; | 138 | return MHD_NO; |
@@ -165,16 +165,16 @@ validate (struct CBC cbc, int ebase) | |||
165 | return ebase; | 165 | return ebase; |
166 | 166 | ||
167 | for (i = 0; i < 10; i++) | 167 | for (i = 0; i < 10; i++) |
168 | { | ||
169 | memset (buf, 'A' + i, 128); | ||
170 | if (0 != memcmp (buf, &cbc.buf[i * 128], 128)) | ||
168 | { | 171 | { |
169 | memset (buf, 'A' + i, 128); | 172 | fprintf (stderr, |
170 | if (0 != memcmp (buf, &cbc.buf[i * 128], 128)) | 173 | "Got `%.*s'\nWant `%.*s'\n", |
171 | { | 174 | 128, buf, 128, &cbc.buf[i * 128]); |
172 | fprintf (stderr, | 175 | return ebase * 2; |
173 | "Got `%.*s'\nWant `%.*s'\n", | ||
174 | 128, buf, 128, &cbc.buf[i * 128]); | ||
175 | return ebase * 2; | ||
176 | } | ||
177 | } | 176 | } |
177 | } | ||
178 | return 0; | 178 | return 0; |
179 | } | 179 | } |
180 | 180 | ||
@@ -201,16 +201,18 @@ testInternalGet () | |||
201 | if (d == NULL) | 201 | if (d == NULL) |
202 | return 1; | 202 | return 1; |
203 | if (0 == port) | 203 | if (0 == port) |
204 | { | ||
205 | const union MHD_DaemonInfo *dinfo; | ||
206 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
207 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
204 | { | 208 | { |
205 | const union MHD_DaemonInfo *dinfo; | 209 | MHD_stop_daemon (d); return 32; |
206 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
207 | if (NULL == dinfo || 0 == dinfo->port) | ||
208 | { MHD_stop_daemon (d); return 32; } | ||
209 | port = (int)dinfo->port; | ||
210 | } | 210 | } |
211 | port = (int) dinfo->port; | ||
212 | } | ||
211 | c = curl_easy_init (); | 213 | c = curl_easy_init (); |
212 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 214 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
213 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 215 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
214 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 216 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
215 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 217 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
216 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 218 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -222,14 +224,14 @@ testInternalGet () | |||
222 | * crashes on my system! */ | 224 | * crashes on my system! */ |
223 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 225 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
224 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 226 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
225 | { | 227 | { |
226 | fprintf (stderr, | 228 | fprintf (stderr, |
227 | "curl_easy_perform failed: `%s'\n", | 229 | "curl_easy_perform failed: `%s'\n", |
228 | curl_easy_strerror (errornum)); | 230 | curl_easy_strerror (errornum)); |
229 | curl_easy_cleanup (c); | 231 | curl_easy_cleanup (c); |
230 | MHD_stop_daemon (d); | 232 | MHD_stop_daemon (d); |
231 | return 2; | 233 | return 2; |
232 | } | 234 | } |
233 | curl_easy_cleanup (c); | 235 | curl_easy_cleanup (c); |
234 | MHD_stop_daemon (d); | 236 | MHD_stop_daemon (d); |
235 | return validate (cbc, 4); | 237 | return validate (cbc, 4); |
@@ -253,21 +255,24 @@ testMultithreadedGet () | |||
253 | cbc.buf = buf; | 255 | cbc.buf = buf; |
254 | cbc.size = 2048; | 256 | cbc.size = 2048; |
255 | cbc.pos = 0; | 257 | cbc.pos = 0; |
256 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 258 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
259 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
257 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 260 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
258 | if (d == NULL) | 261 | if (d == NULL) |
259 | return 16; | 262 | return 16; |
260 | if (0 == port) | 263 | if (0 == port) |
264 | { | ||
265 | const union MHD_DaemonInfo *dinfo; | ||
266 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
267 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
261 | { | 268 | { |
262 | const union MHD_DaemonInfo *dinfo; | 269 | MHD_stop_daemon (d); return 32; |
263 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
264 | if (NULL == dinfo || 0 == dinfo->port) | ||
265 | { MHD_stop_daemon (d); return 32; } | ||
266 | port = (int)dinfo->port; | ||
267 | } | 270 | } |
271 | port = (int) dinfo->port; | ||
272 | } | ||
268 | c = curl_easy_init (); | 273 | c = curl_easy_init (); |
269 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 274 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
270 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 275 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
271 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 276 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
272 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 277 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
273 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 278 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -279,14 +284,14 @@ testMultithreadedGet () | |||
279 | * crashes on my system! */ | 284 | * crashes on my system! */ |
280 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 285 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
281 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 286 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
282 | { | 287 | { |
283 | fprintf (stderr, | 288 | fprintf (stderr, |
284 | "curl_easy_perform failed: `%s'\n", | 289 | "curl_easy_perform failed: `%s'\n", |
285 | curl_easy_strerror (errornum)); | 290 | curl_easy_strerror (errornum)); |
286 | curl_easy_cleanup (c); | 291 | curl_easy_cleanup (c); |
287 | MHD_stop_daemon (d); | 292 | MHD_stop_daemon (d); |
288 | return 32; | 293 | return 32; |
289 | } | 294 | } |
290 | curl_easy_cleanup (c); | 295 | curl_easy_cleanup (c); |
291 | MHD_stop_daemon (d); | 296 | MHD_stop_daemon (d); |
292 | return validate (cbc, 64); | 297 | return validate (cbc, 64); |
@@ -316,16 +321,18 @@ testMultithreadedPoolGet () | |||
316 | if (d == NULL) | 321 | if (d == NULL) |
317 | return 16; | 322 | return 16; |
318 | if (0 == port) | 323 | if (0 == port) |
324 | { | ||
325 | const union MHD_DaemonInfo *dinfo; | ||
326 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
327 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
319 | { | 328 | { |
320 | const union MHD_DaemonInfo *dinfo; | 329 | MHD_stop_daemon (d); return 32; |
321 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
322 | if (NULL == dinfo || 0 == dinfo->port) | ||
323 | { MHD_stop_daemon (d); return 32; } | ||
324 | port = (int)dinfo->port; | ||
325 | } | 330 | } |
331 | port = (int) dinfo->port; | ||
332 | } | ||
326 | c = curl_easy_init (); | 333 | c = curl_easy_init (); |
327 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 334 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
328 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 335 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
329 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 336 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
330 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 337 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
331 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 338 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -337,14 +344,14 @@ testMultithreadedPoolGet () | |||
337 | * crashes on my system! */ | 344 | * crashes on my system! */ |
338 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 345 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
339 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 346 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
340 | { | 347 | { |
341 | fprintf (stderr, | 348 | fprintf (stderr, |
342 | "curl_easy_perform failed: `%s'\n", | 349 | "curl_easy_perform failed: `%s'\n", |
343 | curl_easy_strerror (errornum)); | 350 | curl_easy_strerror (errornum)); |
344 | curl_easy_cleanup (c); | 351 | curl_easy_cleanup (c); |
345 | MHD_stop_daemon (d); | 352 | MHD_stop_daemon (d); |
346 | return 32; | 353 | return 32; |
347 | } | 354 | } |
348 | curl_easy_cleanup (c); | 355 | curl_easy_cleanup (c); |
349 | MHD_stop_daemon (d); | 356 | MHD_stop_daemon (d); |
350 | return validate (cbc, 64); | 357 | return validate (cbc, 64); |
@@ -388,16 +395,18 @@ testExternalGet () | |||
388 | if (d == NULL) | 395 | if (d == NULL) |
389 | return 256; | 396 | return 256; |
390 | if (0 == port) | 397 | if (0 == port) |
398 | { | ||
399 | const union MHD_DaemonInfo *dinfo; | ||
400 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
401 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
391 | { | 402 | { |
392 | const union MHD_DaemonInfo *dinfo; | 403 | MHD_stop_daemon (d); return 32; |
393 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
394 | if (NULL == dinfo || 0 == dinfo->port) | ||
395 | { MHD_stop_daemon (d); return 32; } | ||
396 | port = (int)dinfo->port; | ||
397 | } | 404 | } |
405 | port = (int) dinfo->port; | ||
406 | } | ||
398 | c = curl_easy_init (); | 407 | c = curl_easy_init (); |
399 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 408 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
400 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 409 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
401 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 410 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
402 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 411 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
403 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 412 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -412,86 +421,88 @@ testExternalGet () | |||
412 | 421 | ||
413 | multi = curl_multi_init (); | 422 | multi = curl_multi_init (); |
414 | if (multi == NULL) | 423 | if (multi == NULL) |
424 | { | ||
425 | curl_easy_cleanup (c); | ||
426 | MHD_stop_daemon (d); | ||
427 | return 512; | ||
428 | } | ||
429 | mret = curl_multi_add_handle (multi, c); | ||
430 | if (mret != CURLM_OK) | ||
431 | { | ||
432 | curl_multi_cleanup (multi); | ||
433 | curl_easy_cleanup (c); | ||
434 | MHD_stop_daemon (d); | ||
435 | return 1024; | ||
436 | } | ||
437 | start = time (NULL); | ||
438 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
439 | { | ||
440 | maxsock = MHD_INVALID_SOCKET; | ||
441 | maxposixs = -1; | ||
442 | FD_ZERO (&rs); | ||
443 | FD_ZERO (&ws); | ||
444 | FD_ZERO (&es); | ||
445 | curl_multi_perform (multi, &running); | ||
446 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
447 | if (mret != CURLM_OK) | ||
415 | { | 448 | { |
449 | curl_multi_remove_handle (multi, c); | ||
450 | curl_multi_cleanup (multi); | ||
416 | curl_easy_cleanup (c); | 451 | curl_easy_cleanup (c); |
417 | MHD_stop_daemon (d); | 452 | MHD_stop_daemon (d); |
418 | return 512; | 453 | return 2048; |
419 | } | 454 | } |
420 | mret = curl_multi_add_handle (multi, c); | 455 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
421 | if (mret != CURLM_OK) | ||
422 | { | 456 | { |
457 | curl_multi_remove_handle (multi, c); | ||
423 | curl_multi_cleanup (multi); | 458 | curl_multi_cleanup (multi); |
424 | curl_easy_cleanup (c); | 459 | curl_easy_cleanup (c); |
425 | MHD_stop_daemon (d); | 460 | MHD_stop_daemon (d); |
426 | return 1024; | 461 | return 4096; |
427 | } | 462 | } |
428 | start = time (NULL); | 463 | tv.tv_sec = 0; |
429 | while ((time (NULL) - start < 5) && (multi != NULL)) | 464 | tv.tv_usec = 1000; |
465 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
430 | { | 466 | { |
431 | maxsock = MHD_INVALID_SOCKET; | ||
432 | maxposixs = -1; | ||
433 | FD_ZERO (&rs); | ||
434 | FD_ZERO (&ws); | ||
435 | FD_ZERO (&es); | ||
436 | curl_multi_perform (multi, &running); | ||
437 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
438 | if (mret != CURLM_OK) | ||
439 | { | ||
440 | curl_multi_remove_handle (multi, c); | ||
441 | curl_multi_cleanup (multi); | ||
442 | curl_easy_cleanup (c); | ||
443 | MHD_stop_daemon (d); | ||
444 | return 2048; | ||
445 | } | ||
446 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
447 | { | ||
448 | curl_multi_remove_handle (multi, c); | ||
449 | curl_multi_cleanup (multi); | ||
450 | curl_easy_cleanup (c); | ||
451 | MHD_stop_daemon (d); | ||
452 | return 4096; | ||
453 | } | ||
454 | tv.tv_sec = 0; | ||
455 | tv.tv_usec = 1000; | ||
456 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
457 | { | ||
458 | #ifdef MHD_POSIX_SOCKETS | 467 | #ifdef MHD_POSIX_SOCKETS |
459 | if (EINTR != errno) | 468 | if (EINTR != errno) |
460 | abort (); | 469 | abort (); |
461 | #else | 470 | #else |
462 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 471 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
463 | abort (); | 472 | ws.fd_count) |
464 | Sleep (1000); | 473 | ||(0 != es.fd_count) ) |
474 | abort (); | ||
475 | Sleep (1000); | ||
465 | #endif | 476 | #endif |
466 | } | ||
467 | curl_multi_perform (multi, &running); | ||
468 | if (running == 0) | ||
469 | { | ||
470 | msg = curl_multi_info_read (multi, &running); | ||
471 | if (msg == NULL) | ||
472 | break; | ||
473 | if (msg->msg == CURLMSG_DONE) | ||
474 | { | ||
475 | if (msg->data.result != CURLE_OK) | ||
476 | printf ("%s failed at %s:%d: `%s'\n", | ||
477 | "curl_multi_perform", | ||
478 | __FILE__, | ||
479 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
480 | curl_multi_remove_handle (multi, c); | ||
481 | curl_multi_cleanup (multi); | ||
482 | curl_easy_cleanup (c); | ||
483 | c = NULL; | ||
484 | multi = NULL; | ||
485 | } | ||
486 | } | ||
487 | MHD_run (d); | ||
488 | } | 477 | } |
489 | if (multi != NULL) | 478 | curl_multi_perform (multi, &running); |
479 | if (running == 0) | ||
490 | { | 480 | { |
491 | curl_multi_remove_handle (multi, c); | 481 | msg = curl_multi_info_read (multi, &running); |
492 | curl_easy_cleanup (c); | 482 | if (msg == NULL) |
493 | curl_multi_cleanup (multi); | 483 | break; |
484 | if (msg->msg == CURLMSG_DONE) | ||
485 | { | ||
486 | if (msg->data.result != CURLE_OK) | ||
487 | printf ("%s failed at %s:%d: `%s'\n", | ||
488 | "curl_multi_perform", | ||
489 | __FILE__, | ||
490 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
491 | curl_multi_remove_handle (multi, c); | ||
492 | curl_multi_cleanup (multi); | ||
493 | curl_easy_cleanup (c); | ||
494 | c = NULL; | ||
495 | multi = NULL; | ||
496 | } | ||
494 | } | 497 | } |
498 | MHD_run (d); | ||
499 | } | ||
500 | if (multi != NULL) | ||
501 | { | ||
502 | curl_multi_remove_handle (multi, c); | ||
503 | curl_easy_cleanup (c); | ||
504 | curl_multi_cleanup (multi); | ||
505 | } | ||
495 | MHD_stop_daemon (d); | 506 | MHD_stop_daemon (d); |
496 | return validate (cbc, 8192); | 507 | return validate (cbc, 8192); |
497 | } | 508 | } |
@@ -502,16 +513,16 @@ int | |||
502 | main (int argc, char *const *argv) | 513 | main (int argc, char *const *argv) |
503 | { | 514 | { |
504 | unsigned int errorCount = 0; | 515 | unsigned int errorCount = 0; |
505 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 516 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
506 | 517 | ||
507 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 518 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
508 | return 2; | 519 | return 2; |
509 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 520 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
510 | { | 521 | { |
511 | errorCount += testInternalGet (); | 522 | errorCount += testInternalGet (); |
512 | errorCount += testMultithreadedGet (); | 523 | errorCount += testMultithreadedGet (); |
513 | errorCount += testMultithreadedPoolGet (); | 524 | errorCount += testMultithreadedPoolGet (); |
514 | } | 525 | } |
515 | errorCount += testExternalGet (); | 526 | errorCount += testExternalGet (); |
516 | if (errorCount != 0) | 527 | if (errorCount != 0) |
517 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 528 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_get_response_cleanup.c b/src/testcurl/test_get_response_cleanup.c index 66653a93..04fe3204 100644 --- a/src/testcurl/test_get_response_cleanup.c +++ b/src/testcurl/test_get_response_cleanup.c | |||
@@ -53,10 +53,10 @@ | |||
53 | 53 | ||
54 | #include "mhd_has_in_name.h" | 54 | #include "mhd_has_in_name.h" |
55 | 55 | ||
56 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 56 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
57 | #undef CPU_COUNT | 57 | #undef CPU_COUNT |
58 | #endif | 58 | #endif |
59 | #if !defined(CPU_COUNT) | 59 | #if ! defined(CPU_COUNT) |
60 | #define CPU_COUNT 2 | 60 | #define CPU_COUNT 2 |
61 | #endif | 61 | #endif |
62 | 62 | ||
@@ -72,13 +72,13 @@ fork_curl (const char *url) | |||
72 | { | 72 | { |
73 | pid_t ret; | 73 | pid_t ret; |
74 | 74 | ||
75 | ret = fork(); | 75 | ret = fork (); |
76 | if (ret != 0) | 76 | if (ret != 0) |
77 | return ret; | 77 | return ret; |
78 | execlp ("curl", "curl", "-s", "-N", "-o", "/dev/null", "-GET", url, NULL); | 78 | execlp ("curl", "curl", "-s", "-N", "-o", "/dev/null", "-GET", url, NULL); |
79 | fprintf (stderr, | 79 | fprintf (stderr, |
80 | "Failed to exec curl: %s\n", | 80 | "Failed to exec curl: %s\n", |
81 | strerror (errno)); | 81 | strerror (errno)); |
82 | _exit (-1); | 82 | _exit (-1); |
83 | } | 83 | } |
84 | 84 | ||
@@ -88,7 +88,7 @@ kill_curl (pid_t pid) | |||
88 | { | 88 | { |
89 | int status; | 89 | int status; |
90 | 90 | ||
91 | //fprintf (stderr, "Killing curl\n"); | 91 | // fprintf (stderr, "Killing curl\n"); |
92 | kill (pid, SIGTERM); | 92 | kill (pid, SIGTERM); |
93 | waitpid (pid, &status, 0); | 93 | waitpid (pid, &status, 0); |
94 | } | 94 | } |
@@ -97,7 +97,7 @@ kill_curl (pid_t pid) | |||
97 | static ssize_t | 97 | static ssize_t |
98 | push_callback (void *cls, uint64_t pos, char *buf, size_t max) | 98 | push_callback (void *cls, uint64_t pos, char *buf, size_t max) |
99 | { | 99 | { |
100 | (void)cls;(void)pos; /* Unused. Silent compiler warning. */ | 100 | (void) cls; (void) pos; /* Unused. Silent compiler warning. */ |
101 | 101 | ||
102 | if (max == 0) | 102 | if (max == 0) |
103 | return 0; | 103 | return 0; |
@@ -111,7 +111,7 @@ push_free_callback (void *cls) | |||
111 | { | 111 | { |
112 | int *ok = cls; | 112 | int *ok = cls; |
113 | 113 | ||
114 | //fprintf (stderr, "Cleanup callback called!\n"); | 114 | // fprintf (stderr, "Cleanup callback called!\n"); |
115 | *ok = 0; | 115 | *ok = 0; |
116 | } | 116 | } |
117 | 117 | ||
@@ -129,23 +129,23 @@ ahc_echo (void *cls, | |||
129 | const char *me = cls; | 129 | const char *me = cls; |
130 | struct MHD_Response *response; | 130 | struct MHD_Response *response; |
131 | int ret; | 131 | int ret; |
132 | (void)url;(void)version; /* Unused. Silent compiler warning. */ | 132 | (void) url; (void) version; /* Unused. Silent compiler warning. */ |
133 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 133 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
134 | 134 | ||
135 | //fprintf (stderr, "In CB: %s!\n", method); | 135 | // fprintf (stderr, "In CB: %s!\n", method); |
136 | if (0 != strcmp (me, method)) | 136 | if (0 != strcmp (me, method)) |
137 | return MHD_NO; /* unexpected method */ | 137 | return MHD_NO; /* unexpected method */ |
138 | if (&ptr != *unused) | 138 | if (&ptr != *unused) |
139 | { | 139 | { |
140 | *unused = &ptr; | 140 | *unused = &ptr; |
141 | return MHD_YES; | 141 | return MHD_YES; |
142 | } | 142 | } |
143 | *unused = NULL; | 143 | *unused = NULL; |
144 | response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, | 144 | response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, |
145 | 32 * 1024, | 145 | 32 * 1024, |
146 | &push_callback, | 146 | &push_callback, |
147 | &ok, | 147 | &ok, |
148 | &push_free_callback); | 148 | &push_free_callback); |
149 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 149 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
150 | MHD_destroy_response (response); | 150 | MHD_destroy_response (response); |
151 | if (ret == MHD_NO) | 151 | if (ret == MHD_NO) |
@@ -165,11 +165,11 @@ testInternalGet () | |||
165 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 165 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
166 | port = 0; | 166 | port = 0; |
167 | else | 167 | else |
168 | { | 168 | { |
169 | port = 1180; | 169 | port = 1180; |
170 | if (oneone) | 170 | if (oneone) |
171 | port += 10; | 171 | port += 10; |
172 | } | 172 | } |
173 | 173 | ||
174 | ok = 1; | 174 | ok = 1; |
175 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 175 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
@@ -177,21 +177,23 @@ testInternalGet () | |||
177 | if (d == NULL) | 177 | if (d == NULL) |
178 | return 1; | 178 | return 1; |
179 | if (0 == port) | 179 | if (0 == port) |
180 | { | ||
181 | const union MHD_DaemonInfo *dinfo; | ||
182 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
183 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
180 | { | 184 | { |
181 | const union MHD_DaemonInfo *dinfo; | 185 | MHD_stop_daemon (d); return 32; |
182 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
183 | if (NULL == dinfo || 0 == dinfo->port) | ||
184 | { MHD_stop_daemon (d); return 32; } | ||
185 | port = (int)dinfo->port; | ||
186 | } | 186 | } |
187 | port = (int) dinfo->port; | ||
188 | } | ||
187 | snprintf (url, | 189 | snprintf (url, |
188 | sizeof (url), | 190 | sizeof (url), |
189 | "http://127.0.0.1:%d/", | 191 | "http://127.0.0.1:%d/", |
190 | port); | 192 | port); |
191 | curl = fork_curl (url); | 193 | curl = fork_curl (url); |
192 | (void)sleep (1); | 194 | (void) sleep (1); |
193 | kill_curl (curl); | 195 | kill_curl (curl); |
194 | (void)sleep (1); | 196 | (void) sleep (1); |
195 | /* fprintf (stderr, "Stopping daemon!\n"); */ | 197 | /* fprintf (stderr, "Stopping daemon!\n"); */ |
196 | MHD_stop_daemon (d); | 198 | MHD_stop_daemon (d); |
197 | if (ok != 0) | 199 | if (ok != 0) |
@@ -211,47 +213,50 @@ testMultithreadedGet () | |||
211 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 213 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
212 | port = 0; | 214 | port = 0; |
213 | else | 215 | else |
214 | { | 216 | { |
215 | port = 1181; | 217 | port = 1181; |
216 | if (oneone) | 218 | if (oneone) |
217 | port += 10; | 219 | port += 10; |
218 | } | 220 | } |
219 | 221 | ||
220 | ok = 1; | 222 | ok = 1; |
221 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 223 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
224 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
222 | port, NULL, NULL, &ahc_echo, "GET", | 225 | port, NULL, NULL, &ahc_echo, "GET", |
223 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 2, | 226 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 2, |
224 | MHD_OPTION_END); | 227 | MHD_OPTION_END); |
225 | if (d == NULL) | 228 | if (d == NULL) |
226 | return 16; | 229 | return 16; |
227 | if (0 == port) | 230 | if (0 == port) |
231 | { | ||
232 | const union MHD_DaemonInfo *dinfo; | ||
233 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
234 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
228 | { | 235 | { |
229 | const union MHD_DaemonInfo *dinfo; | 236 | MHD_stop_daemon (d); return 32; |
230 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
231 | if (NULL == dinfo || 0 == dinfo->port) | ||
232 | { MHD_stop_daemon (d); return 32; } | ||
233 | port = (int)dinfo->port; | ||
234 | } | 237 | } |
238 | port = (int) dinfo->port; | ||
239 | } | ||
235 | snprintf (url, | 240 | snprintf (url, |
236 | sizeof (url), | 241 | sizeof (url), |
237 | "http://127.0.0.1:%d/", | 242 | "http://127.0.0.1:%d/", |
238 | port); | 243 | port); |
239 | //fprintf (stderr, "Forking cURL!\n"); | 244 | // fprintf (stderr, "Forking cURL!\n"); |
240 | curl = fork_curl (url); | 245 | curl = fork_curl (url); |
241 | (void)sleep (1); | 246 | (void) sleep (1); |
242 | kill_curl (curl); | 247 | kill_curl (curl); |
243 | (void)sleep (1); | 248 | (void) sleep (1); |
244 | curl = fork_curl (url); | 249 | curl = fork_curl (url); |
245 | (void)sleep (1); | 250 | (void) sleep (1); |
246 | if (ok != 0) | 251 | if (ok != 0) |
247 | { | 252 | { |
248 | kill_curl (curl); | 253 | kill_curl (curl); |
249 | MHD_stop_daemon (d); | 254 | MHD_stop_daemon (d); |
250 | return 64; | 255 | return 64; |
251 | } | 256 | } |
252 | kill_curl (curl); | 257 | kill_curl (curl); |
253 | (void)sleep (1); | 258 | (void) sleep (1); |
254 | //fprintf (stderr, "Stopping daemon!\n"); | 259 | // fprintf (stderr, "Stopping daemon!\n"); |
255 | MHD_stop_daemon (d); | 260 | MHD_stop_daemon (d); |
256 | if (ok != 0) | 261 | if (ok != 0) |
257 | return 32; | 262 | return 32; |
@@ -271,11 +276,11 @@ testMultithreadedPoolGet () | |||
271 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 276 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
272 | port = 0; | 277 | port = 0; |
273 | else | 278 | else |
274 | { | 279 | { |
275 | port = 1182; | 280 | port = 1182; |
276 | if (oneone) | 281 | if (oneone) |
277 | port += 10; | 282 | port += 10; |
278 | } | 283 | } |
279 | 284 | ||
280 | ok = 1; | 285 | ok = 1; |
281 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 286 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
@@ -284,22 +289,24 @@ testMultithreadedPoolGet () | |||
284 | if (d == NULL) | 289 | if (d == NULL) |
285 | return 64; | 290 | return 64; |
286 | if (0 == port) | 291 | if (0 == port) |
292 | { | ||
293 | const union MHD_DaemonInfo *dinfo; | ||
294 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
295 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
287 | { | 296 | { |
288 | const union MHD_DaemonInfo *dinfo; | 297 | MHD_stop_daemon (d); return 32; |
289 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
290 | if (NULL == dinfo || 0 == dinfo->port) | ||
291 | { MHD_stop_daemon (d); return 32; } | ||
292 | port = (int)dinfo->port; | ||
293 | } | 298 | } |
299 | port = (int) dinfo->port; | ||
300 | } | ||
294 | snprintf (url, | 301 | snprintf (url, |
295 | sizeof (url), | 302 | sizeof (url), |
296 | "http://127.0.0.1:%d/", | 303 | "http://127.0.0.1:%d/", |
297 | port); | 304 | port); |
298 | curl = fork_curl (url); | 305 | curl = fork_curl (url); |
299 | (void)sleep (1); | 306 | (void) sleep (1); |
300 | kill_curl (curl); | 307 | kill_curl (curl); |
301 | (void)sleep (1); | 308 | (void) sleep (1); |
302 | //fprintf (stderr, "Stopping daemon!\n"); | 309 | // fprintf (stderr, "Stopping daemon!\n"); |
303 | MHD_stop_daemon (d); | 310 | MHD_stop_daemon (d); |
304 | if (ok != 0) | 311 | if (ok != 0) |
305 | return 128; | 312 | return 128; |
@@ -324,11 +331,11 @@ testExternalGet () | |||
324 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 331 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
325 | port = 0; | 332 | port = 0; |
326 | else | 333 | else |
327 | { | 334 | { |
328 | port = 1183; | 335 | port = 1183; |
329 | if (oneone) | 336 | if (oneone) |
330 | port += 10; | 337 | port += 10; |
331 | } | 338 | } |
332 | 339 | ||
333 | ok = 1; | 340 | ok = 1; |
334 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, | 341 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, |
@@ -336,13 +343,15 @@ testExternalGet () | |||
336 | if (d == NULL) | 343 | if (d == NULL) |
337 | return 256; | 344 | return 256; |
338 | if (0 == port) | 345 | if (0 == port) |
346 | { | ||
347 | const union MHD_DaemonInfo *dinfo; | ||
348 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
349 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
339 | { | 350 | { |
340 | const union MHD_DaemonInfo *dinfo; | 351 | MHD_stop_daemon (d); return 32; |
341 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
342 | if (NULL == dinfo || 0 == dinfo->port) | ||
343 | { MHD_stop_daemon (d); return 32; } | ||
344 | port = (int)dinfo->port; | ||
345 | } | 352 | } |
353 | port = (int) dinfo->port; | ||
354 | } | ||
346 | snprintf (url, | 355 | snprintf (url, |
347 | sizeof (url), | 356 | sizeof (url), |
348 | "http://127.0.0.1:%d/", | 357 | "http://127.0.0.1:%d/", |
@@ -351,47 +360,47 @@ testExternalGet () | |||
351 | 360 | ||
352 | start = time (NULL); | 361 | start = time (NULL); |
353 | while ((time (NULL) - start < 2)) | 362 | while ((time (NULL) - start < 2)) |
363 | { | ||
364 | max = 0; | ||
365 | FD_ZERO (&rs); | ||
366 | FD_ZERO (&ws); | ||
367 | FD_ZERO (&es); | ||
368 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
369 | { | ||
370 | MHD_stop_daemon (d); | ||
371 | return 4096; | ||
372 | } | ||
373 | tv.tv_sec = 0; | ||
374 | tv.tv_usec = 1000; | ||
375 | if (-1 == select (max + 1, &rs, &ws, &es, &tv)) | ||
354 | { | 376 | { |
355 | max = 0; | 377 | if (EINTR != errno) |
356 | FD_ZERO (&rs); | 378 | abort (); |
357 | FD_ZERO (&ws); | ||
358 | FD_ZERO (&es); | ||
359 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
360 | { | ||
361 | MHD_stop_daemon (d); | ||
362 | return 4096; | ||
363 | } | ||
364 | tv.tv_sec = 0; | ||
365 | tv.tv_usec = 1000; | ||
366 | if (-1 == select (max + 1, &rs, &ws, &es, &tv)) | ||
367 | { | ||
368 | if (EINTR != errno) | ||
369 | abort (); | ||
370 | } | ||
371 | MHD_run (d); | ||
372 | } | 379 | } |
380 | MHD_run (d); | ||
381 | } | ||
373 | kill_curl (curl); | 382 | kill_curl (curl); |
374 | start = time (NULL); | 383 | start = time (NULL); |
375 | while ((time (NULL) - start < 2)) | 384 | while ((time (NULL) - start < 2)) |
385 | { | ||
386 | max = 0; | ||
387 | FD_ZERO (&rs); | ||
388 | FD_ZERO (&ws); | ||
389 | FD_ZERO (&es); | ||
390 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
391 | { | ||
392 | MHD_stop_daemon (d); | ||
393 | return 4096; | ||
394 | } | ||
395 | tv.tv_sec = 0; | ||
396 | tv.tv_usec = 1000; | ||
397 | if (-1 == select (max + 1, &rs, &ws, &es, &tv)) | ||
376 | { | 398 | { |
377 | max = 0; | 399 | if (EINTR != errno) |
378 | FD_ZERO (&rs); | 400 | abort (); |
379 | FD_ZERO (&ws); | ||
380 | FD_ZERO (&es); | ||
381 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
382 | { | ||
383 | MHD_stop_daemon (d); | ||
384 | return 4096; | ||
385 | } | ||
386 | tv.tv_sec = 0; | ||
387 | tv.tv_usec = 1000; | ||
388 | if (-1 == select (max + 1, &rs, &ws, &es, &tv)) | ||
389 | { | ||
390 | if (EINTR != errno) | ||
391 | abort (); | ||
392 | } | ||
393 | MHD_run (d); | ||
394 | } | 401 | } |
402 | MHD_run (d); | ||
403 | } | ||
395 | /* fprintf (stderr, "Stopping daemon!\n"); */ | 404 | /* fprintf (stderr, "Stopping daemon!\n"); */ |
396 | MHD_stop_daemon (d); | 405 | MHD_stop_daemon (d); |
397 | if (ok != 0) | 406 | if (ok != 0) |
@@ -404,28 +413,28 @@ int | |||
404 | main (int argc, char *const *argv) | 413 | main (int argc, char *const *argv) |
405 | { | 414 | { |
406 | unsigned int errorCount = 0; | 415 | unsigned int errorCount = 0; |
407 | (void)argc; /* Unused. Silent compiler warning. */ | 416 | (void) argc; /* Unused. Silent compiler warning. */ |
408 | 417 | ||
409 | #ifndef _WIN32 | 418 | #ifndef _WIN32 |
410 | /* Solaris has no way to disable SIGPIPE on socket disconnect. */ | 419 | /* Solaris has no way to disable SIGPIPE on socket disconnect. */ |
411 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTOSUPPRESS_SIGPIPE)) | 420 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTOSUPPRESS_SIGPIPE)) |
412 | { | 421 | { |
413 | struct sigaction act; | 422 | struct sigaction act; |
414 | 423 | ||
415 | act.sa_handler = SIG_IGN; | 424 | act.sa_handler = SIG_IGN; |
416 | sigaction(SIGPIPE, &act, NULL); | 425 | sigaction (SIGPIPE, &act, NULL); |
417 | } | 426 | } |
418 | #endif /* _WIN32 */ | 427 | #endif /* _WIN32 */ |
419 | 428 | ||
420 | if (NULL == argv || 0 == argv[0]) | 429 | if ((NULL == argv)||(0 == argv[0])) |
421 | return 99; | 430 | return 99; |
422 | oneone = has_in_name (argv[0], "11"); | 431 | oneone = has_in_name (argv[0], "11"); |
423 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 432 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
424 | { | 433 | { |
425 | errorCount += testInternalGet (); | 434 | errorCount += testInternalGet (); |
426 | errorCount += testMultithreadedGet (); | 435 | errorCount += testMultithreadedGet (); |
427 | errorCount += testMultithreadedPoolGet (); | 436 | errorCount += testMultithreadedPoolGet (); |
428 | } | 437 | } |
429 | errorCount += testExternalGet (); | 438 | errorCount += testExternalGet (); |
430 | if (errorCount != 0) | 439 | if (errorCount != 0) |
431 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 440 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_get_sendfile.c b/src/testcurl/test_get_sendfile.c index 3e68647b..7651ff56 100644 --- a/src/testcurl/test_get_sendfile.c +++ b/src/testcurl/test_get_sendfile.c | |||
@@ -40,14 +40,15 @@ | |||
40 | #include <unistd.h> | 40 | #include <unistd.h> |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 43 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
44 | #undef CPU_COUNT | 44 | #undef CPU_COUNT |
45 | #endif | 45 | #endif |
46 | #if !defined(CPU_COUNT) | 46 | #if ! defined(CPU_COUNT) |
47 | #define CPU_COUNT 2 | 47 | #define CPU_COUNT 2 |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | #define TESTSTR "This is the content of the test file we are sending using sendfile (if available)" | 50 | #define TESTSTR \ |
51 | "This is the content of the test file we are sending using sendfile (if available)" | ||
51 | 52 | ||
52 | static char *sourcefile; | 53 | static char *sourcefile; |
53 | 54 | ||
@@ -88,25 +89,25 @@ ahc_echo (void *cls, | |||
88 | struct MHD_Response *response; | 89 | struct MHD_Response *response; |
89 | int ret; | 90 | int ret; |
90 | int fd; | 91 | int fd; |
91 | (void)url;(void)version; /* Unused. Silent compiler warning. */ | 92 | (void) url; (void) version; /* Unused. Silent compiler warning. */ |
92 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 93 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
93 | 94 | ||
94 | if (0 != strcmp (me, method)) | 95 | if (0 != strcmp (me, method)) |
95 | return MHD_NO; /* unexpected method */ | 96 | return MHD_NO; /* unexpected method */ |
96 | if (&ptr != *unused) | 97 | if (&ptr != *unused) |
97 | { | 98 | { |
98 | *unused = &ptr; | 99 | *unused = &ptr; |
99 | return MHD_YES; | 100 | return MHD_YES; |
100 | } | 101 | } |
101 | *unused = NULL; | 102 | *unused = NULL; |
102 | fd = open (sourcefile, O_RDONLY); | 103 | fd = open (sourcefile, O_RDONLY); |
103 | if (fd == -1) | 104 | if (fd == -1) |
104 | { | 105 | { |
105 | fprintf (stderr, "Failed to open `%s': %s\n", | 106 | fprintf (stderr, "Failed to open `%s': %s\n", |
106 | sourcefile, | 107 | sourcefile, |
107 | strerror (errno)); | 108 | strerror (errno)); |
108 | exit (1); | 109 | exit (1); |
109 | } | 110 | } |
110 | response = MHD_create_response_from_fd (strlen (TESTSTR), fd); | 111 | response = MHD_create_response_from_fd (strlen (TESTSTR), fd); |
111 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 112 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
112 | MHD_destroy_response (response); | 113 | MHD_destroy_response (response); |
@@ -129,11 +130,11 @@ testInternalGet () | |||
129 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 130 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
130 | port = 0; | 131 | port = 0; |
131 | else | 132 | else |
132 | { | 133 | { |
133 | port = 1200; | 134 | port = 1200; |
134 | if (oneone) | 135 | if (oneone) |
135 | port += 10; | 136 | port += 10; |
136 | } | 137 | } |
137 | 138 | ||
138 | cbc.buf = buf; | 139 | cbc.buf = buf; |
139 | cbc.size = 2048; | 140 | cbc.size = 2048; |
@@ -143,16 +144,18 @@ testInternalGet () | |||
143 | if (d == NULL) | 144 | if (d == NULL) |
144 | return 1; | 145 | return 1; |
145 | if (0 == port) | 146 | if (0 == port) |
147 | { | ||
148 | const union MHD_DaemonInfo *dinfo; | ||
149 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
150 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
146 | { | 151 | { |
147 | const union MHD_DaemonInfo *dinfo; | 152 | MHD_stop_daemon (d); return 32; |
148 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
149 | if (NULL == dinfo || 0 == dinfo->port) | ||
150 | { MHD_stop_daemon (d); return 32; } | ||
151 | port = (int)dinfo->port; | ||
152 | } | 153 | } |
154 | port = (int) dinfo->port; | ||
155 | } | ||
153 | c = curl_easy_init (); | 156 | c = curl_easy_init (); |
154 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); | 157 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); |
155 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 158 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
156 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 159 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
157 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 160 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
158 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 161 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -167,14 +170,14 @@ testInternalGet () | |||
167 | crashes on my system!*/ | 170 | crashes on my system!*/ |
168 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 171 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
169 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 172 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
170 | { | 173 | { |
171 | fprintf (stderr, | 174 | fprintf (stderr, |
172 | "curl_easy_perform failed: `%s'\n", | 175 | "curl_easy_perform failed: `%s'\n", |
173 | curl_easy_strerror (errornum)); | 176 | curl_easy_strerror (errornum)); |
174 | curl_easy_cleanup (c); | 177 | curl_easy_cleanup (c); |
175 | MHD_stop_daemon (d); | 178 | MHD_stop_daemon (d); |
176 | return 2; | 179 | return 2; |
177 | } | 180 | } |
178 | curl_easy_cleanup (c); | 181 | curl_easy_cleanup (c); |
179 | MHD_stop_daemon (d); | 182 | MHD_stop_daemon (d); |
180 | if (cbc.pos != strlen (TESTSTR)) | 183 | if (cbc.pos != strlen (TESTSTR)) |
@@ -198,30 +201,33 @@ testMultithreadedGet () | |||
198 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 201 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
199 | port = 0; | 202 | port = 0; |
200 | else | 203 | else |
201 | { | 204 | { |
202 | port = 1201; | 205 | port = 1201; |
203 | if (oneone) | 206 | if (oneone) |
204 | port += 10; | 207 | port += 10; |
205 | } | 208 | } |
206 | 209 | ||
207 | cbc.buf = buf; | 210 | cbc.buf = buf; |
208 | cbc.size = 2048; | 211 | cbc.size = 2048; |
209 | cbc.pos = 0; | 212 | cbc.pos = 0; |
210 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 213 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
214 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
211 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 215 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
212 | if (d == NULL) | 216 | if (d == NULL) |
213 | return 16; | 217 | return 16; |
214 | if (0 == port) | 218 | if (0 == port) |
219 | { | ||
220 | const union MHD_DaemonInfo *dinfo; | ||
221 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
222 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
215 | { | 223 | { |
216 | const union MHD_DaemonInfo *dinfo; | 224 | MHD_stop_daemon (d); return 32; |
217 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
218 | if (NULL == dinfo || 0 == dinfo->port) | ||
219 | { MHD_stop_daemon (d); return 32; } | ||
220 | port = (int)dinfo->port; | ||
221 | } | 225 | } |
226 | port = (int) dinfo->port; | ||
227 | } | ||
222 | c = curl_easy_init (); | 228 | c = curl_easy_init (); |
223 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); | 229 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); |
224 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 230 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
225 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 231 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
226 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 232 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
227 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 233 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -236,14 +242,14 @@ testMultithreadedGet () | |||
236 | crashes on my system! */ | 242 | crashes on my system! */ |
237 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 243 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
238 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 244 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
239 | { | 245 | { |
240 | fprintf (stderr, | 246 | fprintf (stderr, |
241 | "curl_easy_perform failed: `%s'\n", | 247 | "curl_easy_perform failed: `%s'\n", |
242 | curl_easy_strerror (errornum)); | 248 | curl_easy_strerror (errornum)); |
243 | curl_easy_cleanup (c); | 249 | curl_easy_cleanup (c); |
244 | MHD_stop_daemon (d); | 250 | MHD_stop_daemon (d); |
245 | return 32; | 251 | return 32; |
246 | } | 252 | } |
247 | curl_easy_cleanup (c); | 253 | curl_easy_cleanup (c); |
248 | MHD_stop_daemon (d); | 254 | MHD_stop_daemon (d); |
249 | if (cbc.pos != strlen (TESTSTR)) | 255 | if (cbc.pos != strlen (TESTSTR)) |
@@ -267,11 +273,11 @@ testMultithreadedPoolGet () | |||
267 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 273 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
268 | port = 0; | 274 | port = 0; |
269 | else | 275 | else |
270 | { | 276 | { |
271 | port = 1202; | 277 | port = 1202; |
272 | if (oneone) | 278 | if (oneone) |
273 | port += 10; | 279 | port += 10; |
274 | } | 280 | } |
275 | 281 | ||
276 | cbc.buf = buf; | 282 | cbc.buf = buf; |
277 | cbc.size = 2048; | 283 | cbc.size = 2048; |
@@ -282,16 +288,18 @@ testMultithreadedPoolGet () | |||
282 | if (d == NULL) | 288 | if (d == NULL) |
283 | return 16; | 289 | return 16; |
284 | if (0 == port) | 290 | if (0 == port) |
291 | { | ||
292 | const union MHD_DaemonInfo *dinfo; | ||
293 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
294 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
285 | { | 295 | { |
286 | const union MHD_DaemonInfo *dinfo; | 296 | MHD_stop_daemon (d); return 32; |
287 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
288 | if (NULL == dinfo || 0 == dinfo->port) | ||
289 | { MHD_stop_daemon (d); return 32; } | ||
290 | port = (int)dinfo->port; | ||
291 | } | 297 | } |
298 | port = (int) dinfo->port; | ||
299 | } | ||
292 | c = curl_easy_init (); | 300 | c = curl_easy_init (); |
293 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); | 301 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); |
294 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 302 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
295 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 303 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
296 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 304 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
297 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 305 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -306,14 +314,14 @@ testMultithreadedPoolGet () | |||
306 | crashes on my system!*/ | 314 | crashes on my system!*/ |
307 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 315 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
308 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 316 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
309 | { | 317 | { |
310 | fprintf (stderr, | 318 | fprintf (stderr, |
311 | "curl_easy_perform failed: `%s'\n", | 319 | "curl_easy_perform failed: `%s'\n", |
312 | curl_easy_strerror (errornum)); | 320 | curl_easy_strerror (errornum)); |
313 | curl_easy_cleanup (c); | 321 | curl_easy_cleanup (c); |
314 | MHD_stop_daemon (d); | 322 | MHD_stop_daemon (d); |
315 | return 32; | 323 | return 32; |
316 | } | 324 | } |
317 | curl_easy_cleanup (c); | 325 | curl_easy_cleanup (c); |
318 | MHD_stop_daemon (d); | 326 | MHD_stop_daemon (d); |
319 | if (cbc.pos != strlen (TESTSTR)) | 327 | if (cbc.pos != strlen (TESTSTR)) |
@@ -351,11 +359,11 @@ testExternalGet () | |||
351 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 359 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
352 | port = 0; | 360 | port = 0; |
353 | else | 361 | else |
354 | { | 362 | { |
355 | port = 1203; | 363 | port = 1203; |
356 | if (oneone) | 364 | if (oneone) |
357 | port += 10; | 365 | port += 10; |
358 | } | 366 | } |
359 | 367 | ||
360 | multi = NULL; | 368 | multi = NULL; |
361 | cbc.buf = buf; | 369 | cbc.buf = buf; |
@@ -366,16 +374,18 @@ testExternalGet () | |||
366 | if (d == NULL) | 374 | if (d == NULL) |
367 | return 256; | 375 | return 256; |
368 | if (0 == port) | 376 | if (0 == port) |
377 | { | ||
378 | const union MHD_DaemonInfo *dinfo; | ||
379 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
380 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
369 | { | 381 | { |
370 | const union MHD_DaemonInfo *dinfo; | 382 | MHD_stop_daemon (d); return 32; |
371 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
372 | if (NULL == dinfo || 0 == dinfo->port) | ||
373 | { MHD_stop_daemon (d); return 32; } | ||
374 | port = (int)dinfo->port; | ||
375 | } | 383 | } |
384 | port = (int) dinfo->port; | ||
385 | } | ||
376 | c = curl_easy_init (); | 386 | c = curl_easy_init (); |
377 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); | 387 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/"); |
378 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 388 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
379 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 389 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
380 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 390 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
381 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 391 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -393,86 +403,88 @@ testExternalGet () | |||
393 | 403 | ||
394 | multi = curl_multi_init (); | 404 | multi = curl_multi_init (); |
395 | if (multi == NULL) | 405 | if (multi == NULL) |
406 | { | ||
407 | curl_easy_cleanup (c); | ||
408 | MHD_stop_daemon (d); | ||
409 | return 512; | ||
410 | } | ||
411 | mret = curl_multi_add_handle (multi, c); | ||
412 | if (mret != CURLM_OK) | ||
413 | { | ||
414 | curl_multi_cleanup (multi); | ||
415 | curl_easy_cleanup (c); | ||
416 | MHD_stop_daemon (d); | ||
417 | return 1024; | ||
418 | } | ||
419 | start = time (NULL); | ||
420 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
421 | { | ||
422 | maxsock = MHD_INVALID_SOCKET; | ||
423 | maxposixs = -1; | ||
424 | FD_ZERO (&rs); | ||
425 | FD_ZERO (&ws); | ||
426 | FD_ZERO (&es); | ||
427 | curl_multi_perform (multi, &running); | ||
428 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
429 | if (mret != CURLM_OK) | ||
396 | { | 430 | { |
431 | curl_multi_remove_handle (multi, c); | ||
432 | curl_multi_cleanup (multi); | ||
397 | curl_easy_cleanup (c); | 433 | curl_easy_cleanup (c); |
398 | MHD_stop_daemon (d); | 434 | MHD_stop_daemon (d); |
399 | return 512; | 435 | return 2048; |
400 | } | 436 | } |
401 | mret = curl_multi_add_handle (multi, c); | 437 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
402 | if (mret != CURLM_OK) | ||
403 | { | 438 | { |
439 | curl_multi_remove_handle (multi, c); | ||
404 | curl_multi_cleanup (multi); | 440 | curl_multi_cleanup (multi); |
405 | curl_easy_cleanup (c); | 441 | curl_easy_cleanup (c); |
406 | MHD_stop_daemon (d); | 442 | MHD_stop_daemon (d); |
407 | return 1024; | 443 | return 4096; |
408 | } | 444 | } |
409 | start = time (NULL); | 445 | tv.tv_sec = 0; |
410 | while ((time (NULL) - start < 5) && (multi != NULL)) | 446 | tv.tv_usec = 1000; |
447 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
411 | { | 448 | { |
412 | maxsock = MHD_INVALID_SOCKET; | ||
413 | maxposixs = -1; | ||
414 | FD_ZERO (&rs); | ||
415 | FD_ZERO (&ws); | ||
416 | FD_ZERO (&es); | ||
417 | curl_multi_perform (multi, &running); | ||
418 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
419 | if (mret != CURLM_OK) | ||
420 | { | ||
421 | curl_multi_remove_handle (multi, c); | ||
422 | curl_multi_cleanup (multi); | ||
423 | curl_easy_cleanup (c); | ||
424 | MHD_stop_daemon (d); | ||
425 | return 2048; | ||
426 | } | ||
427 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
428 | { | ||
429 | curl_multi_remove_handle (multi, c); | ||
430 | curl_multi_cleanup (multi); | ||
431 | curl_easy_cleanup (c); | ||
432 | MHD_stop_daemon (d); | ||
433 | return 4096; | ||
434 | } | ||
435 | tv.tv_sec = 0; | ||
436 | tv.tv_usec = 1000; | ||
437 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
438 | { | ||
439 | #ifdef MHD_POSIX_SOCKETS | 449 | #ifdef MHD_POSIX_SOCKETS |
440 | if (EINTR != errno) | 450 | if (EINTR != errno) |
441 | abort (); | 451 | abort (); |
442 | #else | 452 | #else |
443 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 453 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
444 | abort (); | 454 | ws.fd_count) |
445 | Sleep (1000); | 455 | ||(0 != es.fd_count) ) |
456 | abort (); | ||
457 | Sleep (1000); | ||
446 | #endif | 458 | #endif |
447 | } | ||
448 | curl_multi_perform (multi, &running); | ||
449 | if (running == 0) | ||
450 | { | ||
451 | msg = curl_multi_info_read (multi, &running); | ||
452 | if (msg == NULL) | ||
453 | break; | ||
454 | if (msg->msg == CURLMSG_DONE) | ||
455 | { | ||
456 | if (msg->data.result != CURLE_OK) | ||
457 | printf ("%s failed at %s:%d: `%s'\n", | ||
458 | "curl_multi_perform", | ||
459 | __FILE__, | ||
460 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
461 | curl_multi_remove_handle (multi, c); | ||
462 | curl_multi_cleanup (multi); | ||
463 | curl_easy_cleanup (c); | ||
464 | c = NULL; | ||
465 | multi = NULL; | ||
466 | } | ||
467 | } | ||
468 | MHD_run (d); | ||
469 | } | 459 | } |
470 | if (multi != NULL) | 460 | curl_multi_perform (multi, &running); |
461 | if (running == 0) | ||
471 | { | 462 | { |
472 | curl_multi_remove_handle (multi, c); | 463 | msg = curl_multi_info_read (multi, &running); |
473 | curl_easy_cleanup (c); | 464 | if (msg == NULL) |
474 | curl_multi_cleanup (multi); | 465 | break; |
466 | if (msg->msg == CURLMSG_DONE) | ||
467 | { | ||
468 | if (msg->data.result != CURLE_OK) | ||
469 | printf ("%s failed at %s:%d: `%s'\n", | ||
470 | "curl_multi_perform", | ||
471 | __FILE__, | ||
472 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
473 | curl_multi_remove_handle (multi, c); | ||
474 | curl_multi_cleanup (multi); | ||
475 | curl_easy_cleanup (c); | ||
476 | c = NULL; | ||
477 | multi = NULL; | ||
478 | } | ||
475 | } | 479 | } |
480 | MHD_run (d); | ||
481 | } | ||
482 | if (multi != NULL) | ||
483 | { | ||
484 | curl_multi_remove_handle (multi, c); | ||
485 | curl_easy_cleanup (c); | ||
486 | curl_multi_cleanup (multi); | ||
487 | } | ||
476 | MHD_stop_daemon (d); | 488 | MHD_stop_daemon (d); |
477 | if (cbc.pos != strlen (TESTSTR)) | 489 | if (cbc.pos != strlen (TESTSTR)) |
478 | return 8192; | 490 | return 8192; |
@@ -495,7 +507,7 @@ testUnknownPortGet () | |||
495 | 507 | ||
496 | struct sockaddr_in addr; | 508 | struct sockaddr_in addr; |
497 | socklen_t addr_len = sizeof(addr); | 509 | socklen_t addr_len = sizeof(addr); |
498 | memset(&addr, 0, sizeof(addr)); | 510 | memset (&addr, 0, sizeof(addr)); |
499 | addr.sin_family = AF_INET; | 511 | addr.sin_family = AF_INET; |
500 | addr.sin_port = 0; | 512 | addr.sin_port = 0; |
501 | addr.sin_addr.s_addr = INADDR_ANY; | 513 | addr.sin_addr.s_addr = INADDR_ANY; |
@@ -511,29 +523,31 @@ testUnknownPortGet () | |||
511 | return 32768; | 523 | return 32768; |
512 | 524 | ||
513 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 525 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
514 | { | 526 | { |
515 | di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD); | 527 | di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD); |
516 | if (di == NULL) | 528 | if (di == NULL) |
517 | return 65536; | 529 | return 65536; |
518 | 530 | ||
519 | if (0 != getsockname(di->listen_fd, (struct sockaddr *) &addr, &addr_len)) | 531 | if (0 != getsockname (di->listen_fd, (struct sockaddr *) &addr, &addr_len)) |
520 | return 131072; | 532 | return 131072; |
521 | 533 | ||
522 | if (addr.sin_family != AF_INET) | 534 | if (addr.sin_family != AF_INET) |
523 | return 26214; | 535 | return 26214; |
524 | port = (int)ntohs(addr.sin_port); | 536 | port = (int) ntohs (addr.sin_port); |
525 | } | 537 | } |
526 | else | 538 | else |
539 | { | ||
540 | const union MHD_DaemonInfo *dinfo; | ||
541 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
542 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
527 | { | 543 | { |
528 | const union MHD_DaemonInfo *dinfo; | 544 | MHD_stop_daemon (d); return 32; |
529 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
530 | if (NULL == dinfo || 0 == dinfo->port) | ||
531 | { MHD_stop_daemon (d); return 32; } | ||
532 | port = (int)dinfo->port; | ||
533 | } | 545 | } |
546 | port = (int) dinfo->port; | ||
547 | } | ||
534 | 548 | ||
535 | snprintf(buf, sizeof(buf), "http://127.0.0.1:%d/", | 549 | snprintf (buf, sizeof(buf), "http://127.0.0.1:%d/", |
536 | port); | 550 | port); |
537 | 551 | ||
538 | c = curl_easy_init (); | 552 | c = curl_easy_init (); |
539 | curl_easy_setopt (c, CURLOPT_URL, buf); | 553 | curl_easy_setopt (c, CURLOPT_URL, buf); |
@@ -551,14 +565,14 @@ testUnknownPortGet () | |||
551 | crashes on my system! */ | 565 | crashes on my system! */ |
552 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 566 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
553 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 567 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
554 | { | 568 | { |
555 | fprintf (stderr, | 569 | fprintf (stderr, |
556 | "curl_easy_perform failed: `%s'\n", | 570 | "curl_easy_perform failed: `%s'\n", |
557 | curl_easy_strerror (errornum)); | 571 | curl_easy_strerror (errornum)); |
558 | curl_easy_cleanup (c); | 572 | curl_easy_cleanup (c); |
559 | MHD_stop_daemon (d); | 573 | MHD_stop_daemon (d); |
560 | return 524288; | 574 | return 524288; |
561 | } | 575 | } |
562 | curl_easy_cleanup (c); | 576 | curl_easy_cleanup (c); |
563 | MHD_stop_daemon (d); | 577 | MHD_stop_daemon (d); |
564 | if (cbc.pos != strlen (TESTSTR)) | 578 | if (cbc.pos != strlen (TESTSTR)) |
@@ -575,9 +589,9 @@ main (int argc, char *const *argv) | |||
575 | unsigned int errorCount = 0; | 589 | unsigned int errorCount = 0; |
576 | const char *tmp; | 590 | const char *tmp; |
577 | FILE *f; | 591 | FILE *f; |
578 | (void)argc; /* Unused. Silent compiler warning. */ | 592 | (void) argc; /* Unused. Silent compiler warning. */ |
579 | 593 | ||
580 | if (NULL == argv || 0 == argv[0]) | 594 | if ((NULL == argv)||(0 == argv[0])) |
581 | return 99; | 595 | return 99; |
582 | oneone = has_in_name (argv[0], "11"); | 596 | oneone = has_in_name (argv[0], "11"); |
583 | 597 | ||
@@ -594,24 +608,24 @@ main (int argc, char *const *argv) | |||
594 | oneone ? "11" : ""); | 608 | oneone ? "11" : ""); |
595 | f = fopen (sourcefile, "w"); | 609 | f = fopen (sourcefile, "w"); |
596 | if (NULL == f) | 610 | if (NULL == f) |
597 | { | 611 | { |
598 | fprintf (stderr, "failed to write test file\n"); | 612 | fprintf (stderr, "failed to write test file\n"); |
599 | free (sourcefile); | 613 | free (sourcefile); |
600 | return 1; | 614 | return 1; |
601 | } | 615 | } |
602 | if (1 != | 616 | if (1 != |
603 | fwrite (TESTSTR, strlen (TESTSTR), 1, f)) | 617 | fwrite (TESTSTR, strlen (TESTSTR), 1, f)) |
604 | abort (); | 618 | abort (); |
605 | fclose (f); | 619 | fclose (f); |
606 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 620 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
607 | return 2; | 621 | return 2; |
608 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 622 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
609 | { | 623 | { |
610 | errorCount += testInternalGet (); | 624 | errorCount += testInternalGet (); |
611 | errorCount += testMultithreadedGet (); | 625 | errorCount += testMultithreadedGet (); |
612 | errorCount += testMultithreadedPoolGet (); | 626 | errorCount += testMultithreadedPoolGet (); |
613 | errorCount += testUnknownPortGet (); | 627 | errorCount += testUnknownPortGet (); |
614 | } | 628 | } |
615 | errorCount += testExternalGet (); | 629 | errorCount += testExternalGet (); |
616 | if (errorCount != 0) | 630 | if (errorCount != 0) |
617 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 631 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_iplimit.c b/src/testcurl/test_iplimit.c index 35ae6645..82d2923f 100644 --- a/src/testcurl/test_iplimit.c +++ b/src/testcurl/test_iplimit.c | |||
@@ -45,10 +45,10 @@ | |||
45 | #include <windows.h> | 45 | #include <windows.h> |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 48 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
49 | #undef CPU_COUNT | 49 | #undef CPU_COUNT |
50 | #endif | 50 | #endif |
51 | #if !defined(CPU_COUNT) | 51 | #if ! defined(CPU_COUNT) |
52 | #define CPU_COUNT 2 | 52 | #define CPU_COUNT 2 |
53 | #endif | 53 | #endif |
54 | 54 | ||
@@ -86,19 +86,19 @@ ahc_echo (void *cls, | |||
86 | const char *me = cls; | 86 | const char *me = cls; |
87 | struct MHD_Response *response; | 87 | struct MHD_Response *response; |
88 | int ret; | 88 | int ret; |
89 | (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 89 | (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
90 | 90 | ||
91 | if (0 != strcmp (me, method)) | 91 | if (0 != strcmp (me, method)) |
92 | return MHD_NO; /* unexpected method */ | 92 | return MHD_NO; /* unexpected method */ |
93 | if (&ptr != *unused) | 93 | if (&ptr != *unused) |
94 | { | 94 | { |
95 | *unused = &ptr; | 95 | *unused = &ptr; |
96 | return MHD_YES; | 96 | return MHD_YES; |
97 | } | 97 | } |
98 | *unused = NULL; | 98 | *unused = NULL; |
99 | response = MHD_create_response_from_buffer (strlen (url), | 99 | response = MHD_create_response_from_buffer (strlen (url), |
100 | (void *) url, | 100 | (void *) url, |
101 | MHD_RESPMEM_MUST_COPY); | 101 | MHD_RESPMEM_MUST_COPY); |
102 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 102 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
103 | MHD_destroy_response (response); | 103 | MHD_destroy_response (response); |
104 | if (ret == MHD_NO) | 104 | if (ret == MHD_NO) |
@@ -119,14 +119,14 @@ testMultithreadedGet () | |||
119 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 119 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
120 | port = 0; | 120 | port = 0; |
121 | else | 121 | else |
122 | { | 122 | { |
123 | port = 1260; | 123 | port = 1260; |
124 | if (oneone) | 124 | if (oneone) |
125 | port += 5; | 125 | port += 5; |
126 | } | 126 | } |
127 | 127 | ||
128 | /* Test only valid for HTTP/1.1 (uses persistent connections) */ | 128 | /* Test only valid for HTTP/1.1 (uses persistent connections) */ |
129 | if (!oneone) | 129 | if (! oneone) |
130 | return 0; | 130 | return 0; |
131 | 131 | ||
132 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 132 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
@@ -137,83 +137,85 @@ testMultithreadedGet () | |||
137 | if (d == NULL) | 137 | if (d == NULL) |
138 | return 16; | 138 | return 16; |
139 | if (0 == port) | 139 | if (0 == port) |
140 | { | ||
141 | const union MHD_DaemonInfo *dinfo; | ||
142 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
143 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
140 | { | 144 | { |
141 | const union MHD_DaemonInfo *dinfo; | 145 | MHD_stop_daemon (d); return 32; |
142 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
143 | if (NULL == dinfo || 0 == dinfo->port) | ||
144 | { MHD_stop_daemon (d); return 32; } | ||
145 | port = (int)dinfo->port; | ||
146 | } | 146 | } |
147 | port = (int) dinfo->port; | ||
148 | } | ||
147 | 149 | ||
148 | for (k = 0; k < 3; ++k) | 150 | for (k = 0; k < 3; ++k) |
151 | { | ||
152 | struct CBC cbc[3]; | ||
153 | CURL *cenv[3]; | ||
154 | int i; | ||
155 | |||
156 | success = 0; | ||
157 | failure = 0; | ||
158 | for (i = 0; i < 3; ++i) | ||
159 | { | ||
160 | CURL *c; | ||
161 | CURLcode errornum; | ||
162 | |||
163 | cenv[i] = c = curl_easy_init (); | ||
164 | cbc[i].buf = buf; | ||
165 | cbc[i].size = 2048; | ||
166 | cbc[i].pos = 0; | ||
167 | |||
168 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | ||
169 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); | ||
170 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
171 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]); | ||
172 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
173 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
174 | curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L); | ||
175 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
176 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
177 | /* NOTE: use of CONNECTTIMEOUT without also | ||
178 | * setting NOSIGNAL results in really weird | ||
179 | * crashes on my system! */ | ||
180 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
181 | |||
182 | errornum = curl_easy_perform (c); | ||
183 | if (CURLE_OK == errornum) | ||
184 | success++; | ||
185 | else | ||
186 | failure++; | ||
187 | } | ||
188 | |||
189 | /* Cleanup the environments */ | ||
190 | for (i = 0; i < 3; ++i) | ||
191 | curl_easy_cleanup (cenv[i]); | ||
192 | if ( (2 != success) || | ||
193 | (1 != failure) ) | ||
149 | { | 194 | { |
150 | struct CBC cbc[3]; | 195 | fprintf (stderr, |
151 | CURL *cenv[3]; | 196 | "Unexpected number of success (%u) or failure (%u)\n", |
152 | int i; | 197 | success, |
153 | 198 | failure); | |
154 | success = 0; | 199 | MHD_stop_daemon (d); |
155 | failure = 0; | 200 | return 32; |
156 | for (i = 0; i < 3; ++i) | 201 | } |
157 | { | 202 | |
158 | CURL *c; | 203 | (void) sleep (2); |
159 | CURLcode errornum; | 204 | |
160 | 205 | for (i = 0; i < 2; ++i) | |
161 | cenv[i] = c = curl_easy_init (); | 206 | { |
162 | cbc[i].buf = buf; | 207 | if (cbc[i].pos != strlen ("/hello_world")) |
163 | cbc[i].size = 2048; | ||
164 | cbc[i].pos = 0; | ||
165 | |||
166 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | ||
167 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | ||
168 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
169 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]); | ||
170 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
171 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
172 | curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L); | ||
173 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
174 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
175 | /* NOTE: use of CONNECTTIMEOUT without also | ||
176 | * setting NOSIGNAL results in really weird | ||
177 | * crashes on my system! */ | ||
178 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
179 | |||
180 | errornum = curl_easy_perform (c); | ||
181 | if (CURLE_OK == errornum) | ||
182 | success++; | ||
183 | else | ||
184 | failure++; | ||
185 | } | ||
186 | |||
187 | /* Cleanup the environments */ | ||
188 | for (i = 0; i < 3; ++i) | ||
189 | curl_easy_cleanup (cenv[i]); | ||
190 | if ( (2 != success) || | ||
191 | (1 != failure) ) | ||
192 | { | 208 | { |
193 | fprintf (stderr, | ||
194 | "Unexpected number of success (%u) or failure (%u)\n", | ||
195 | success, | ||
196 | failure); | ||
197 | MHD_stop_daemon (d); | 209 | MHD_stop_daemon (d); |
198 | return 32; | 210 | return 64; |
211 | } | ||
212 | if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world"))) | ||
213 | { | ||
214 | MHD_stop_daemon (d); | ||
215 | return 128; | ||
199 | } | 216 | } |
200 | |||
201 | (void)sleep(2); | ||
202 | |||
203 | for (i = 0; i < 2; ++i) | ||
204 | { | ||
205 | if (cbc[i].pos != strlen ("/hello_world")) | ||
206 | { | ||
207 | MHD_stop_daemon (d); | ||
208 | return 64; | ||
209 | } | ||
210 | if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world"))) | ||
211 | { | ||
212 | MHD_stop_daemon (d); | ||
213 | return 128; | ||
214 | } | ||
215 | } | ||
216 | } | 217 | } |
218 | } | ||
217 | MHD_stop_daemon (d); | 219 | MHD_stop_daemon (d); |
218 | return 0; | 220 | return 0; |
219 | } | 221 | } |
@@ -228,14 +230,14 @@ testMultithreadedPoolGet () | |||
228 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 230 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
229 | port = 0; | 231 | port = 0; |
230 | else | 232 | else |
231 | { | 233 | { |
232 | port = 1261; | 234 | port = 1261; |
233 | if (oneone) | 235 | if (oneone) |
234 | port += 5; | 236 | port += 5; |
235 | } | 237 | } |
236 | 238 | ||
237 | /* Test only valid for HTTP/1.1 (uses persistent connections) */ | 239 | /* Test only valid for HTTP/1.1 (uses persistent connections) */ |
238 | if (!oneone) | 240 | if (! oneone) |
239 | return 0; | 241 | return 0; |
240 | 242 | ||
241 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 243 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
@@ -246,90 +248,92 @@ testMultithreadedPoolGet () | |||
246 | if (d == NULL) | 248 | if (d == NULL) |
247 | return 16; | 249 | return 16; |
248 | if (0 == port) | 250 | if (0 == port) |
251 | { | ||
252 | const union MHD_DaemonInfo *dinfo; | ||
253 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
254 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
249 | { | 255 | { |
250 | const union MHD_DaemonInfo *dinfo; | 256 | MHD_stop_daemon (d); return 32; |
251 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
252 | if (NULL == dinfo || 0 == dinfo->port) | ||
253 | { MHD_stop_daemon (d); return 32; } | ||
254 | port = (int)dinfo->port; | ||
255 | } | 257 | } |
258 | port = (int) dinfo->port; | ||
259 | } | ||
256 | 260 | ||
257 | for (k = 0; k < 3; ++k) | 261 | for (k = 0; k < 3; ++k) |
262 | { | ||
263 | struct CBC cbc[3]; | ||
264 | CURL *cenv[3]; | ||
265 | int i; | ||
266 | |||
267 | for (i = 0; i < 3; ++i) | ||
258 | { | 268 | { |
259 | struct CBC cbc[3]; | 269 | CURL *c; |
260 | CURL *cenv[3]; | 270 | CURLcode errornum; |
261 | int i; | 271 | |
262 | 272 | cenv[i] = c = curl_easy_init (); | |
263 | for (i = 0; i < 3; ++i) | 273 | cbc[i].buf = buf; |
264 | { | 274 | cbc[i].size = 2048; |
265 | CURL *c; | 275 | cbc[i].pos = 0; |
266 | CURLcode errornum; | 276 | |
267 | 277 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | |
268 | cenv[i] = c = curl_easy_init (); | 278 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
269 | cbc[i].buf = buf; | 279 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
270 | cbc[i].size = 2048; | 280 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]); |
271 | cbc[i].pos = 0; | 281 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
272 | 282 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | |
273 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 283 | curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L); |
274 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 284 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
275 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 285 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); |
276 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc[i]); | 286 | /* NOTE: use of CONNECTTIMEOUT without also |
277 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 287 | * setting NOSIGNAL results in really weird |
278 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | 288 | * crashes on my system! */ |
279 | curl_easy_setopt (c, CURLOPT_FORBID_REUSE, 0L); | 289 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
280 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 290 | |
281 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | 291 | errornum = curl_easy_perform (c); |
282 | /* NOTE: use of CONNECTTIMEOUT without also | 292 | if ( ( (CURLE_OK != errornum) && (i < 2) ) || |
283 | * setting NOSIGNAL results in really weird | 293 | ( (CURLE_OK == errornum) && (i == 2) ) ) |
284 | * crashes on my system! */ | 294 | { |
285 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 295 | int j; |
286 | 296 | ||
287 | errornum = curl_easy_perform (c); | 297 | /* First 2 should succeed */ |
288 | if ( ( (CURLE_OK != errornum) && (i < 2) ) || | 298 | if (i < 2) |
289 | ( (CURLE_OK == errornum) && (i == 2) ) ) | 299 | fprintf (stderr, |
290 | { | 300 | "curl_easy_perform failed: `%s'\n", |
291 | int j; | 301 | curl_easy_strerror (errornum)); |
292 | 302 | ||
293 | /* First 2 should succeed */ | 303 | /* Last request should have failed */ |
294 | if (i < 2) | 304 | else |
295 | fprintf (stderr, | 305 | fprintf (stderr, |
296 | "curl_easy_perform failed: `%s'\n", | 306 | "No error on IP address over limit\n"); |
297 | curl_easy_strerror (errornum)); | 307 | |
298 | 308 | for (j = 0; j < i; ++j) | |
299 | /* Last request should have failed */ | 309 | curl_easy_cleanup (cenv[j]); |
300 | else | 310 | MHD_stop_daemon (d); |
301 | fprintf (stderr, | 311 | return 32; |
302 | "No error on IP address over limit\n"); | 312 | } |
303 | 313 | } | |
304 | for (j = 0; j < i; ++j) | 314 | |
305 | curl_easy_cleanup (cenv[j]); | 315 | /* Cleanup the environments */ |
306 | MHD_stop_daemon (d); | 316 | for (i = 0; i < 3; ++i) |
307 | return 32; | 317 | curl_easy_cleanup (cenv[i]); |
308 | } | ||
309 | } | ||
310 | |||
311 | /* Cleanup the environments */ | ||
312 | for (i = 0; i < 3; ++i) | ||
313 | curl_easy_cleanup (cenv[i]); | ||
314 | |||
315 | (void)sleep(2); | ||
316 | |||
317 | for (i = 0; i < 2; ++i) | ||
318 | { | ||
319 | if (cbc[i].pos != strlen ("/hello_world")) | ||
320 | { | ||
321 | MHD_stop_daemon (d); | ||
322 | return 64; | ||
323 | } | ||
324 | if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world"))) | ||
325 | { | ||
326 | MHD_stop_daemon (d); | ||
327 | return 128; | ||
328 | } | ||
329 | } | ||
330 | 318 | ||
319 | (void) sleep (2); | ||
331 | 320 | ||
321 | for (i = 0; i < 2; ++i) | ||
322 | { | ||
323 | if (cbc[i].pos != strlen ("/hello_world")) | ||
324 | { | ||
325 | MHD_stop_daemon (d); | ||
326 | return 64; | ||
327 | } | ||
328 | if (0 != strncmp ("/hello_world", cbc[i].buf, strlen ("/hello_world"))) | ||
329 | { | ||
330 | MHD_stop_daemon (d); | ||
331 | return 128; | ||
332 | } | ||
332 | } | 333 | } |
334 | |||
335 | |||
336 | } | ||
333 | MHD_stop_daemon (d); | 337 | MHD_stop_daemon (d); |
334 | return 0; | 338 | return 0; |
335 | } | 339 | } |
@@ -338,9 +342,9 @@ int | |||
338 | main (int argc, char *const *argv) | 342 | main (int argc, char *const *argv) |
339 | { | 343 | { |
340 | unsigned int errorCount = 0; | 344 | unsigned int errorCount = 0; |
341 | (void)argc; /* Unused. Silent compiler warning. */ | 345 | (void) argc; /* Unused. Silent compiler warning. */ |
342 | 346 | ||
343 | if (NULL == argv || 0 == argv[0]) | 347 | if ((NULL == argv)||(0 == argv[0])) |
344 | return 99; | 348 | return 99; |
345 | oneone = has_in_name (argv[0], "11"); | 349 | oneone = has_in_name (argv[0], "11"); |
346 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 350 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
diff --git a/src/testcurl/test_large_put.c b/src/testcurl/test_large_put.c index 4495cfd6..0b7256ae 100644 --- a/src/testcurl/test_large_put.c +++ b/src/testcurl/test_large_put.c | |||
@@ -38,10 +38,10 @@ | |||
38 | 38 | ||
39 | #include "test_helpers.h" | 39 | #include "test_helpers.h" |
40 | 40 | ||
41 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 41 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
42 | #undef CPU_COUNT | 42 | #undef CPU_COUNT |
43 | #endif | 43 | #endif |
44 | #if !defined(CPU_COUNT) | 44 | #if ! defined(CPU_COUNT) |
45 | #define CPU_COUNT 2 | 45 | #define CPU_COUNT 2 |
46 | #endif | 46 | #endif |
47 | 47 | ||
@@ -61,34 +61,35 @@ struct CBC | |||
61 | }; | 61 | }; |
62 | 62 | ||
63 | char* | 63 | char* |
64 | alloc_init(size_t buf_size) | 64 | alloc_init (size_t buf_size) |
65 | { | 65 | { |
66 | static const char template[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz"; | 66 | static const char template[] = |
67 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz"; | ||
67 | static const size_t templ_size = sizeof(template) / sizeof(char) - 1; | 68 | static const size_t templ_size = sizeof(template) / sizeof(char) - 1; |
68 | char *buf; | 69 | char *buf; |
69 | char *fill_ptr; | 70 | char *fill_ptr; |
70 | size_t to_fill; | 71 | size_t to_fill; |
71 | 72 | ||
72 | buf = malloc(buf_size); | 73 | buf = malloc (buf_size); |
73 | if (NULL == buf) | 74 | if (NULL == buf) |
74 | return NULL; | 75 | return NULL; |
75 | 76 | ||
76 | fill_ptr = buf; | 77 | fill_ptr = buf; |
77 | to_fill = buf_size; | 78 | to_fill = buf_size; |
78 | while (to_fill > 0) | 79 | while (to_fill > 0) |
79 | { | 80 | { |
80 | const size_t to_copy = to_fill > templ_size ? templ_size : to_fill; | 81 | const size_t to_copy = to_fill > templ_size ? templ_size : to_fill; |
81 | memcpy (fill_ptr, template, to_copy); | 82 | memcpy (fill_ptr, template, to_copy); |
82 | fill_ptr += to_copy; | 83 | fill_ptr += to_copy; |
83 | to_fill -= to_copy; | 84 | to_fill -= to_copy; |
84 | } | 85 | } |
85 | return buf; | 86 | return buf; |
86 | } | 87 | } |
87 | 88 | ||
88 | static size_t | 89 | static size_t |
89 | putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) | 90 | putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) |
90 | { | 91 | { |
91 | size_t *pos = (size_t *)ptr; | 92 | size_t *pos = (size_t *) ptr; |
92 | size_t wrt; | 93 | size_t wrt; |
93 | 94 | ||
94 | wrt = size * nmemb; | 95 | wrt = size * nmemb; |
@@ -127,46 +128,46 @@ ahc_echo (void *cls, | |||
127 | struct MHD_Response *response; | 128 | struct MHD_Response *response; |
128 | int ret; | 129 | int ret; |
129 | static size_t processed; | 130 | static size_t processed; |
130 | (void)version; /* Unused. Silent compiler warning. */ | 131 | (void) version; /* Unused. Silent compiler warning. */ |
131 | 132 | ||
132 | if (0 != strcmp ("PUT", method)) | 133 | if (0 != strcmp ("PUT", method)) |
133 | return MHD_NO; /* unexpected method */ | 134 | return MHD_NO; /* unexpected method */ |
134 | if ((*done) == 0) | 135 | if ((*done) == 0) |
136 | { | ||
137 | size_t *pproc; | ||
138 | if (NULL == *pparam) | ||
139 | { | ||
140 | processed = 0; | ||
141 | *pparam = &processed; /* Safe as long as only one parallel request served. */ | ||
142 | } | ||
143 | pproc = (size_t*) *pparam; | ||
144 | |||
145 | if (0 == *upload_data_size) | ||
146 | return MHD_YES; /* No data to process. */ | ||
147 | |||
148 | if (*pproc + *upload_data_size > PUT_SIZE) | ||
149 | { | ||
150 | fprintf (stderr, "Incoming data larger than expected.\n"); | ||
151 | return MHD_NO; | ||
152 | } | ||
153 | if ( (! incr_read) && (*upload_data_size != PUT_SIZE) ) | ||
154 | return MHD_YES; /* Wait until whole request is received. */ | ||
155 | |||
156 | if (0 != memcmp (upload_data, put_buffer + (*pproc), *upload_data_size)) | ||
135 | { | 157 | { |
136 | size_t *pproc; | 158 | fprintf (stderr, "Incoming data does not match sent data.\n"); |
137 | if (NULL == *pparam) | 159 | return MHD_NO; |
138 | { | ||
139 | processed = 0; | ||
140 | *pparam = &processed; /* Safe as long as only one parallel request served. */ | ||
141 | } | ||
142 | pproc = (size_t*) *pparam; | ||
143 | |||
144 | if (0 == *upload_data_size) | ||
145 | return MHD_YES; /* No data to process. */ | ||
146 | |||
147 | if (*pproc + *upload_data_size > PUT_SIZE) | ||
148 | { | ||
149 | fprintf (stderr, "Incoming data larger than expected.\n"); | ||
150 | return MHD_NO; | ||
151 | } | ||
152 | if ( (!incr_read) && (*upload_data_size != PUT_SIZE) ) | ||
153 | return MHD_YES; /* Wait until whole request is received. */ | ||
154 | |||
155 | if (0 != memcmp(upload_data, put_buffer + (*pproc), *upload_data_size)) | ||
156 | { | ||
157 | fprintf (stderr, "Incoming data does not match sent data.\n"); | ||
158 | return MHD_NO; | ||
159 | } | ||
160 | *pproc += *upload_data_size; | ||
161 | *upload_data_size = 0; /* Current block of data is fully processed. */ | ||
162 | |||
163 | if (PUT_SIZE == *pproc) | ||
164 | *done = 1; /* Whole request is processed. */ | ||
165 | return MHD_YES; | ||
166 | } | 160 | } |
161 | *pproc += *upload_data_size; | ||
162 | *upload_data_size = 0; /* Current block of data is fully processed. */ | ||
163 | |||
164 | if (PUT_SIZE == *pproc) | ||
165 | *done = 1; /* Whole request is processed. */ | ||
166 | return MHD_YES; | ||
167 | } | ||
167 | response = MHD_create_response_from_buffer (strlen (url), | 168 | response = MHD_create_response_from_buffer (strlen (url), |
168 | (void *) url, | 169 | (void *) url, |
169 | MHD_RESPMEM_MUST_COPY); | 170 | MHD_RESPMEM_MUST_COPY); |
170 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 171 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
171 | MHD_destroy_response (response); | 172 | MHD_destroy_response (response); |
172 | return ret; | 173 | return ret; |
@@ -188,35 +189,39 @@ testPutInternalThread (unsigned int add_flag) | |||
188 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 189 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
189 | port = 0; | 190 | port = 0; |
190 | else | 191 | else |
191 | { | 192 | { |
192 | port = 1270; | 193 | port = 1270; |
193 | if (oneone) | 194 | if (oneone) |
194 | port += 10; | 195 | port += 10; |
195 | if (incr_read) | 196 | if (incr_read) |
196 | port += 20; | 197 | port += 20; |
197 | } | 198 | } |
198 | 199 | ||
199 | cbc.buf = buf; | 200 | cbc.buf = buf; |
200 | cbc.size = 2048; | 201 | cbc.size = 2048; |
201 | cbc.pos = 0; | 202 | cbc.pos = 0; |
202 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | add_flag, | 203 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
204 | | add_flag, | ||
203 | port, | 205 | port, |
204 | NULL, NULL, &ahc_echo, &done_flag, | 206 | NULL, NULL, &ahc_echo, &done_flag, |
205 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4 / 3)), | 207 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
206 | MHD_OPTION_END); | 208 | (size_t) (incr_read ? 1024 : (PUT_SIZE * 4 / 3)), |
209 | MHD_OPTION_END); | ||
207 | if (d == NULL) | 210 | if (d == NULL) |
208 | return 1; | 211 | return 1; |
209 | if (0 == port) | 212 | if (0 == port) |
213 | { | ||
214 | const union MHD_DaemonInfo *dinfo; | ||
215 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
216 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
210 | { | 217 | { |
211 | const union MHD_DaemonInfo *dinfo; | 218 | MHD_stop_daemon (d); return 32; |
212 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
213 | if (NULL == dinfo || 0 == dinfo->port) | ||
214 | { MHD_stop_daemon (d); return 32; } | ||
215 | port = (int)dinfo->port; | ||
216 | } | 219 | } |
220 | port = (int) dinfo->port; | ||
221 | } | ||
217 | c = curl_easy_init (); | 222 | c = curl_easy_init (); |
218 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 223 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
219 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 224 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
220 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 225 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
221 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 226 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
222 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 227 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -235,14 +240,14 @@ testPutInternalThread (unsigned int add_flag) | |||
235 | * crashes on my system! */ | 240 | * crashes on my system! */ |
236 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 241 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
237 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 242 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
238 | { | 243 | { |
239 | fprintf (stderr, | 244 | fprintf (stderr, |
240 | "curl_easy_perform failed: `%s'\n", | 245 | "curl_easy_perform failed: `%s'\n", |
241 | curl_easy_strerror (errornum)); | 246 | curl_easy_strerror (errornum)); |
242 | curl_easy_cleanup (c); | 247 | curl_easy_cleanup (c); |
243 | MHD_stop_daemon (d); | 248 | MHD_stop_daemon (d); |
244 | return 2; | 249 | return 2; |
245 | } | 250 | } |
246 | curl_easy_cleanup (c); | 251 | curl_easy_cleanup (c); |
247 | MHD_stop_daemon (d); | 252 | MHD_stop_daemon (d); |
248 | if (cbc.pos != strlen ("/hello_world")) | 253 | if (cbc.pos != strlen ("/hello_world")) |
@@ -267,36 +272,40 @@ testPutThreadPerConn (unsigned int add_flag) | |||
267 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 272 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
268 | port = 0; | 273 | port = 0; |
269 | else | 274 | else |
270 | { | 275 | { |
271 | port = 1271; | 276 | port = 1271; |
272 | if (oneone) | 277 | if (oneone) |
273 | port += 10; | 278 | port += 10; |
274 | if (incr_read) | 279 | if (incr_read) |
275 | port += 20; | 280 | port += 20; |
276 | } | 281 | } |
277 | 282 | ||
278 | cbc.buf = buf; | 283 | cbc.buf = buf; |
279 | cbc.size = 2048; | 284 | cbc.size = 2048; |
280 | cbc.pos = 0; | 285 | cbc.pos = 0; |
281 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | | 286 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
282 | MHD_USE_ERROR_LOG | add_flag, | 287 | | MHD_USE_INTERNAL_POLLING_THREAD |
288 | | MHD_USE_ERROR_LOG | add_flag, | ||
283 | port, | 289 | port, |
284 | NULL, NULL, &ahc_echo, &done_flag, | 290 | NULL, NULL, &ahc_echo, &done_flag, |
285 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4)), | 291 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
286 | MHD_OPTION_END); | 292 | (size_t) (incr_read ? 1024 : (PUT_SIZE * 4)), |
293 | MHD_OPTION_END); | ||
287 | if (d == NULL) | 294 | if (d == NULL) |
288 | return 16; | 295 | return 16; |
289 | if (0 == port) | 296 | if (0 == port) |
297 | { | ||
298 | const union MHD_DaemonInfo *dinfo; | ||
299 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
300 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
290 | { | 301 | { |
291 | const union MHD_DaemonInfo *dinfo; | 302 | MHD_stop_daemon (d); return 32; |
292 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
293 | if (NULL == dinfo || 0 == dinfo->port) | ||
294 | { MHD_stop_daemon (d); return 32; } | ||
295 | port = (int)dinfo->port; | ||
296 | } | 303 | } |
304 | port = (int) dinfo->port; | ||
305 | } | ||
297 | c = curl_easy_init (); | 306 | c = curl_easy_init (); |
298 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 307 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
299 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 308 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
300 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 309 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
301 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 310 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
302 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 311 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -315,21 +324,21 @@ testPutThreadPerConn (unsigned int add_flag) | |||
315 | * crashes on my system! */ | 324 | * crashes on my system! */ |
316 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 325 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
317 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 326 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
318 | { | 327 | { |
319 | fprintf (stderr, | 328 | fprintf (stderr, |
320 | "curl_easy_perform failed: `%s'\n", | 329 | "curl_easy_perform failed: `%s'\n", |
321 | curl_easy_strerror (errornum)); | 330 | curl_easy_strerror (errornum)); |
322 | curl_easy_cleanup (c); | 331 | curl_easy_cleanup (c); |
323 | MHD_stop_daemon (d); | 332 | MHD_stop_daemon (d); |
324 | return 32; | 333 | return 32; |
325 | } | 334 | } |
326 | curl_easy_cleanup (c); | 335 | curl_easy_cleanup (c); |
327 | MHD_stop_daemon (d); | 336 | MHD_stop_daemon (d); |
328 | if (cbc.pos != strlen ("/hello_world")) | 337 | if (cbc.pos != strlen ("/hello_world")) |
329 | { | 338 | { |
330 | fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf); | 339 | fprintf (stderr, "Got invalid response `%.*s'\n", (int) cbc.pos, cbc.buf); |
331 | return 64; | 340 | return 64; |
332 | } | 341 | } |
333 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 342 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
334 | return 128; | 343 | return 128; |
335 | return 0; | 344 | return 0; |
@@ -350,36 +359,40 @@ testPutThreadPool (unsigned int add_flag) | |||
350 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 359 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
351 | port = 0; | 360 | port = 0; |
352 | else | 361 | else |
353 | { | 362 | { |
354 | port = 1272; | 363 | port = 1272; |
355 | if (oneone) | 364 | if (oneone) |
356 | port += 10; | 365 | port += 10; |
357 | if (incr_read) | 366 | if (incr_read) |
358 | port += 20; | 367 | port += 20; |
359 | } | 368 | } |
360 | 369 | ||
361 | cbc.buf = buf; | 370 | cbc.buf = buf; |
362 | cbc.size = 2048; | 371 | cbc.size = 2048; |
363 | cbc.pos = 0; | 372 | cbc.pos = 0; |
364 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | add_flag, | 373 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
374 | | add_flag, | ||
365 | port, | 375 | port, |
366 | NULL, NULL, &ahc_echo, &done_flag, | 376 | NULL, NULL, &ahc_echo, &done_flag, |
367 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, | 377 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, |
368 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4)), | 378 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
369 | MHD_OPTION_END); | 379 | (size_t) (incr_read ? 1024 : (PUT_SIZE * 4)), |
380 | MHD_OPTION_END); | ||
370 | if (d == NULL) | 381 | if (d == NULL) |
371 | return 16; | 382 | return 16; |
372 | if (0 == port) | 383 | if (0 == port) |
384 | { | ||
385 | const union MHD_DaemonInfo *dinfo; | ||
386 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
387 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
373 | { | 388 | { |
374 | const union MHD_DaemonInfo *dinfo; | 389 | MHD_stop_daemon (d); return 32; |
375 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
376 | if (NULL == dinfo || 0 == dinfo->port) | ||
377 | { MHD_stop_daemon (d); return 32; } | ||
378 | port = (int)dinfo->port; | ||
379 | } | 390 | } |
391 | port = (int) dinfo->port; | ||
392 | } | ||
380 | c = curl_easy_init (); | 393 | c = curl_easy_init (); |
381 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 394 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
382 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 395 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
383 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 396 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
384 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 397 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
385 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 398 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -398,21 +411,21 @@ testPutThreadPool (unsigned int add_flag) | |||
398 | * crashes on my system! */ | 411 | * crashes on my system! */ |
399 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 412 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
400 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 413 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
401 | { | 414 | { |
402 | fprintf (stderr, | 415 | fprintf (stderr, |
403 | "curl_easy_perform failed: `%s'\n", | 416 | "curl_easy_perform failed: `%s'\n", |
404 | curl_easy_strerror (errornum)); | 417 | curl_easy_strerror (errornum)); |
405 | curl_easy_cleanup (c); | 418 | curl_easy_cleanup (c); |
406 | MHD_stop_daemon (d); | 419 | MHD_stop_daemon (d); |
407 | return 32; | 420 | return 32; |
408 | } | 421 | } |
409 | curl_easy_cleanup (c); | 422 | curl_easy_cleanup (c); |
410 | MHD_stop_daemon (d); | 423 | MHD_stop_daemon (d); |
411 | if (cbc.pos != strlen ("/hello_world")) | 424 | if (cbc.pos != strlen ("/hello_world")) |
412 | { | 425 | { |
413 | fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf); | 426 | fprintf (stderr, "Got invalid response `%.*s'\n", (int) cbc.pos, cbc.buf); |
414 | return 64; | 427 | return 64; |
415 | } | 428 | } |
416 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 429 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
417 | return 128; | 430 | return 128; |
418 | return 0; | 431 | return 0; |
@@ -447,13 +460,13 @@ testPutExternal (void) | |||
447 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 460 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
448 | port = 0; | 461 | port = 0; |
449 | else | 462 | else |
450 | { | 463 | { |
451 | port = 1273; | 464 | port = 1273; |
452 | if (oneone) | 465 | if (oneone) |
453 | port += 10; | 466 | port += 10; |
454 | if (incr_read) | 467 | if (incr_read) |
455 | port += 20; | 468 | port += 20; |
456 | } | 469 | } |
457 | 470 | ||
458 | cbc.buf = buf; | 471 | cbc.buf = buf; |
459 | cbc.size = 2048; | 472 | cbc.size = 2048; |
@@ -462,21 +475,24 @@ testPutExternal (void) | |||
462 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, | 475 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, |
463 | port, | 476 | port, |
464 | NULL, NULL, &ahc_echo, &done_flag, | 477 | NULL, NULL, &ahc_echo, &done_flag, |
465 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read ? 1024 : (PUT_SIZE * 4)), | 478 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
479 | (size_t) (incr_read ? 1024 : (PUT_SIZE * 4)), | ||
466 | MHD_OPTION_END); | 480 | MHD_OPTION_END); |
467 | if (d == NULL) | 481 | if (d == NULL) |
468 | return 256; | 482 | return 256; |
469 | if (0 == port) | 483 | if (0 == port) |
484 | { | ||
485 | const union MHD_DaemonInfo *dinfo; | ||
486 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
487 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
470 | { | 488 | { |
471 | const union MHD_DaemonInfo *dinfo; | 489 | MHD_stop_daemon (d); return 32; |
472 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
473 | if (NULL == dinfo || 0 == dinfo->port) | ||
474 | { MHD_stop_daemon (d); return 32; } | ||
475 | port = (int)dinfo->port; | ||
476 | } | 490 | } |
491 | port = (int) dinfo->port; | ||
492 | } | ||
477 | c = curl_easy_init (); | 493 | c = curl_easy_init (); |
478 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 494 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
479 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 495 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
480 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 496 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
481 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 497 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
482 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 498 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -498,92 +514,94 @@ testPutExternal (void) | |||
498 | 514 | ||
499 | multi = curl_multi_init (); | 515 | multi = curl_multi_init (); |
500 | if (multi == NULL) | 516 | if (multi == NULL) |
517 | { | ||
518 | curl_easy_cleanup (c); | ||
519 | MHD_stop_daemon (d); | ||
520 | return 512; | ||
521 | } | ||
522 | mret = curl_multi_add_handle (multi, c); | ||
523 | if (mret != CURLM_OK) | ||
524 | { | ||
525 | curl_multi_cleanup (multi); | ||
526 | curl_easy_cleanup (c); | ||
527 | MHD_stop_daemon (d); | ||
528 | return 1024; | ||
529 | } | ||
530 | start = time (NULL); | ||
531 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
532 | { | ||
533 | maxsock = MHD_INVALID_SOCKET; | ||
534 | maxposixs = -1; | ||
535 | FD_ZERO (&rs); | ||
536 | FD_ZERO (&ws); | ||
537 | FD_ZERO (&es); | ||
538 | curl_multi_perform (multi, &running); | ||
539 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
540 | if (mret != CURLM_OK) | ||
501 | { | 541 | { |
542 | curl_multi_remove_handle (multi, c); | ||
543 | curl_multi_cleanup (multi); | ||
502 | curl_easy_cleanup (c); | 544 | curl_easy_cleanup (c); |
503 | MHD_stop_daemon (d); | 545 | MHD_stop_daemon (d); |
504 | return 512; | 546 | return 2048; |
505 | } | 547 | } |
506 | mret = curl_multi_add_handle (multi, c); | 548 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
507 | if (mret != CURLM_OK) | ||
508 | { | 549 | { |
550 | curl_multi_remove_handle (multi, c); | ||
509 | curl_multi_cleanup (multi); | 551 | curl_multi_cleanup (multi); |
510 | curl_easy_cleanup (c); | 552 | curl_easy_cleanup (c); |
511 | MHD_stop_daemon (d); | 553 | MHD_stop_daemon (d); |
512 | return 1024; | 554 | return 4096; |
513 | } | 555 | } |
514 | start = time (NULL); | 556 | tv.tv_sec = 0; |
515 | while ((time (NULL) - start < 5) && (multi != NULL)) | 557 | tv.tv_usec = 1000; |
558 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
516 | { | 559 | { |
517 | maxsock = MHD_INVALID_SOCKET; | ||
518 | maxposixs = -1; | ||
519 | FD_ZERO (&rs); | ||
520 | FD_ZERO (&ws); | ||
521 | FD_ZERO (&es); | ||
522 | curl_multi_perform (multi, &running); | ||
523 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
524 | if (mret != CURLM_OK) | ||
525 | { | ||
526 | curl_multi_remove_handle (multi, c); | ||
527 | curl_multi_cleanup (multi); | ||
528 | curl_easy_cleanup (c); | ||
529 | MHD_stop_daemon (d); | ||
530 | return 2048; | ||
531 | } | ||
532 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
533 | { | ||
534 | curl_multi_remove_handle (multi, c); | ||
535 | curl_multi_cleanup (multi); | ||
536 | curl_easy_cleanup (c); | ||
537 | MHD_stop_daemon (d); | ||
538 | return 4096; | ||
539 | } | ||
540 | tv.tv_sec = 0; | ||
541 | tv.tv_usec = 1000; | ||
542 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
543 | { | ||
544 | #ifdef MHD_POSIX_SOCKETS | 560 | #ifdef MHD_POSIX_SOCKETS |
545 | if (EINTR != errno) | 561 | if (EINTR != errno) |
546 | abort (); | 562 | abort (); |
547 | #else | 563 | #else |
548 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 564 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
549 | abort (); | 565 | ws.fd_count) |
550 | Sleep (1000); | 566 | ||(0 != es.fd_count) ) |
567 | abort (); | ||
568 | Sleep (1000); | ||
551 | #endif | 569 | #endif |
552 | } | ||
553 | curl_multi_perform (multi, &running); | ||
554 | if (running == 0) | ||
555 | { | ||
556 | msg = curl_multi_info_read (multi, &running); | ||
557 | if (msg == NULL) | ||
558 | break; | ||
559 | if (msg->msg == CURLMSG_DONE) | ||
560 | { | ||
561 | if (msg->data.result != CURLE_OK) | ||
562 | printf ("%s failed at %s:%d: `%s'\n", | ||
563 | "curl_multi_perform", | ||
564 | __FILE__, | ||
565 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
566 | curl_multi_remove_handle (multi, c); | ||
567 | curl_multi_cleanup (multi); | ||
568 | curl_easy_cleanup (c); | ||
569 | c = NULL; | ||
570 | multi = NULL; | ||
571 | } | ||
572 | } | ||
573 | MHD_run (d); | ||
574 | } | 570 | } |
575 | if (multi != NULL) | 571 | curl_multi_perform (multi, &running); |
572 | if (running == 0) | ||
576 | { | 573 | { |
577 | curl_multi_remove_handle (multi, c); | 574 | msg = curl_multi_info_read (multi, &running); |
578 | curl_easy_cleanup (c); | 575 | if (msg == NULL) |
579 | curl_multi_cleanup (multi); | 576 | break; |
577 | if (msg->msg == CURLMSG_DONE) | ||
578 | { | ||
579 | if (msg->data.result != CURLE_OK) | ||
580 | printf ("%s failed at %s:%d: `%s'\n", | ||
581 | "curl_multi_perform", | ||
582 | __FILE__, | ||
583 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
584 | curl_multi_remove_handle (multi, c); | ||
585 | curl_multi_cleanup (multi); | ||
586 | curl_easy_cleanup (c); | ||
587 | c = NULL; | ||
588 | multi = NULL; | ||
589 | } | ||
580 | } | 590 | } |
591 | MHD_run (d); | ||
592 | } | ||
593 | if (multi != NULL) | ||
594 | { | ||
595 | curl_multi_remove_handle (multi, c); | ||
596 | curl_easy_cleanup (c); | ||
597 | curl_multi_cleanup (multi); | ||
598 | } | ||
581 | MHD_stop_daemon (d); | 599 | MHD_stop_daemon (d); |
582 | if (cbc.pos != strlen ("/hello_world")) | 600 | if (cbc.pos != strlen ("/hello_world")) |
583 | { | 601 | { |
584 | fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf); | 602 | fprintf (stderr, "Got invalid response `%.*s'\n", (int) cbc.pos, cbc.buf); |
585 | return 8192; | 603 | return 8192; |
586 | } | 604 | } |
587 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 605 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
588 | return 16384; | 606 | return 16384; |
589 | return 0; | 607 | return 0; |
@@ -597,59 +615,67 @@ main (int argc, char *const *argv) | |||
597 | unsigned int errorCount = 0; | 615 | unsigned int errorCount = 0; |
598 | unsigned int lastErr; | 616 | unsigned int lastErr; |
599 | 617 | ||
600 | oneone = has_in_name(argv[0], "11"); | 618 | oneone = has_in_name (argv[0], "11"); |
601 | incr_read = has_in_name(argv[0], "_inc"); | 619 | incr_read = has_in_name (argv[0], "_inc"); |
602 | verbose = has_param(argc, argv, "-v"); | 620 | verbose = has_param (argc, argv, "-v"); |
603 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 621 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
604 | return 99; | 622 | return 99; |
605 | put_buffer = alloc_init (PUT_SIZE); | 623 | put_buffer = alloc_init (PUT_SIZE); |
606 | if (NULL == put_buffer) | 624 | if (NULL == put_buffer) |
607 | return 99; | 625 | return 99; |
608 | lastErr = testPutExternal (); | 626 | lastErr = testPutExternal (); |
609 | if (verbose && 0 != lastErr) | 627 | if (verbose &&(0 != lastErr)) |
610 | fprintf (stderr, "Error during testing with external select().\n"); | 628 | fprintf (stderr, "Error during testing with external select().\n"); |
611 | errorCount += lastErr; | 629 | errorCount += lastErr; |
612 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 630 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
631 | { | ||
632 | lastErr = testPutInternalThread (0); | ||
633 | if (verbose &&(0 != lastErr) ) | ||
634 | fprintf (stderr, | ||
635 | "Error during testing with internal thread with select().\n"); | ||
636 | errorCount += lastErr; | ||
637 | lastErr = testPutThreadPerConn (0); | ||
638 | if (verbose &&(0 != lastErr) ) | ||
639 | fprintf (stderr, | ||
640 | "Error during testing with internal thread per connection with select().\n"); | ||
641 | errorCount += lastErr; | ||
642 | lastErr = testPutThreadPool (0); | ||
643 | if (verbose &&(0 != lastErr) ) | ||
644 | fprintf (stderr, | ||
645 | "Error during testing with thread pool per connection with select().\n"); | ||
646 | errorCount += lastErr; | ||
647 | if (MHD_is_feature_supported (MHD_FEATURE_POLL)) | ||
613 | { | 648 | { |
614 | lastErr = testPutInternalThread (0); | 649 | lastErr = testPutInternalThread (MHD_USE_POLL); |
615 | if (verbose && 0 != lastErr) | 650 | if (verbose &&(0 != lastErr) ) |
616 | fprintf (stderr, "Error during testing with internal thread with select().\n"); | 651 | fprintf (stderr, |
652 | "Error during testing with internal thread with poll().\n"); | ||
617 | errorCount += lastErr; | 653 | errorCount += lastErr; |
618 | lastErr = testPutThreadPerConn (0); | 654 | lastErr = testPutThreadPerConn (MHD_USE_POLL); |
619 | if (verbose && 0 != lastErr) | 655 | if (verbose &&(0 != lastErr) ) |
620 | fprintf (stderr, "Error during testing with internal thread per connection with select().\n"); | 656 | fprintf (stderr, |
657 | "Error during testing with internal thread per connection with poll().\n"); | ||
658 | errorCount += lastErr; | ||
659 | lastErr = testPutThreadPool (MHD_USE_POLL); | ||
660 | if (verbose &&(0 != lastErr) ) | ||
661 | fprintf (stderr, | ||
662 | "Error during testing with thread pool per connection with poll().\n"); | ||
663 | errorCount += lastErr; | ||
664 | } | ||
665 | if (MHD_is_feature_supported (MHD_FEATURE_EPOLL)) | ||
666 | { | ||
667 | lastErr = testPutInternalThread (MHD_USE_EPOLL); | ||
668 | if (verbose &&(0 != lastErr) ) | ||
669 | fprintf (stderr, | ||
670 | "Error during testing with internal thread with epoll.\n"); | ||
621 | errorCount += lastErr; | 671 | errorCount += lastErr; |
622 | lastErr = testPutThreadPool (0); | 672 | lastErr = testPutThreadPool (MHD_USE_EPOLL); |
623 | if (verbose && 0 != lastErr) | 673 | if (verbose &&(0 != lastErr) ) |
624 | fprintf (stderr, "Error during testing with thread pool per connection with select().\n"); | 674 | fprintf (stderr, |
675 | "Error during testing with thread pool per connection with epoll.\n"); | ||
625 | errorCount += lastErr; | 676 | errorCount += lastErr; |
626 | if (MHD_is_feature_supported(MHD_FEATURE_POLL)) | ||
627 | { | ||
628 | lastErr = testPutInternalThread (MHD_USE_POLL); | ||
629 | if (verbose && 0 != lastErr) | ||
630 | fprintf (stderr, "Error during testing with internal thread with poll().\n"); | ||
631 | errorCount += lastErr; | ||
632 | lastErr = testPutThreadPerConn (MHD_USE_POLL); | ||
633 | if (verbose && 0 != lastErr) | ||
634 | fprintf (stderr, "Error during testing with internal thread per connection with poll().\n"); | ||
635 | errorCount += lastErr; | ||
636 | lastErr = testPutThreadPool (MHD_USE_POLL); | ||
637 | if (verbose && 0 != lastErr) | ||
638 | fprintf (stderr, "Error during testing with thread pool per connection with poll().\n"); | ||
639 | errorCount += lastErr; | ||
640 | } | ||
641 | if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) | ||
642 | { | ||
643 | lastErr = testPutInternalThread (MHD_USE_EPOLL); | ||
644 | if (verbose && 0 != lastErr) | ||
645 | fprintf (stderr, "Error during testing with internal thread with epoll.\n"); | ||
646 | errorCount += lastErr; | ||
647 | lastErr = testPutThreadPool (MHD_USE_EPOLL); | ||
648 | if (verbose && 0 != lastErr) | ||
649 | fprintf (stderr, "Error during testing with thread pool per connection with epoll.\n"); | ||
650 | errorCount += lastErr; | ||
651 | } | ||
652 | } | 677 | } |
678 | } | ||
653 | free (put_buffer); | 679 | free (put_buffer); |
654 | if (errorCount != 0) | 680 | if (errorCount != 0) |
655 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 681 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_long_header.c b/src/testcurl/test_long_header.c index dc76a136..01d62d11 100644 --- a/src/testcurl/test_long_header.c +++ b/src/testcurl/test_long_header.c | |||
@@ -42,14 +42,14 @@ | |||
42 | * half of this value, so the actual value does not have | 42 | * half of this value, so the actual value does not have |
43 | * to be big at all... | 43 | * to be big at all... |
44 | */ | 44 | */ |
45 | #define VERY_LONG (1024*8) | 45 | #define VERY_LONG (1024 * 8) |
46 | 46 | ||
47 | static int oneone; | 47 | static int oneone; |
48 | 48 | ||
49 | static int | 49 | static int |
50 | apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) | 50 | apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
51 | { | 51 | { |
52 | (void)cls;(void)addr;(void)addrlen; /* Unused. Silent compiler warning. */ | 52 | (void) cls; (void) addr; (void) addrlen; /* Unused. Silent compiler warning. */ |
53 | return MHD_YES; | 53 | return MHD_YES; |
54 | } | 54 | } |
55 | 55 | ||
@@ -63,7 +63,7 @@ struct CBC | |||
63 | static size_t | 63 | static size_t |
64 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 64 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) |
65 | { | 65 | { |
66 | (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ | 66 | (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */ |
67 | return size * nmemb; | 67 | return size * nmemb; |
68 | } | 68 | } |
69 | 69 | ||
@@ -79,14 +79,14 @@ ahc_echo (void *cls, | |||
79 | const char *me = cls; | 79 | const char *me = cls; |
80 | struct MHD_Response *response; | 80 | struct MHD_Response *response; |
81 | int ret; | 81 | int ret; |
82 | (void)version;(void)upload_data; /* Unused. Silent compiler warning. */ | 82 | (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ |
83 | (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ | 83 | (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ |
84 | 84 | ||
85 | if (0 != strcmp (me, method)) | 85 | if (0 != strcmp (me, method)) |
86 | return MHD_NO; /* unexpected method */ | 86 | return MHD_NO; /* unexpected method */ |
87 | response = MHD_create_response_from_buffer (strlen (url), | 87 | response = MHD_create_response_from_buffer (strlen (url), |
88 | (void *) url, | 88 | (void *) url, |
89 | MHD_RESPMEM_MUST_COPY); | 89 | MHD_RESPMEM_MUST_COPY); |
90 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 90 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
91 | MHD_destroy_response (response); | 91 | MHD_destroy_response (response); |
92 | return ret; | 92 | return ret; |
@@ -107,44 +107,47 @@ testLongUrlGet (size_t buff_size) | |||
107 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 107 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
108 | port = 0; | 108 | port = 0; |
109 | else | 109 | else |
110 | { | 110 | { |
111 | port = 1330 + buff_size % 20; | 111 | port = 1330 + buff_size % 20; |
112 | if (oneone) | 112 | if (oneone) |
113 | port += 5; | 113 | port += 5; |
114 | } | 114 | } |
115 | cbc.buf = buf; | 115 | cbc.buf = buf; |
116 | cbc.size = 2048; | 116 | cbc.size = 2048; |
117 | cbc.pos = 0; | 117 | cbc.pos = 0; |
118 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , | 118 | d = MHD_start_daemon ( |
119 | port, | 119 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */, |
120 | &apc_all, | 120 | port, |
121 | NULL, | 121 | &apc_all, |
122 | &ahc_echo, | 122 | NULL, |
123 | "GET", | 123 | &ahc_echo, |
124 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 124 | "GET", |
125 | (size_t) buff_size, MHD_OPTION_END); | 125 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
126 | (size_t) buff_size, MHD_OPTION_END); | ||
126 | if (d == NULL) | 127 | if (d == NULL) |
127 | return 1; | 128 | return 1; |
128 | if (0 == port) | 129 | if (0 == port) |
130 | { | ||
131 | const union MHD_DaemonInfo *dinfo; | ||
132 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
133 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
129 | { | 134 | { |
130 | const union MHD_DaemonInfo *dinfo; | 135 | MHD_stop_daemon (d); return 32; |
131 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
132 | if (NULL == dinfo || 0 == dinfo->port) | ||
133 | { MHD_stop_daemon (d); return 32; } | ||
134 | port = (int)dinfo->port; | ||
135 | } | 136 | } |
137 | port = (int) dinfo->port; | ||
138 | } | ||
136 | c = curl_easy_init (); | 139 | c = curl_easy_init (); |
137 | url = malloc (VERY_LONG); | 140 | url = malloc (VERY_LONG); |
138 | if (url == NULL) | 141 | if (url == NULL) |
139 | { | 142 | { |
140 | MHD_stop_daemon (d); | 143 | MHD_stop_daemon (d); |
141 | return 1; | 144 | return 1; |
142 | } | 145 | } |
143 | memset (url, 'a', VERY_LONG); | 146 | memset (url, 'a', VERY_LONG); |
144 | url[VERY_LONG - 1] = '\0'; | 147 | url[VERY_LONG - 1] = '\0'; |
145 | memcpy (url, "http://127.0.0.1/", strlen ("http://127.0.0.1/")); | 148 | memcpy (url, "http://127.0.0.1/", strlen ("http://127.0.0.1/")); |
146 | curl_easy_setopt (c, CURLOPT_URL, url); | 149 | curl_easy_setopt (c, CURLOPT_URL, url); |
147 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 150 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
148 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 151 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
149 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 152 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
150 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 153 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -159,19 +162,19 @@ testLongUrlGet (size_t buff_size) | |||
159 | crashes on my system! */ | 162 | crashes on my system! */ |
160 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 163 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
161 | if (CURLE_OK == curl_easy_perform (c)) | 164 | if (CURLE_OK == curl_easy_perform (c)) |
162 | { | 165 | { |
163 | curl_easy_cleanup (c); | 166 | curl_easy_cleanup (c); |
164 | MHD_stop_daemon (d); | 167 | MHD_stop_daemon (d); |
165 | free (url); | 168 | free (url); |
166 | return 2; | 169 | return 2; |
167 | } | 170 | } |
168 | if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) | 171 | if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) |
169 | { | 172 | { |
170 | curl_easy_cleanup (c); | 173 | curl_easy_cleanup (c); |
171 | MHD_stop_daemon (d); | 174 | MHD_stop_daemon (d); |
172 | free (url); | 175 | free (url); |
173 | return 4; | 176 | return 4; |
174 | } | 177 | } |
175 | curl_easy_cleanup (c); | 178 | curl_easy_cleanup (c); |
176 | MHD_stop_daemon (d); | 179 | MHD_stop_daemon (d); |
177 | free (url); | 180 | free (url); |
@@ -196,40 +199,43 @@ testLongHeaderGet (size_t buff_size) | |||
196 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 199 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
197 | port = 0; | 200 | port = 0; |
198 | else | 201 | else |
199 | { | 202 | { |
200 | port = 1331 + buff_size % 20; | 203 | port = 1331 + buff_size % 20; |
201 | if (oneone) | 204 | if (oneone) |
202 | port += 5; | 205 | port += 5; |
203 | } | 206 | } |
204 | 207 | ||
205 | cbc.buf = buf; | 208 | cbc.buf = buf; |
206 | cbc.size = 2048; | 209 | cbc.size = 2048; |
207 | cbc.pos = 0; | 210 | cbc.pos = 0; |
208 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , | 211 | d = MHD_start_daemon ( |
209 | port, | 212 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */, |
210 | &apc_all, | 213 | port, |
211 | NULL, | 214 | &apc_all, |
212 | &ahc_echo, | 215 | NULL, |
213 | "GET", | 216 | &ahc_echo, |
214 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 217 | "GET", |
215 | (size_t) buff_size, MHD_OPTION_END); | 218 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
219 | (size_t) buff_size, MHD_OPTION_END); | ||
216 | if (d == NULL) | 220 | if (d == NULL) |
217 | return 16; | 221 | return 16; |
218 | if (0 == port) | 222 | if (0 == port) |
223 | { | ||
224 | const union MHD_DaemonInfo *dinfo; | ||
225 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
226 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
219 | { | 227 | { |
220 | const union MHD_DaemonInfo *dinfo; | 228 | MHD_stop_daemon (d); return 32; |
221 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
222 | if (NULL == dinfo || 0 == dinfo->port) | ||
223 | { MHD_stop_daemon (d); return 32; } | ||
224 | port = (int)dinfo->port; | ||
225 | } | 229 | } |
230 | port = (int) dinfo->port; | ||
231 | } | ||
226 | c = curl_easy_init (); | 232 | c = curl_easy_init (); |
227 | url = malloc (VERY_LONG); | 233 | url = malloc (VERY_LONG); |
228 | if (url == NULL) | 234 | if (url == NULL) |
229 | { | 235 | { |
230 | MHD_stop_daemon (d); | 236 | MHD_stop_daemon (d); |
231 | return 16; | 237 | return 16; |
232 | } | 238 | } |
233 | memset (url, 'a', VERY_LONG); | 239 | memset (url, 'a', VERY_LONG); |
234 | url[VERY_LONG - 1] = '\0'; | 240 | url[VERY_LONG - 1] = '\0'; |
235 | url[VERY_LONG / 2] = ':'; | 241 | url[VERY_LONG / 2] = ':'; |
@@ -238,7 +244,7 @@ testLongHeaderGet (size_t buff_size) | |||
238 | 244 | ||
239 | curl_easy_setopt (c, CURLOPT_HTTPHEADER, header); | 245 | curl_easy_setopt (c, CURLOPT_HTTPHEADER, header); |
240 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 246 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
241 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 247 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
242 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 248 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
243 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 249 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
244 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 250 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -253,21 +259,21 @@ testLongHeaderGet (size_t buff_size) | |||
253 | crashes on my system! */ | 259 | crashes on my system! */ |
254 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 260 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
255 | if (CURLE_OK == curl_easy_perform (c)) | 261 | if (CURLE_OK == curl_easy_perform (c)) |
256 | { | 262 | { |
257 | curl_easy_cleanup (c); | 263 | curl_easy_cleanup (c); |
258 | MHD_stop_daemon (d); | 264 | MHD_stop_daemon (d); |
259 | curl_slist_free_all (header); | 265 | curl_slist_free_all (header); |
260 | free (url); | 266 | free (url); |
261 | return 32; | 267 | return 32; |
262 | } | 268 | } |
263 | if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) | 269 | if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) |
264 | { | 270 | { |
265 | curl_slist_free_all (header); | 271 | curl_slist_free_all (header); |
266 | curl_easy_cleanup (c); | 272 | curl_easy_cleanup (c); |
267 | MHD_stop_daemon (d); | 273 | MHD_stop_daemon (d); |
268 | free (url); | 274 | free (url); |
269 | return 64; | 275 | return 64; |
270 | } | 276 | } |
271 | curl_slist_free_all (header); | 277 | curl_slist_free_all (header); |
272 | curl_easy_cleanup (c); | 278 | curl_easy_cleanup (c); |
273 | MHD_stop_daemon (d); | 279 | MHD_stop_daemon (d); |
@@ -281,9 +287,9 @@ int | |||
281 | main (int argc, char *const *argv) | 287 | main (int argc, char *const *argv) |
282 | { | 288 | { |
283 | unsigned int errorCount = 0; | 289 | unsigned int errorCount = 0; |
284 | (void)argc; /* Unused. Silent compiler warning. */ | 290 | (void) argc; /* Unused. Silent compiler warning. */ |
285 | 291 | ||
286 | if (NULL == argv || 0 == argv[0]) | 292 | if ((NULL == argv)||(0 == argv[0])) |
287 | return 99; | 293 | return 99; |
288 | oneone = has_in_name (argv[0], "11"); | 294 | oneone = has_in_name (argv[0], "11"); |
289 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 295 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
diff --git a/src/testcurl/test_parse_cookies.c b/src/testcurl/test_parse_cookies.c index c09846d8..da33ea3f 100644 --- a/src/testcurl/test_parse_cookies.c +++ b/src/testcurl/test_parse_cookies.c | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | /* | 1 | /* |
3 | This file is part of libmicrohttpd | 2 | This file is part of libmicrohttpd |
4 | Copyright (C) 2007 Christian Grothoff | 3 | Copyright (C) 2007 Christian Grothoff |
@@ -73,15 +72,15 @@ ahc_echo (void *cls, | |||
73 | struct MHD_Response *response; | 72 | struct MHD_Response *response; |
74 | int ret; | 73 | int ret; |
75 | const char *hdr; | 74 | const char *hdr; |
76 | (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. */ |
77 | 76 | ||
78 | if (0 != strcmp (me, method)) | 77 | if (0 != strcmp (me, method)) |
79 | return MHD_NO; /* unexpected method */ | 78 | return MHD_NO; /* unexpected method */ |
80 | if (&ptr != *unused) | 79 | if (&ptr != *unused) |
81 | { | 80 | { |
82 | *unused = &ptr; | 81 | *unused = &ptr; |
83 | return MHD_YES; | 82 | return MHD_YES; |
84 | } | 83 | } |
85 | *unused = NULL; | 84 | *unused = NULL; |
86 | 85 | ||
87 | hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name1"); | 86 | hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name1"); |
@@ -97,8 +96,8 @@ ahc_echo (void *cls, | |||
97 | if ((hdr == NULL) || (0 != strcmp (hdr, "var4 with spaces"))) | 96 | if ((hdr == NULL) || (0 != strcmp (hdr, "var4 with spaces"))) |
98 | abort (); | 97 | abort (); |
99 | response = MHD_create_response_from_buffer (strlen (url), | 98 | response = MHD_create_response_from_buffer (strlen (url), |
100 | (void *) url, | 99 | (void *) url, |
101 | MHD_RESPMEM_PERSISTENT); | 100 | MHD_RESPMEM_PERSISTENT); |
102 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 101 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
103 | MHD_destroy_response (response); | 102 | MHD_destroy_response (response); |
104 | if (ret == MHD_NO) | 103 | if (ret == MHD_NO) |
@@ -133,11 +132,11 @@ testExternalGet () | |||
133 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 132 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
134 | port = 0; | 133 | port = 0; |
135 | else | 134 | else |
136 | { | 135 | { |
137 | port = 1340; | 136 | port = 1340; |
138 | if (oneone) | 137 | if (oneone) |
139 | port += 5; | 138 | port += 5; |
140 | } | 139 | } |
141 | 140 | ||
142 | multi = NULL; | 141 | multi = NULL; |
143 | cbc.buf = buf; | 142 | cbc.buf = buf; |
@@ -148,16 +147,18 @@ testExternalGet () | |||
148 | if (d == NULL) | 147 | if (d == NULL) |
149 | return 256; | 148 | return 256; |
150 | if (0 == port) | 149 | if (0 == port) |
150 | { | ||
151 | const union MHD_DaemonInfo *dinfo; | ||
152 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
153 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
151 | { | 154 | { |
152 | const union MHD_DaemonInfo *dinfo; | 155 | MHD_stop_daemon (d); return 32; |
153 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
154 | if (NULL == dinfo || 0 == dinfo->port) | ||
155 | { MHD_stop_daemon (d); return 32; } | ||
156 | port = (int)dinfo->port; | ||
157 | } | 156 | } |
157 | port = (int) dinfo->port; | ||
158 | } | ||
158 | c = curl_easy_init (); | 159 | c = curl_easy_init (); |
159 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 160 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
160 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 161 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
161 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 162 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
162 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 163 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
163 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 164 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -180,86 +181,88 @@ testExternalGet () | |||
180 | 181 | ||
181 | multi = curl_multi_init (); | 182 | multi = curl_multi_init (); |
182 | if (multi == NULL) | 183 | if (multi == NULL) |
184 | { | ||
185 | curl_easy_cleanup (c); | ||
186 | MHD_stop_daemon (d); | ||
187 | return 512; | ||
188 | } | ||
189 | mret = curl_multi_add_handle (multi, c); | ||
190 | if (mret != CURLM_OK) | ||
191 | { | ||
192 | curl_multi_cleanup (multi); | ||
193 | curl_easy_cleanup (c); | ||
194 | MHD_stop_daemon (d); | ||
195 | return 1024; | ||
196 | } | ||
197 | start = time (NULL); | ||
198 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
199 | { | ||
200 | maxsock = MHD_INVALID_SOCKET; | ||
201 | maxposixs = -1; | ||
202 | FD_ZERO (&rs); | ||
203 | FD_ZERO (&ws); | ||
204 | FD_ZERO (&es); | ||
205 | curl_multi_perform (multi, &running); | ||
206 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
207 | if (mret != CURLM_OK) | ||
183 | { | 208 | { |
209 | curl_multi_remove_handle (multi, c); | ||
210 | curl_multi_cleanup (multi); | ||
184 | curl_easy_cleanup (c); | 211 | curl_easy_cleanup (c); |
185 | MHD_stop_daemon (d); | 212 | MHD_stop_daemon (d); |
186 | return 512; | 213 | return 2048; |
187 | } | 214 | } |
188 | mret = curl_multi_add_handle (multi, c); | 215 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
189 | if (mret != CURLM_OK) | ||
190 | { | 216 | { |
217 | curl_multi_remove_handle (multi, c); | ||
191 | curl_multi_cleanup (multi); | 218 | curl_multi_cleanup (multi); |
192 | curl_easy_cleanup (c); | 219 | curl_easy_cleanup (c); |
193 | MHD_stop_daemon (d); | 220 | MHD_stop_daemon (d); |
194 | return 1024; | 221 | return 4096; |
195 | } | 222 | } |
196 | start = time (NULL); | 223 | tv.tv_sec = 0; |
197 | while ((time (NULL) - start < 5) && (multi != NULL)) | 224 | tv.tv_usec = 1000; |
225 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
198 | { | 226 | { |
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 | 227 | #ifdef MHD_POSIX_SOCKETS |
227 | if (EINTR != errno) | 228 | if (EINTR != errno) |
228 | abort (); | 229 | abort (); |
229 | #else | 230 | #else |
230 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 231 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
231 | abort (); | 232 | ws.fd_count) |
232 | Sleep (1000); | 233 | ||(0 != es.fd_count) ) |
234 | abort (); | ||
235 | Sleep (1000); | ||
233 | #endif | 236 | #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 | } | 237 | } |
257 | if (multi != NULL) | 238 | curl_multi_perform (multi, &running); |
239 | if (running == 0) | ||
258 | { | 240 | { |
259 | curl_multi_remove_handle (multi, c); | 241 | msg = curl_multi_info_read (multi, &running); |
260 | curl_easy_cleanup (c); | 242 | if (msg == NULL) |
261 | curl_multi_cleanup (multi); | 243 | break; |
244 | if (msg->msg == CURLMSG_DONE) | ||
245 | { | ||
246 | if (msg->data.result != CURLE_OK) | ||
247 | printf ("%s failed at %s:%d: `%s'\n", | ||
248 | "curl_multi_perform", | ||
249 | __FILE__, | ||
250 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
251 | curl_multi_remove_handle (multi, c); | ||
252 | curl_multi_cleanup (multi); | ||
253 | curl_easy_cleanup (c); | ||
254 | c = NULL; | ||
255 | multi = NULL; | ||
256 | } | ||
262 | } | 257 | } |
258 | MHD_run (d); | ||
259 | } | ||
260 | if (multi != NULL) | ||
261 | { | ||
262 | curl_multi_remove_handle (multi, c); | ||
263 | curl_easy_cleanup (c); | ||
264 | curl_multi_cleanup (multi); | ||
265 | } | ||
263 | MHD_stop_daemon (d); | 266 | MHD_stop_daemon (d); |
264 | if (cbc.pos != strlen ("/hello_world")) | 267 | if (cbc.pos != strlen ("/hello_world")) |
265 | return 8192; | 268 | return 8192; |
@@ -273,9 +276,9 @@ int | |||
273 | main (int argc, char *const *argv) | 276 | main (int argc, char *const *argv) |
274 | { | 277 | { |
275 | unsigned int errorCount = 0; | 278 | unsigned int errorCount = 0; |
276 | (void)argc; /* Unused. Silent compiler warning. */ | 279 | (void) argc; /* Unused. Silent compiler warning. */ |
277 | 280 | ||
278 | if (NULL == argv || 0 == argv[0]) | 281 | if ((NULL == argv)||(0 == argv[0])) |
279 | return 99; | 282 | return 99; |
280 | oneone = has_in_name (argv[0], "11"); | 283 | oneone = has_in_name (argv[0], "11"); |
281 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 284 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
diff --git a/src/testcurl/test_post.c b/src/testcurl/test_post.c index 03452a2f..b665139a 100644 --- a/src/testcurl/test_post.c +++ b/src/testcurl/test_post.c | |||
@@ -45,10 +45,10 @@ | |||
45 | 45 | ||
46 | #include "mhd_has_in_name.h" | 46 | #include "mhd_has_in_name.h" |
47 | 47 | ||
48 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 48 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
49 | #undef CPU_COUNT | 49 | #undef CPU_COUNT |
50 | #endif | 50 | #endif |
51 | #if !defined(CPU_COUNT) | 51 | #if ! defined(CPU_COUNT) |
52 | #define CPU_COUNT 2 | 52 | #define CPU_COUNT 2 |
53 | #endif | 53 | #endif |
54 | 54 | ||
@@ -66,12 +66,12 @@ struct CBC | |||
66 | 66 | ||
67 | static void | 67 | static void |
68 | completed_cb (void *cls, | 68 | completed_cb (void *cls, |
69 | struct MHD_Connection *connection, | 69 | struct MHD_Connection *connection, |
70 | void **con_cls, | 70 | void **con_cls, |
71 | enum MHD_RequestTerminationCode toe) | 71 | enum MHD_RequestTerminationCode toe) |
72 | { | 72 | { |
73 | struct MHD_PostProcessor *pp = *con_cls; | 73 | struct MHD_PostProcessor *pp = *con_cls; |
74 | (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ | 74 | (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */ |
75 | 75 | ||
76 | if (NULL != pp) | 76 | if (NULL != pp) |
77 | MHD_destroy_post_processor (pp); | 77 | MHD_destroy_post_processor (pp); |
@@ -107,8 +107,8 @@ post_iterator (void *cls, | |||
107 | const char *value, uint64_t off, size_t size) | 107 | const char *value, uint64_t off, size_t size) |
108 | { | 108 | { |
109 | int *eok = cls; | 109 | int *eok = cls; |
110 | (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ | 110 | (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */ |
111 | (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ | 111 | (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */ |
112 | 112 | ||
113 | if ((0 == strcasecmp (key, "name")) && | 113 | if ((0 == strcasecmp (key, "name")) && |
114 | (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size))) | 114 | (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size))) |
@@ -133,32 +133,32 @@ ahc_echo (void *cls, | |||
133 | struct MHD_Response *response; | 133 | struct MHD_Response *response; |
134 | struct MHD_PostProcessor *pp; | 134 | struct MHD_PostProcessor *pp; |
135 | int ret; | 135 | int ret; |
136 | (void)cls;(void)version; /* Unused. Silent compiler warning. */ | 136 | (void) cls; (void) version; /* Unused. Silent compiler warning. */ |
137 | 137 | ||
138 | if (0 != strcasecmp ("POST", method)) | 138 | if (0 != strcasecmp ("POST", method)) |
139 | { | 139 | { |
140 | printf ("METHOD: %s\n", method); | 140 | printf ("METHOD: %s\n", method); |
141 | return MHD_NO; /* unexpected method */ | 141 | return MHD_NO; /* unexpected method */ |
142 | } | 142 | } |
143 | pp = *unused; | 143 | pp = *unused; |
144 | if (pp == NULL) | 144 | if (pp == NULL) |
145 | { | 145 | { |
146 | eok = 0; | 146 | eok = 0; |
147 | pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); | 147 | pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); |
148 | *unused = pp; | 148 | *unused = pp; |
149 | } | 149 | } |
150 | MHD_post_process (pp, upload_data, *upload_data_size); | 150 | MHD_post_process (pp, upload_data, *upload_data_size); |
151 | if ((eok == 3) && (0 == *upload_data_size)) | 151 | if ((eok == 3) && (0 == *upload_data_size)) |
152 | { | 152 | { |
153 | response = MHD_create_response_from_buffer (strlen (url), | 153 | response = MHD_create_response_from_buffer (strlen (url), |
154 | (void *) url, | 154 | (void *) url, |
155 | MHD_RESPMEM_MUST_COPY); | 155 | MHD_RESPMEM_MUST_COPY); |
156 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 156 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
157 | MHD_destroy_response (response); | 157 | MHD_destroy_response (response); |
158 | MHD_destroy_post_processor (pp); | 158 | MHD_destroy_post_processor (pp); |
159 | *unused = NULL; | 159 | *unused = NULL; |
160 | return ret; | 160 | return ret; |
161 | } | 161 | } |
162 | *upload_data_size = 0; | 162 | *upload_data_size = 0; |
163 | return MHD_YES; | 163 | return MHD_YES; |
164 | } | 164 | } |
@@ -177,32 +177,34 @@ testInternalPost () | |||
177 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 177 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
178 | port = 0; | 178 | port = 0; |
179 | else | 179 | else |
180 | { | 180 | { |
181 | port = 1370; | 181 | port = 1370; |
182 | if (oneone) | 182 | if (oneone) |
183 | port += 10; | 183 | port += 10; |
184 | } | 184 | } |
185 | 185 | ||
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_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 189 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
190 | port, NULL, NULL, &ahc_echo, NULL, | 190 | port, NULL, NULL, &ahc_echo, NULL, |
191 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, | 191 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, |
192 | MHD_OPTION_END); | 192 | MHD_OPTION_END); |
193 | if (d == NULL) | 193 | if (d == NULL) |
194 | return 1; | 194 | return 1; |
195 | if (0 == port) | 195 | if (0 == port) |
196 | { | ||
197 | const union MHD_DaemonInfo *dinfo; | ||
198 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
199 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
196 | { | 200 | { |
197 | const union MHD_DaemonInfo *dinfo; | 201 | MHD_stop_daemon (d); return 32; |
198 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
199 | if (NULL == dinfo || 0 == dinfo->port) | ||
200 | { MHD_stop_daemon (d); return 32; } | ||
201 | port = (int)dinfo->port; | ||
202 | } | 202 | } |
203 | port = (int) dinfo->port; | ||
204 | } | ||
203 | c = curl_easy_init (); | 205 | c = curl_easy_init (); |
204 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 206 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
205 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 207 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
206 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 208 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
207 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 209 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
208 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 210 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
@@ -220,14 +222,14 @@ testInternalPost () | |||
220 | * crashes on my system! */ | 222 | * crashes on my system! */ |
221 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 223 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
222 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 224 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
223 | { | 225 | { |
224 | fprintf (stderr, | 226 | fprintf (stderr, |
225 | "curl_easy_perform failed: `%s'\n", | 227 | "curl_easy_perform failed: `%s'\n", |
226 | curl_easy_strerror (errornum)); | 228 | curl_easy_strerror (errornum)); |
227 | curl_easy_cleanup (c); | 229 | curl_easy_cleanup (c); |
228 | MHD_stop_daemon (d); | 230 | MHD_stop_daemon (d); |
229 | return 2; | 231 | return 2; |
230 | } | 232 | } |
231 | curl_easy_cleanup (c); | 233 | curl_easy_cleanup (c); |
232 | MHD_stop_daemon (d); | 234 | MHD_stop_daemon (d); |
233 | if (cbc.pos != strlen ("/hello_world")) | 235 | if (cbc.pos != strlen ("/hello_world")) |
@@ -250,32 +252,35 @@ testMultithreadedPost () | |||
250 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 252 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
251 | port = 0; | 253 | port = 0; |
252 | else | 254 | else |
253 | { | 255 | { |
254 | port = 1371; | 256 | port = 1371; |
255 | if (oneone) | 257 | if (oneone) |
256 | port += 10; | 258 | port += 10; |
257 | } | 259 | } |
258 | 260 | ||
259 | cbc.buf = buf; | 261 | cbc.buf = buf; |
260 | cbc.size = 2048; | 262 | cbc.size = 2048; |
261 | cbc.pos = 0; | 263 | cbc.pos = 0; |
262 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 264 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
265 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
263 | port, NULL, NULL, &ahc_echo, NULL, | 266 | port, NULL, NULL, &ahc_echo, NULL, |
264 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, | 267 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, |
265 | MHD_OPTION_END); | 268 | MHD_OPTION_END); |
266 | if (d == NULL) | 269 | if (d == NULL) |
267 | return 16; | 270 | return 16; |
268 | if (0 == port) | 271 | if (0 == port) |
272 | { | ||
273 | const union MHD_DaemonInfo *dinfo; | ||
274 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
275 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
269 | { | 276 | { |
270 | const union MHD_DaemonInfo *dinfo; | 277 | MHD_stop_daemon (d); return 32; |
271 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
272 | if (NULL == dinfo || 0 == dinfo->port) | ||
273 | { MHD_stop_daemon (d); return 32; } | ||
274 | port = (int)dinfo->port; | ||
275 | } | 278 | } |
279 | port = (int) dinfo->port; | ||
280 | } | ||
276 | c = curl_easy_init (); | 281 | c = curl_easy_init (); |
277 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 282 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
278 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 283 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
279 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 284 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
280 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 285 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
281 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 286 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
@@ -293,14 +298,14 @@ testMultithreadedPost () | |||
293 | * crashes on my system! */ | 298 | * crashes on my system! */ |
294 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 299 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
295 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 300 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
296 | { | 301 | { |
297 | fprintf (stderr, | 302 | fprintf (stderr, |
298 | "curl_easy_perform failed: `%s'\n", | 303 | "curl_easy_perform failed: `%s'\n", |
299 | curl_easy_strerror (errornum)); | 304 | curl_easy_strerror (errornum)); |
300 | curl_easy_cleanup (c); | 305 | curl_easy_cleanup (c); |
301 | MHD_stop_daemon (d); | 306 | MHD_stop_daemon (d); |
302 | return 32; | 307 | return 32; |
303 | } | 308 | } |
304 | curl_easy_cleanup (c); | 309 | curl_easy_cleanup (c); |
305 | MHD_stop_daemon (d); | 310 | MHD_stop_daemon (d); |
306 | if (cbc.pos != strlen ("/hello_world")) | 311 | if (cbc.pos != strlen ("/hello_world")) |
@@ -323,11 +328,11 @@ testMultithreadedPoolPost () | |||
323 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 328 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
324 | port = 0; | 329 | port = 0; |
325 | else | 330 | else |
326 | { | 331 | { |
327 | port = 1372; | 332 | port = 1372; |
328 | if (oneone) | 333 | if (oneone) |
329 | port += 10; | 334 | port += 10; |
330 | } | 335 | } |
331 | 336 | ||
332 | cbc.buf = buf; | 337 | cbc.buf = buf; |
333 | cbc.size = 2048; | 338 | cbc.size = 2048; |
@@ -335,21 +340,23 @@ testMultithreadedPoolPost () | |||
335 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 340 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
336 | port, NULL, NULL, &ahc_echo, NULL, | 341 | port, NULL, NULL, &ahc_echo, NULL, |
337 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, | 342 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, |
338 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, | 343 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, |
339 | MHD_OPTION_END); | 344 | MHD_OPTION_END); |
340 | if (d == NULL) | 345 | if (d == NULL) |
341 | return 16; | 346 | return 16; |
342 | if (0 == port) | 347 | if (0 == port) |
348 | { | ||
349 | const union MHD_DaemonInfo *dinfo; | ||
350 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
351 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
343 | { | 352 | { |
344 | const union MHD_DaemonInfo *dinfo; | 353 | MHD_stop_daemon (d); return 32; |
345 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
346 | if (NULL == dinfo || 0 == dinfo->port) | ||
347 | { MHD_stop_daemon (d); return 32; } | ||
348 | port = (int)dinfo->port; | ||
349 | } | 354 | } |
355 | port = (int) dinfo->port; | ||
356 | } | ||
350 | c = curl_easy_init (); | 357 | c = curl_easy_init (); |
351 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 358 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
352 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 359 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
353 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 360 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
354 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 361 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
355 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 362 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
@@ -367,14 +374,14 @@ testMultithreadedPoolPost () | |||
367 | * crashes on my system! */ | 374 | * crashes on my system! */ |
368 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 375 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
369 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 376 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
370 | { | 377 | { |
371 | fprintf (stderr, | 378 | fprintf (stderr, |
372 | "curl_easy_perform failed: `%s'\n", | 379 | "curl_easy_perform failed: `%s'\n", |
373 | curl_easy_strerror (errornum)); | 380 | curl_easy_strerror (errornum)); |
374 | curl_easy_cleanup (c); | 381 | curl_easy_cleanup (c); |
375 | MHD_stop_daemon (d); | 382 | MHD_stop_daemon (d); |
376 | return 32; | 383 | return 32; |
377 | } | 384 | } |
378 | curl_easy_cleanup (c); | 385 | curl_easy_cleanup (c); |
379 | MHD_stop_daemon (d); | 386 | MHD_stop_daemon (d); |
380 | if (cbc.pos != strlen ("/hello_world")) | 387 | if (cbc.pos != strlen ("/hello_world")) |
@@ -411,11 +418,11 @@ testExternalPost () | |||
411 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 418 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
412 | port = 0; | 419 | port = 0; |
413 | else | 420 | else |
414 | { | 421 | { |
415 | port = 1373; | 422 | port = 1373; |
416 | if (oneone) | 423 | if (oneone) |
417 | port += 10; | 424 | port += 10; |
418 | } | 425 | } |
419 | 426 | ||
420 | multi = NULL; | 427 | multi = NULL; |
421 | cbc.buf = buf; | 428 | cbc.buf = buf; |
@@ -423,21 +430,23 @@ testExternalPost () | |||
423 | cbc.pos = 0; | 430 | cbc.pos = 0; |
424 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, | 431 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, |
425 | port, NULL, NULL, &ahc_echo, NULL, | 432 | port, NULL, NULL, &ahc_echo, NULL, |
426 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, | 433 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, |
427 | MHD_OPTION_END); | 434 | MHD_OPTION_END); |
428 | if (d == NULL) | 435 | if (d == NULL) |
429 | return 256; | 436 | return 256; |
430 | if (0 == port) | 437 | if (0 == port) |
438 | { | ||
439 | const union MHD_DaemonInfo *dinfo; | ||
440 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
441 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
431 | { | 442 | { |
432 | const union MHD_DaemonInfo *dinfo; | 443 | MHD_stop_daemon (d); return 32; |
433 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
434 | if (NULL == dinfo || 0 == dinfo->port) | ||
435 | { MHD_stop_daemon (d); return 32; } | ||
436 | port = (int)dinfo->port; | ||
437 | } | 444 | } |
445 | port = (int) dinfo->port; | ||
446 | } | ||
438 | c = curl_easy_init (); | 447 | c = curl_easy_init (); |
439 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 448 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
440 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 449 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
441 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 450 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
442 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 451 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
443 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 452 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
@@ -458,85 +467,88 @@ testExternalPost () | |||
458 | 467 | ||
459 | multi = curl_multi_init (); | 468 | multi = curl_multi_init (); |
460 | if (multi == NULL) | 469 | if (multi == NULL) |
470 | { | ||
471 | curl_easy_cleanup (c); | ||
472 | MHD_stop_daemon (d); | ||
473 | return 512; | ||
474 | } | ||
475 | mret = curl_multi_add_handle (multi, c); | ||
476 | if (mret != CURLM_OK) | ||
477 | { | ||
478 | curl_multi_cleanup (multi); | ||
479 | curl_easy_cleanup (c); | ||
480 | MHD_stop_daemon (d); | ||
481 | return 1024; | ||
482 | } | ||
483 | start = time (NULL); | ||
484 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
485 | { | ||
486 | maxsock = MHD_INVALID_SOCKET; | ||
487 | maxposixs = -1; | ||
488 | FD_ZERO (&rs); | ||
489 | FD_ZERO (&ws); | ||
490 | FD_ZERO (&es); | ||
491 | curl_multi_perform (multi, &running); | ||
492 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
493 | if (mret != CURLM_OK) | ||
461 | { | 494 | { |
495 | curl_multi_remove_handle (multi, c); | ||
496 | curl_multi_cleanup (multi); | ||
462 | curl_easy_cleanup (c); | 497 | curl_easy_cleanup (c); |
463 | MHD_stop_daemon (d); | 498 | MHD_stop_daemon (d); |
464 | return 512; | 499 | return 2048; |
465 | } | 500 | } |
466 | mret = curl_multi_add_handle (multi, c); | 501 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
467 | if (mret != CURLM_OK) | ||
468 | { | 502 | { |
503 | curl_multi_remove_handle (multi, c); | ||
469 | curl_multi_cleanup (multi); | 504 | curl_multi_cleanup (multi); |
470 | curl_easy_cleanup (c); | 505 | curl_easy_cleanup (c); |
471 | MHD_stop_daemon (d); | 506 | MHD_stop_daemon (d); |
472 | return 1024; | 507 | return 4096; |
473 | } | 508 | } |
474 | start = time (NULL); | 509 | tv.tv_sec = 0; |
475 | while ((time (NULL) - start < 5) && (multi != NULL)) | 510 | tv.tv_usec = 1000; |
511 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
476 | { | 512 | { |
477 | maxsock = MHD_INVALID_SOCKET; | ||
478 | maxposixs = -1; | ||
479 | FD_ZERO (&rs); | ||
480 | FD_ZERO (&ws); | ||
481 | FD_ZERO (&es); | ||
482 | curl_multi_perform (multi, &running); | ||
483 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
484 | if (mret != CURLM_OK) | ||
485 | { | ||
486 | curl_multi_remove_handle (multi, c); | ||
487 | curl_multi_cleanup (multi); | ||
488 | curl_easy_cleanup (c); | ||
489 | MHD_stop_daemon (d); | ||
490 | return 2048; | ||
491 | } | ||
492 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
493 | { | ||
494 | curl_multi_remove_handle (multi, c); | ||
495 | curl_multi_cleanup (multi); | ||
496 | curl_easy_cleanup (c); | ||
497 | MHD_stop_daemon (d); | ||
498 | return 4096; | ||
499 | } | ||
500 | tv.tv_sec = 0; | ||
501 | tv.tv_usec = 1000; | ||
502 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
503 | { | ||
504 | #ifdef MHD_POSIX_SOCKETS | 513 | #ifdef MHD_POSIX_SOCKETS |
505 | if (EINTR != errno) | 514 | if (EINTR != errno) |
506 | abort (); | 515 | abort (); |
507 | #else | 516 | #else |
508 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 517 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
509 | abort (); | 518 | ws.fd_count) |
510 | Sleep (1000); | 519 | ||(0 != es.fd_count) ) |
520 | abort (); | ||
521 | Sleep (1000); | ||
511 | #endif | 522 | #endif |
512 | } | ||
513 | curl_multi_perform (multi, &running); | ||
514 | if (running == 0) | ||
515 | { | ||
516 | msg = curl_multi_info_read (multi, &running); | ||
517 | if (msg == NULL) | ||
518 | break; | ||
519 | if (msg->msg == CURLMSG_DONE) | ||
520 | { | ||
521 | if (msg->data.result != CURLE_OK) | ||
522 | printf ("%s failed at %s:%d: `%s'\n", | ||
523 | "curl_multi_perform", | ||
524 | __FILE__, | ||
525 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
526 | curl_multi_remove_handle (multi, c); | ||
527 | curl_multi_cleanup (multi); | ||
528 | curl_easy_cleanup (c); | ||
529 | c = NULL; | ||
530 | multi = NULL; | ||
531 | } | ||
532 | } MHD_run (d); | ||
533 | } | 523 | } |
534 | if (multi != NULL) | 524 | curl_multi_perform (multi, &running); |
525 | if (running == 0) | ||
535 | { | 526 | { |
536 | curl_multi_remove_handle (multi, c); | 527 | msg = curl_multi_info_read (multi, &running); |
537 | curl_easy_cleanup (c); | 528 | if (msg == NULL) |
538 | curl_multi_cleanup (multi); | 529 | break; |
530 | if (msg->msg == CURLMSG_DONE) | ||
531 | { | ||
532 | if (msg->data.result != CURLE_OK) | ||
533 | printf ("%s failed at %s:%d: `%s'\n", | ||
534 | "curl_multi_perform", | ||
535 | __FILE__, | ||
536 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
537 | curl_multi_remove_handle (multi, c); | ||
538 | curl_multi_cleanup (multi); | ||
539 | curl_easy_cleanup (c); | ||
540 | c = NULL; | ||
541 | multi = NULL; | ||
542 | } | ||
539 | } | 543 | } |
544 | MHD_run (d); | ||
545 | } | ||
546 | if (multi != NULL) | ||
547 | { | ||
548 | curl_multi_remove_handle (multi, c); | ||
549 | curl_easy_cleanup (c); | ||
550 | curl_multi_cleanup (multi); | ||
551 | } | ||
540 | MHD_stop_daemon (d); | 552 | MHD_stop_daemon (d); |
541 | if (cbc.pos != strlen ("/hello_world")) | 553 | if (cbc.pos != strlen ("/hello_world")) |
542 | return 8192; | 554 | return 8192; |
@@ -548,43 +560,43 @@ testExternalPost () | |||
548 | 560 | ||
549 | static int | 561 | static int |
550 | ahc_cancel (void *cls, | 562 | ahc_cancel (void *cls, |
551 | struct MHD_Connection *connection, | 563 | struct MHD_Connection *connection, |
552 | const char *url, | 564 | const char *url, |
553 | const char *method, | 565 | const char *method, |
554 | const char *version, | 566 | const char *version, |
555 | const char *upload_data, size_t *upload_data_size, | 567 | const char *upload_data, size_t *upload_data_size, |
556 | void **unused) | 568 | void **unused) |
557 | { | 569 | { |
558 | struct MHD_Response *response; | 570 | struct MHD_Response *response; |
559 | int ret; | 571 | int ret; |
560 | (void)cls;(void)url;(void)version; /* Unused. Silent compiler warning. */ | 572 | (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */ |
561 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 573 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
562 | 574 | ||
563 | if (0 != strcasecmp ("POST", method)) | 575 | if (0 != strcasecmp ("POST", method)) |
564 | { | 576 | { |
565 | fprintf (stderr, | 577 | fprintf (stderr, |
566 | "Unexpected method `%s'\n", method); | 578 | "Unexpected method `%s'\n", method); |
567 | return MHD_NO; | 579 | return MHD_NO; |
568 | } | 580 | } |
569 | 581 | ||
570 | if (*unused == NULL) | 582 | if (*unused == NULL) |
571 | { | 583 | { |
572 | *unused = "wibble"; | 584 | *unused = "wibble"; |
573 | /* We don't want the body. Send a 500. */ | 585 | /* We don't want the body. Send a 500. */ |
574 | response = MHD_create_response_from_buffer (0, NULL, | 586 | response = MHD_create_response_from_buffer (0, NULL, |
575 | MHD_RESPMEM_PERSISTENT); | 587 | MHD_RESPMEM_PERSISTENT); |
576 | ret = MHD_queue_response(connection, 500, response); | 588 | ret = MHD_queue_response (connection, 500, response); |
577 | if (ret != MHD_YES) | 589 | if (ret != MHD_YES) |
578 | fprintf(stderr, "Failed to queue response\n"); | 590 | fprintf (stderr, "Failed to queue response\n"); |
579 | MHD_destroy_response(response); | 591 | MHD_destroy_response (response); |
580 | return ret; | 592 | return ret; |
581 | } | 593 | } |
582 | else | 594 | else |
583 | { | 595 | { |
584 | fprintf(stderr, | 596 | fprintf (stderr, |
585 | "In ahc_cancel again. This should not happen.\n"); | 597 | "In ahc_cancel again. This should not happen.\n"); |
586 | return MHD_NO; | 598 | return MHD_NO; |
587 | } | 599 | } |
588 | } | 600 | } |
589 | 601 | ||
590 | struct CRBC | 602 | struct CRBC |
@@ -596,7 +608,7 @@ struct CRBC | |||
596 | 608 | ||
597 | 609 | ||
598 | static size_t | 610 | static size_t |
599 | readBuffer(void *p, size_t size, size_t nmemb, void *opaque) | 611 | readBuffer (void *p, size_t size, size_t nmemb, void *opaque) |
600 | { | 612 | { |
601 | struct CRBC *data = opaque; | 613 | struct CRBC *data = opaque; |
602 | size_t required = size * nmemb; | 614 | size_t required = size * nmemb; |
@@ -605,18 +617,18 @@ readBuffer(void *p, size_t size, size_t nmemb, void *opaque) | |||
605 | if (required > left) | 617 | if (required > left) |
606 | required = left; | 618 | required = left; |
607 | 619 | ||
608 | memcpy(p, data->buffer + data->pos, required); | 620 | memcpy (p, data->buffer + data->pos, required); |
609 | data->pos += required; | 621 | data->pos += required; |
610 | 622 | ||
611 | return required/size; | 623 | return required / size; |
612 | } | 624 | } |
613 | 625 | ||
614 | 626 | ||
615 | static size_t | 627 | static size_t |
616 | slowReadBuffer(void *p, size_t size, size_t nmemb, void *opaque) | 628 | slowReadBuffer (void *p, size_t size, size_t nmemb, void *opaque) |
617 | { | 629 | { |
618 | (void)sleep(1); | 630 | (void) sleep (1); |
619 | return readBuffer(p, size, nmemb, opaque); | 631 | return readBuffer (p, size, nmemb, opaque); |
620 | } | 632 | } |
621 | 633 | ||
622 | 634 | ||
@@ -628,7 +640,7 @@ slowReadBuffer(void *p, size_t size, size_t nmemb, void *opaque) | |||
628 | 640 | ||
629 | 641 | ||
630 | static int | 642 | static int |
631 | testMultithreadedPostCancelPart(int flags) | 643 | testMultithreadedPostCancelPart (int flags) |
632 | { | 644 | { |
633 | struct MHD_Daemon *d; | 645 | struct MHD_Daemon *d; |
634 | CURL *c; | 646 | CURL *c; |
@@ -645,44 +657,48 @@ testMultithreadedPostCancelPart(int flags) | |||
645 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 657 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
646 | port = 0; | 658 | port = 0; |
647 | else | 659 | else |
648 | { | 660 | { |
649 | port = 1374; | 661 | port = 1374; |
650 | if (oneone) | 662 | if (oneone) |
651 | port += 10; | 663 | port += 10; |
652 | } | 664 | } |
653 | 665 | ||
654 | /* Don't test features that aren't available with HTTP/1.0 in | 666 | /* Don't test features that aren't available with HTTP/1.0 in |
655 | * HTTP/1.0 mode. */ | 667 | * HTTP/1.0 mode. */ |
656 | if (!oneone && (flags & (FLAG_EXPECT_CONTINUE | FLAG_CHUNKED))) | 668 | if (! oneone && (flags & (FLAG_EXPECT_CONTINUE | FLAG_CHUNKED))) |
657 | return 0; | 669 | return 0; |
658 | 670 | ||
659 | cbc.buf = buf; | 671 | cbc.buf = buf; |
660 | cbc.size = 2048; | 672 | cbc.size = 2048; |
661 | cbc.pos = 0; | 673 | cbc.pos = 0; |
662 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 674 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
675 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
663 | port, NULL, NULL, &ahc_cancel, NULL, | 676 | port, NULL, NULL, &ahc_cancel, NULL, |
664 | MHD_OPTION_END); | 677 | MHD_OPTION_END); |
665 | if (d == NULL) | 678 | if (d == NULL) |
666 | return 32768; | 679 | return 32768; |
667 | if (0 == port) | 680 | if (0 == port) |
681 | { | ||
682 | const union MHD_DaemonInfo *dinfo; | ||
683 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
684 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
668 | { | 685 | { |
669 | const union MHD_DaemonInfo *dinfo; | 686 | MHD_stop_daemon (d); return 32; |
670 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
671 | if (NULL == dinfo || 0 == dinfo->port) | ||
672 | { MHD_stop_daemon (d); return 32; } | ||
673 | port = (int)dinfo->port; | ||
674 | } | 687 | } |
688 | port = (int) dinfo->port; | ||
689 | } | ||
675 | 690 | ||
676 | crbc.buffer = "Test content"; | 691 | crbc.buffer = "Test content"; |
677 | crbc.size = strlen(crbc.buffer); | 692 | crbc.size = strlen (crbc.buffer); |
678 | crbc.pos = 0; | 693 | crbc.pos = 0; |
679 | 694 | ||
680 | c = curl_easy_init (); | 695 | c = curl_easy_init (); |
681 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 696 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
682 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 697 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
683 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 698 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
684 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 699 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
685 | curl_easy_setopt (c, CURLOPT_READFUNCTION, (flags & FLAG_SLOW_READ) ? &slowReadBuffer : &readBuffer); | 700 | curl_easy_setopt (c, CURLOPT_READFUNCTION, (flags & FLAG_SLOW_READ) ? |
701 | &slowReadBuffer : &readBuffer); | ||
686 | curl_easy_setopt (c, CURLOPT_READDATA, &crbc); | 702 | curl_easy_setopt (c, CURLOPT_READDATA, &crbc); |
687 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, NULL); | 703 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, NULL); |
688 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, crbc.size); | 704 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, crbc.size); |
@@ -700,68 +716,72 @@ testMultithreadedPostCancelPart(int flags) | |||
700 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 716 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
701 | 717 | ||
702 | if (flags & FLAG_CHUNKED) | 718 | if (flags & FLAG_CHUNKED) |
703 | headers = curl_slist_append(headers, "Transfer-Encoding: chunked"); | 719 | headers = curl_slist_append (headers, "Transfer-Encoding: chunked"); |
704 | if (!(flags & FLAG_FORM_DATA)) | 720 | if (! (flags & FLAG_FORM_DATA)) |
705 | headers = curl_slist_append(headers, "Content-Type: application/octet-stream"); | 721 | headers = curl_slist_append (headers, |
722 | "Content-Type: application/octet-stream"); | ||
706 | if (flags & FLAG_EXPECT_CONTINUE) | 723 | if (flags & FLAG_EXPECT_CONTINUE) |
707 | headers = curl_slist_append(headers, "Expect: 100-Continue"); | 724 | headers = curl_slist_append (headers, "Expect: 100-Continue"); |
708 | curl_easy_setopt(c, CURLOPT_HTTPHEADER, headers); | 725 | curl_easy_setopt (c, CURLOPT_HTTPHEADER, headers); |
709 | 726 | ||
710 | if (CURLE_HTTP_RETURNED_ERROR != (errornum = curl_easy_perform (c))) | 727 | if (CURLE_HTTP_RETURNED_ERROR != (errornum = curl_easy_perform (c))) |
711 | { | 728 | { |
712 | #ifdef _WIN32 | 729 | #ifdef _WIN32 |
713 | curl_version_info_data *curlverd = curl_version_info(CURLVERSION_NOW); | 730 | curl_version_info_data *curlverd = curl_version_info (CURLVERSION_NOW); |
714 | if (0 != (flags & FLAG_SLOW_READ) && CURLE_RECV_ERROR == errornum && | 731 | if ((0 != (flags & FLAG_SLOW_READ)) &&(CURLE_RECV_ERROR == errornum) && |
715 | (curlverd == NULL || curlverd->ares_num < 0x073100) ) | 732 | ((curlverd == NULL) ||(curlverd->ares_num < 0x073100) ) ) |
716 | { /* libcurl up to version 7.49.0 didn't have workaround for WinSock bug */ | 733 | { /* libcurl up to version 7.49.0 didn't have workaround for WinSock bug */ |
717 | fprintf (stderr, "Ignored curl_easy_perform expected failure on W32 with \"slow read\".\n"); | 734 | fprintf (stderr, |
718 | result = 0; | 735 | "Ignored curl_easy_perform expected failure on W32 with \"slow read\".\n"); |
719 | } | 736 | result = 0; |
720 | else | 737 | } |
738 | else | ||
721 | #else /* ! _WIN32 */ | 739 | #else /* ! _WIN32 */ |
722 | if(1) | 740 | if (1) |
723 | #endif /* ! _WIN32 */ | 741 | #endif /* ! _WIN32 */ |
724 | { | ||
725 | fprintf (stderr, | ||
726 | "flibbet curl_easy_perform didn't fail as expected: `%s' %d\n", | ||
727 | curl_easy_strerror (errornum), errornum); | ||
728 | result = 65536; | ||
729 | } | ||
730 | curl_easy_cleanup (c); | ||
731 | MHD_stop_daemon (d); | ||
732 | curl_slist_free_all(headers); | ||
733 | return result; | ||
734 | } | ||
735 | |||
736 | if (CURLE_OK != (cc = curl_easy_getinfo(c, CURLINFO_RESPONSE_CODE, &response_code))) | ||
737 | { | 742 | { |
738 | fprintf(stderr, "curl_easy_getinfo failed: '%s'\n", curl_easy_strerror(errornum)); | 743 | fprintf (stderr, |
744 | "flibbet curl_easy_perform didn't fail as expected: `%s' %d\n", | ||
745 | curl_easy_strerror (errornum), errornum); | ||
739 | result = 65536; | 746 | result = 65536; |
740 | } | 747 | } |
741 | 748 | curl_easy_cleanup (c); | |
742 | if (!result && (response_code != 500)) | 749 | MHD_stop_daemon (d); |
743 | { | 750 | curl_slist_free_all (headers); |
744 | fprintf(stderr, "Unexpected response code: %ld\n", response_code); | 751 | return result; |
745 | result = 131072; | 752 | } |
746 | } | 753 | |
747 | 754 | if (CURLE_OK != (cc = curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, | |
748 | if (!result && (cbc.pos != 0)) | 755 | &response_code))) |
756 | { | ||
757 | fprintf (stderr, "curl_easy_getinfo failed: '%s'\n", curl_easy_strerror ( | ||
758 | errornum)); | ||
759 | result = 65536; | ||
760 | } | ||
761 | |||
762 | if (! result && (response_code != 500)) | ||
763 | { | ||
764 | fprintf (stderr, "Unexpected response code: %ld\n", response_code); | ||
765 | result = 131072; | ||
766 | } | ||
767 | |||
768 | if (! result && (cbc.pos != 0)) | ||
749 | result = 262144; | 769 | result = 262144; |
750 | 770 | ||
751 | curl_easy_cleanup (c); | 771 | curl_easy_cleanup (c); |
752 | MHD_stop_daemon (d); | 772 | MHD_stop_daemon (d); |
753 | curl_slist_free_all(headers); | 773 | curl_slist_free_all (headers); |
754 | return result; | 774 | return result; |
755 | } | 775 | } |
756 | 776 | ||
757 | 777 | ||
758 | static int | 778 | static int |
759 | testMultithreadedPostCancel() | 779 | testMultithreadedPostCancel () |
760 | { | 780 | { |
761 | int result = 0; | 781 | int result = 0; |
762 | int flags; | 782 | int flags; |
763 | for(flags = 0; flags < FLAG_COUNT; ++flags) | 783 | for (flags = 0; flags < FLAG_COUNT; ++flags) |
764 | result |= testMultithreadedPostCancelPart(flags); | 784 | result |= testMultithreadedPostCancelPart (flags); |
765 | return result; | 785 | return result; |
766 | } | 786 | } |
767 | 787 | ||
@@ -770,20 +790,20 @@ int | |||
770 | main (int argc, char *const *argv) | 790 | main (int argc, char *const *argv) |
771 | { | 791 | { |
772 | unsigned int errorCount = 0; | 792 | unsigned int errorCount = 0; |
773 | (void)argc; /* Unused. Silent compiler warning. */ | 793 | (void) argc; /* Unused. Silent compiler warning. */ |
774 | 794 | ||
775 | if (NULL == argv || 0 == argv[0]) | 795 | if ((NULL == argv)||(0 == argv[0])) |
776 | return 99; | 796 | return 99; |
777 | oneone = has_in_name (argv[0], "11"); | 797 | oneone = has_in_name (argv[0], "11"); |
778 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 798 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
779 | return 2; | 799 | return 2; |
780 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 800 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
781 | { | 801 | { |
782 | errorCount += testMultithreadedPostCancel (); | 802 | errorCount += testMultithreadedPostCancel (); |
783 | errorCount += testInternalPost (); | 803 | errorCount += testInternalPost (); |
784 | errorCount += testMultithreadedPost (); | 804 | errorCount += testMultithreadedPost (); |
785 | errorCount += testMultithreadedPoolPost (); | 805 | errorCount += testMultithreadedPoolPost (); |
786 | } | 806 | } |
787 | errorCount += testExternalPost (); | 807 | errorCount += testExternalPost (); |
788 | if (errorCount != 0) | 808 | if (errorCount != 0) |
789 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 809 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_post_loop.c b/src/testcurl/test_post_loop.c index 6da54a95..558228a2 100644 --- a/src/testcurl/test_post_loop.c +++ b/src/testcurl/test_post_loop.c | |||
@@ -38,14 +38,15 @@ | |||
38 | #include <unistd.h> | 38 | #include <unistd.h> |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 41 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
42 | #undef CPU_COUNT | 42 | #undef CPU_COUNT |
43 | #endif | 43 | #endif |
44 | #if !defined(CPU_COUNT) | 44 | #if ! defined(CPU_COUNT) |
45 | #define CPU_COUNT 2 | 45 | #define CPU_COUNT 2 |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | #define POST_DATA "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n" | 48 | #define POST_DATA \ |
49 | "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n" | ||
49 | 50 | ||
50 | #define LOOPCOUNT 1000 | 51 | #define LOOPCOUNT 1000 |
51 | 52 | ||
@@ -82,25 +83,25 @@ ahc_echo (void *cls, | |||
82 | static int marker; | 83 | static int marker; |
83 | struct MHD_Response *response; | 84 | struct MHD_Response *response; |
84 | int ret; | 85 | int ret; |
85 | (void)cls;(void)url;(void)version; /* Unused. Silent compiler warning. */ | 86 | (void) cls; (void) url; (void) version; /* Unused. Silent compiler warning. */ |
86 | (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 87 | (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
87 | 88 | ||
88 | if (0 != strcmp ("POST", method)) | 89 | if (0 != strcmp ("POST", method)) |
89 | { | 90 | { |
90 | printf ("METHOD: %s\n", method); | 91 | printf ("METHOD: %s\n", method); |
91 | return MHD_NO; /* unexpected method */ | 92 | return MHD_NO; /* unexpected method */ |
92 | } | 93 | } |
93 | if ((*mptr != NULL) && (0 == *upload_data_size)) | 94 | if ((*mptr != NULL) && (0 == *upload_data_size)) |
94 | { | 95 | { |
95 | if (*mptr != &marker) | 96 | if (*mptr != &marker) |
96 | abort (); | 97 | abort (); |
97 | response = MHD_create_response_from_buffer (2, "OK", | 98 | response = MHD_create_response_from_buffer (2, "OK", |
98 | MHD_RESPMEM_PERSISTENT); | 99 | MHD_RESPMEM_PERSISTENT); |
99 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 100 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
100 | MHD_destroy_response (response); | 101 | MHD_destroy_response (response); |
101 | *mptr = NULL; | 102 | *mptr = NULL; |
102 | return ret; | 103 | return ret; |
103 | } | 104 | } |
104 | if (strlen (POST_DATA) != *upload_data_size) | 105 | if (strlen (POST_DATA) != *upload_data_size) |
105 | return MHD_YES; | 106 | return MHD_YES; |
106 | *upload_data_size = 0; | 107 | *upload_data_size = 0; |
@@ -124,11 +125,11 @@ testInternalPost () | |||
124 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 125 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
125 | port = 0; | 126 | port = 0; |
126 | else | 127 | else |
127 | { | 128 | { |
128 | port = 1350; | 129 | port = 1350; |
129 | if (oneone) | 130 | if (oneone) |
130 | port += 10; | 131 | port += 10; |
131 | } | 132 | } |
132 | 133 | ||
133 | cbc.buf = buf; | 134 | cbc.buf = buf; |
134 | cbc.size = 2048; | 135 | cbc.size = 2048; |
@@ -137,58 +138,60 @@ testInternalPost () | |||
137 | if (d == NULL) | 138 | if (d == NULL) |
138 | return 1; | 139 | return 1; |
139 | if (0 == port) | 140 | if (0 == port) |
141 | { | ||
142 | const union MHD_DaemonInfo *dinfo; | ||
143 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
144 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
140 | { | 145 | { |
141 | const union MHD_DaemonInfo *dinfo; | 146 | MHD_stop_daemon (d); return 32; |
142 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
143 | if (NULL == dinfo || 0 == dinfo->port) | ||
144 | { MHD_stop_daemon (d); return 32; } | ||
145 | port = (int)dinfo->port; | ||
146 | } | 147 | } |
148 | port = (int) dinfo->port; | ||
149 | } | ||
147 | for (i = 0; i < LOOPCOUNT; i++) | 150 | for (i = 0; i < LOOPCOUNT; i++) |
151 | { | ||
152 | if (99 == i % 100) | ||
153 | fprintf (stderr, "."); | ||
154 | c = curl_easy_init (); | ||
155 | cbc.pos = 0; | ||
156 | buf[0] = '\0'; | ||
157 | snprintf (url, | ||
158 | sizeof (url), | ||
159 | "http://127.0.0.1:%d/hw%d", | ||
160 | port, | ||
161 | i); | ||
162 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
163 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
164 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
165 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
166 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
167 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
168 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
169 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
170 | if (oneone) | ||
171 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
172 | else | ||
173 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
174 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
175 | /* NOTE: use of CONNECTTIMEOUT without also | ||
176 | * setting NOSIGNAL results in really weird | ||
177 | * crashes on my system! */ | ||
178 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
179 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
148 | { | 180 | { |
149 | if (99 == i % 100) | 181 | fprintf (stderr, |
150 | fprintf (stderr, "."); | 182 | "curl_easy_perform failed: `%s'\n", |
151 | c = curl_easy_init (); | 183 | curl_easy_strerror (errornum)); |
152 | cbc.pos = 0; | ||
153 | buf[0] = '\0'; | ||
154 | snprintf (url, | ||
155 | sizeof (url), | ||
156 | "http://127.0.0.1:%d/hw%d", | ||
157 | port, | ||
158 | i); | ||
159 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
160 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
161 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
162 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
163 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
164 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
165 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
166 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
167 | if (oneone) | ||
168 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
169 | else | ||
170 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
171 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
172 | /* NOTE: use of CONNECTTIMEOUT without also | ||
173 | * setting NOSIGNAL results in really weird | ||
174 | * crashes on my system! */ | ||
175 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
176 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
177 | { | ||
178 | fprintf (stderr, | ||
179 | "curl_easy_perform failed: `%s'\n", | ||
180 | curl_easy_strerror (errornum)); | ||
181 | curl_easy_cleanup (c); | ||
182 | MHD_stop_daemon (d); | ||
183 | return 2; | ||
184 | } | ||
185 | curl_easy_cleanup (c); | 184 | curl_easy_cleanup (c); |
186 | if ((buf[0] != 'O') || (buf[1] != 'K')) | 185 | MHD_stop_daemon (d); |
187 | { | 186 | return 2; |
188 | MHD_stop_daemon (d); | 187 | } |
189 | return 4; | 188 | curl_easy_cleanup (c); |
190 | } | 189 | if ((buf[0] != 'O') || (buf[1] != 'K')) |
190 | { | ||
191 | MHD_stop_daemon (d); | ||
192 | return 4; | ||
191 | } | 193 | } |
194 | } | ||
192 | MHD_stop_daemon (d); | 195 | MHD_stop_daemon (d); |
193 | if (LOOPCOUNT >= 99) | 196 | if (LOOPCOUNT >= 99) |
194 | fprintf (stderr, "\n"); | 197 | fprintf (stderr, "\n"); |
@@ -210,73 +213,76 @@ testMultithreadedPost () | |||
210 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 213 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
211 | port = 0; | 214 | port = 0; |
212 | else | 215 | else |
213 | { | 216 | { |
214 | port = 1351; | 217 | port = 1351; |
215 | if (oneone) | 218 | if (oneone) |
216 | port += 10; | 219 | port += 10; |
217 | } | 220 | } |
218 | 221 | ||
219 | cbc.buf = buf; | 222 | cbc.buf = buf; |
220 | cbc.size = 2048; | 223 | cbc.size = 2048; |
221 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 224 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
225 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
222 | port, NULL, NULL, | 226 | port, NULL, NULL, |
223 | &ahc_echo, NULL, | 227 | &ahc_echo, NULL, |
224 | MHD_OPTION_END); | 228 | MHD_OPTION_END); |
225 | if (d == NULL) | 229 | if (d == NULL) |
226 | return 16; | 230 | return 16; |
227 | if (0 == port) | 231 | if (0 == port) |
232 | { | ||
233 | const union MHD_DaemonInfo *dinfo; | ||
234 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
235 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
228 | { | 236 | { |
229 | const union MHD_DaemonInfo *dinfo; | 237 | MHD_stop_daemon (d); return 32; |
230 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
231 | if (NULL == dinfo || 0 == dinfo->port) | ||
232 | { MHD_stop_daemon (d); return 32; } | ||
233 | port = (int)dinfo->port; | ||
234 | } | 238 | } |
239 | port = (int) dinfo->port; | ||
240 | } | ||
235 | for (i = 0; i < LOOPCOUNT; i++) | 241 | for (i = 0; i < LOOPCOUNT; i++) |
242 | { | ||
243 | if (99 == i % 100) | ||
244 | fprintf (stderr, "."); | ||
245 | c = curl_easy_init (); | ||
246 | cbc.pos = 0; | ||
247 | buf[0] = '\0'; | ||
248 | snprintf (url, | ||
249 | sizeof (url), | ||
250 | "http://127.0.0.1:%d/hw%d", | ||
251 | port, | ||
252 | i); | ||
253 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
254 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
255 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
256 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
257 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
258 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
259 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
260 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
261 | if (oneone) | ||
262 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
263 | else | ||
264 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
265 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
266 | /* NOTE: use of CONNECTTIMEOUT without also | ||
267 | * setting NOSIGNAL results in really weird | ||
268 | * crashes on my system! */ | ||
269 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
270 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
236 | { | 271 | { |
237 | if (99 == i % 100) | 272 | fprintf (stderr, |
238 | fprintf (stderr, "."); | 273 | "curl_easy_perform failed: `%s'\n", |
239 | c = curl_easy_init (); | 274 | curl_easy_strerror (errornum)); |
240 | cbc.pos = 0; | ||
241 | buf[0] = '\0'; | ||
242 | snprintf (url, | ||
243 | sizeof (url), | ||
244 | "http://127.0.0.1:%d/hw%d", | ||
245 | port, | ||
246 | i); | ||
247 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
248 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
249 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
250 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
251 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
252 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
253 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
254 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
255 | if (oneone) | ||
256 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
257 | else | ||
258 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
259 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
260 | /* NOTE: use of CONNECTTIMEOUT without also | ||
261 | * setting NOSIGNAL results in really weird | ||
262 | * crashes on my system! */ | ||
263 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
264 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
265 | { | ||
266 | fprintf (stderr, | ||
267 | "curl_easy_perform failed: `%s'\n", | ||
268 | curl_easy_strerror (errornum)); | ||
269 | curl_easy_cleanup (c); | ||
270 | MHD_stop_daemon (d); | ||
271 | return 32; | ||
272 | } | ||
273 | curl_easy_cleanup (c); | 275 | curl_easy_cleanup (c); |
274 | if ((buf[0] != 'O') || (buf[1] != 'K')) | 276 | MHD_stop_daemon (d); |
275 | { | 277 | return 32; |
276 | MHD_stop_daemon (d); | 278 | } |
277 | return 64; | 279 | curl_easy_cleanup (c); |
278 | } | 280 | if ((buf[0] != 'O') || (buf[1] != 'K')) |
281 | { | ||
282 | MHD_stop_daemon (d); | ||
283 | return 64; | ||
279 | } | 284 | } |
285 | } | ||
280 | MHD_stop_daemon (d); | 286 | MHD_stop_daemon (d); |
281 | if (LOOPCOUNT >= 99) | 287 | if (LOOPCOUNT >= 99) |
282 | fprintf (stderr, "\n"); | 288 | fprintf (stderr, "\n"); |
@@ -298,11 +304,11 @@ testMultithreadedPoolPost () | |||
298 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 304 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
299 | port = 0; | 305 | port = 0; |
300 | else | 306 | else |
301 | { | 307 | { |
302 | port = 1352; | 308 | port = 1352; |
303 | if (oneone) | 309 | if (oneone) |
304 | port += 10; | 310 | port += 10; |
305 | } | 311 | } |
306 | 312 | ||
307 | cbc.buf = buf; | 313 | cbc.buf = buf; |
308 | cbc.size = 2048; | 314 | cbc.size = 2048; |
@@ -312,58 +318,60 @@ testMultithreadedPoolPost () | |||
312 | if (d == NULL) | 318 | if (d == NULL) |
313 | return 16; | 319 | return 16; |
314 | if (0 == port) | 320 | if (0 == port) |
321 | { | ||
322 | const union MHD_DaemonInfo *dinfo; | ||
323 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
324 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
315 | { | 325 | { |
316 | const union MHD_DaemonInfo *dinfo; | 326 | MHD_stop_daemon (d); return 32; |
317 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
318 | if (NULL == dinfo || 0 == dinfo->port) | ||
319 | { MHD_stop_daemon (d); return 32; } | ||
320 | port = (int)dinfo->port; | ||
321 | } | 327 | } |
328 | port = (int) dinfo->port; | ||
329 | } | ||
322 | for (i = 0; i < LOOPCOUNT; i++) | 330 | for (i = 0; i < LOOPCOUNT; i++) |
331 | { | ||
332 | if (99 == i % 100) | ||
333 | fprintf (stderr, "."); | ||
334 | c = curl_easy_init (); | ||
335 | cbc.pos = 0; | ||
336 | buf[0] = '\0'; | ||
337 | snprintf (url, | ||
338 | sizeof (url), | ||
339 | "http://127.0.0.1:%d/hw%d", | ||
340 | port, | ||
341 | i); | ||
342 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
343 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
344 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
345 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
346 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
347 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
348 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
349 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
350 | if (oneone) | ||
351 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
352 | else | ||
353 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
354 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
355 | /* NOTE: use of CONNECTTIMEOUT without also | ||
356 | * setting NOSIGNAL results in really weird | ||
357 | * crashes on my system! */ | ||
358 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
359 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
323 | { | 360 | { |
324 | if (99 == i % 100) | 361 | fprintf (stderr, |
325 | fprintf (stderr, "."); | 362 | "curl_easy_perform failed: `%s'\n", |
326 | c = curl_easy_init (); | 363 | curl_easy_strerror (errornum)); |
327 | cbc.pos = 0; | ||
328 | buf[0] = '\0'; | ||
329 | snprintf (url, | ||
330 | sizeof (url), | ||
331 | "http://127.0.0.1:%d/hw%d", | ||
332 | port, | ||
333 | i); | ||
334 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
335 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
336 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
337 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
338 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
339 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
340 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
341 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
342 | if (oneone) | ||
343 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
344 | else | ||
345 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
346 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
347 | /* NOTE: use of CONNECTTIMEOUT without also | ||
348 | * setting NOSIGNAL results in really weird | ||
349 | * crashes on my system! */ | ||
350 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
351 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
352 | { | ||
353 | fprintf (stderr, | ||
354 | "curl_easy_perform failed: `%s'\n", | ||
355 | curl_easy_strerror (errornum)); | ||
356 | curl_easy_cleanup (c); | ||
357 | MHD_stop_daemon (d); | ||
358 | return 32; | ||
359 | } | ||
360 | curl_easy_cleanup (c); | 364 | curl_easy_cleanup (c); |
361 | if ((buf[0] != 'O') || (buf[1] != 'K')) | 365 | MHD_stop_daemon (d); |
362 | { | 366 | return 32; |
363 | MHD_stop_daemon (d); | 367 | } |
364 | return 64; | 368 | curl_easy_cleanup (c); |
365 | } | 369 | if ((buf[0] != 'O') || (buf[1] != 'K')) |
370 | { | ||
371 | MHD_stop_daemon (d); | ||
372 | return 64; | ||
366 | } | 373 | } |
374 | } | ||
367 | MHD_stop_daemon (d); | 375 | MHD_stop_daemon (d); |
368 | if (LOOPCOUNT >= 99) | 376 | if (LOOPCOUNT >= 99) |
369 | fprintf (stderr, "\n"); | 377 | fprintf (stderr, "\n"); |
@@ -401,11 +409,11 @@ testExternalPost () | |||
401 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 409 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
402 | port = 0; | 410 | port = 0; |
403 | else | 411 | else |
404 | { | 412 | { |
405 | port = 1353; | 413 | port = 1353; |
406 | if (oneone) | 414 | if (oneone) |
407 | port += 10; | 415 | port += 10; |
408 | } | 416 | } |
409 | 417 | ||
410 | multi = NULL; | 418 | multi = NULL; |
411 | cbc.buf = buf; | 419 | cbc.buf = buf; |
@@ -416,134 +424,138 @@ testExternalPost () | |||
416 | if (d == NULL) | 424 | if (d == NULL) |
417 | return 256; | 425 | return 256; |
418 | if (0 == port) | 426 | if (0 == port) |
427 | { | ||
428 | const union MHD_DaemonInfo *dinfo; | ||
429 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
430 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
419 | { | 431 | { |
420 | const union MHD_DaemonInfo *dinfo; | 432 | MHD_stop_daemon (d); return 32; |
421 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
422 | if (NULL == dinfo || 0 == dinfo->port) | ||
423 | { MHD_stop_daemon (d); return 32; } | ||
424 | port = (int)dinfo->port; | ||
425 | } | 433 | } |
434 | port = (int) dinfo->port; | ||
435 | } | ||
426 | multi = curl_multi_init (); | 436 | multi = curl_multi_init (); |
427 | if (multi == NULL) | 437 | if (multi == NULL) |
438 | { | ||
439 | MHD_stop_daemon (d); | ||
440 | return 512; | ||
441 | } | ||
442 | for (i = 0; i < LOOPCOUNT; i++) | ||
443 | { | ||
444 | if (99 == i % 100) | ||
445 | fprintf (stderr, "."); | ||
446 | c = curl_easy_init (); | ||
447 | cbc.pos = 0; | ||
448 | buf[0] = '\0'; | ||
449 | snprintf (url, | ||
450 | sizeof (url), | ||
451 | "http://127.0.0.1:%d/hw%d", | ||
452 | port, | ||
453 | i); | ||
454 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
455 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
456 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
457 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
458 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
459 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
460 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
461 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
462 | if (oneone) | ||
463 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
464 | else | ||
465 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
466 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
467 | /* NOTE: use of CONNECTTIMEOUT without also | ||
468 | * setting NOSIGNAL results in really weird | ||
469 | * crashes on my system! */ | ||
470 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
471 | mret = curl_multi_add_handle (multi, c); | ||
472 | if (mret != CURLM_OK) | ||
428 | { | 473 | { |
474 | curl_multi_cleanup (multi); | ||
475 | curl_easy_cleanup (c); | ||
429 | MHD_stop_daemon (d); | 476 | MHD_stop_daemon (d); |
430 | return 512; | 477 | return 1024; |
431 | } | 478 | } |
432 | for (i = 0; i < LOOPCOUNT; i++) | 479 | start = time (NULL); |
480 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
433 | { | 481 | { |
434 | if (99 == i % 100) | 482 | maxsock = MHD_INVALID_SOCKET; |
435 | fprintf (stderr, "."); | 483 | maxposixs = -1; |
436 | c = curl_easy_init (); | 484 | FD_ZERO (&rs); |
437 | cbc.pos = 0; | 485 | FD_ZERO (&ws); |
438 | buf[0] = '\0'; | 486 | FD_ZERO (&es); |
439 | snprintf (url, | 487 | while (CURLM_CALL_MULTI_PERFORM == |
440 | sizeof (url), | 488 | curl_multi_perform (multi, &running)) |
441 | "http://127.0.0.1:%d/hw%d", | 489 | ; |
442 | port, | 490 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); |
443 | i); | ||
444 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
445 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
446 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
447 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | ||
448 | curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA)); | ||
449 | curl_easy_setopt (c, CURLOPT_POST, 1L); | ||
450 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
451 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
452 | if (oneone) | ||
453 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
454 | else | ||
455 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
456 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
457 | /* NOTE: use of CONNECTTIMEOUT without also | ||
458 | * setting NOSIGNAL results in really weird | ||
459 | * crashes on my system! */ | ||
460 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
461 | mret = curl_multi_add_handle (multi, c); | ||
462 | if (mret != CURLM_OK) | 491 | if (mret != CURLM_OK) |
492 | { | ||
493 | curl_multi_remove_handle (multi, c); | ||
494 | curl_multi_cleanup (multi); | ||
495 | curl_easy_cleanup (c); | ||
496 | MHD_stop_daemon (d); | ||
497 | return 2048; | ||
498 | } | ||
499 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
500 | { | ||
501 | curl_multi_remove_handle (multi, c); | ||
502 | curl_multi_cleanup (multi); | ||
503 | curl_easy_cleanup (c); | ||
504 | MHD_stop_daemon (d); | ||
505 | return 4096; | ||
506 | } | ||
507 | if (MHD_NO == MHD_get_timeout (d, &timeout)) | ||
508 | timeout = 100; /* 100ms == INFTY -- CURL bug... */ | ||
509 | if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) && | ||
510 | (ctimeout < (long long) timeout) && (ctimeout >= 0)) | ||
511 | timeout = ctimeout; | ||
512 | if ( (c == NULL) || (running == 0) ) | ||
513 | timeout = 0; /* terminate quickly... */ | ||
514 | tv.tv_sec = timeout / 1000; | ||
515 | tv.tv_usec = (timeout % 1000) * 1000; | ||
516 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
517 | { | ||
518 | if (EINTR == errno) | ||
519 | continue; | ||
520 | fprintf (stderr, | ||
521 | "select failed: %s\n", | ||
522 | strerror (errno)); | ||
523 | break; | ||
524 | } | ||
525 | while (CURLM_CALL_MULTI_PERFORM == | ||
526 | curl_multi_perform (multi, &running)) | ||
527 | ; | ||
528 | if (running == 0) | ||
529 | { | ||
530 | msg = curl_multi_info_read (multi, &running); | ||
531 | if (msg == NULL) | ||
532 | break; | ||
533 | if (msg->msg == CURLMSG_DONE) | ||
463 | { | 534 | { |
464 | curl_multi_cleanup (multi); | 535 | if (msg->data.result != CURLE_OK) |
465 | curl_easy_cleanup (c); | 536 | printf ("%s failed at %s:%d: `%s'\n", |
466 | MHD_stop_daemon (d); | 537 | "curl_multi_perform", |
467 | return 1024; | 538 | __FILE__, |
468 | } | 539 | __LINE__, curl_easy_strerror (msg->data.result)); |
469 | start = time (NULL); | ||
470 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
471 | { | ||
472 | maxsock = MHD_INVALID_SOCKET; | ||
473 | maxposixs = -1; | ||
474 | FD_ZERO (&rs); | ||
475 | FD_ZERO (&ws); | ||
476 | FD_ZERO (&es); | ||
477 | while (CURLM_CALL_MULTI_PERFORM == | ||
478 | curl_multi_perform (multi, &running)); | ||
479 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
480 | if (mret != CURLM_OK) | ||
481 | { | ||
482 | curl_multi_remove_handle (multi, c); | ||
483 | curl_multi_cleanup (multi); | ||
484 | curl_easy_cleanup (c); | ||
485 | MHD_stop_daemon (d); | ||
486 | return 2048; | ||
487 | } | ||
488 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
489 | { | ||
490 | curl_multi_remove_handle (multi, c); | ||
491 | curl_multi_cleanup (multi); | ||
492 | curl_easy_cleanup (c); | ||
493 | MHD_stop_daemon (d); | ||
494 | return 4096; | ||
495 | } | ||
496 | if (MHD_NO == MHD_get_timeout (d, &timeout)) | ||
497 | timeout = 100; /* 100ms == INFTY -- CURL bug... */ | ||
498 | if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) && | ||
499 | (ctimeout < (long long)timeout) && (ctimeout >= 0)) | ||
500 | timeout = ctimeout; | ||
501 | if ( (c == NULL) || (running == 0) ) | ||
502 | timeout = 0; /* terminate quickly... */ | ||
503 | tv.tv_sec = timeout / 1000; | ||
504 | tv.tv_usec = (timeout % 1000) * 1000; | ||
505 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
506 | { | ||
507 | if (EINTR == errno) | ||
508 | continue; | ||
509 | fprintf (stderr, | ||
510 | "select failed: %s\n", | ||
511 | strerror (errno)); | ||
512 | break; | ||
513 | } | ||
514 | while (CURLM_CALL_MULTI_PERFORM == | ||
515 | curl_multi_perform (multi, &running)); | ||
516 | if (running == 0) | ||
517 | { | ||
518 | msg = curl_multi_info_read (multi, &running); | ||
519 | if (msg == NULL) | ||
520 | break; | ||
521 | if (msg->msg == CURLMSG_DONE) | ||
522 | { | ||
523 | if (msg->data.result != CURLE_OK) | ||
524 | printf ("%s failed at %s:%d: `%s'\n", | ||
525 | "curl_multi_perform", | ||
526 | __FILE__, | ||
527 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
528 | curl_multi_remove_handle (multi, c); | ||
529 | curl_easy_cleanup (c); | ||
530 | c = NULL; | ||
531 | } | ||
532 | } | ||
533 | MHD_run (d); | ||
534 | } | ||
535 | if (c != NULL) | ||
536 | { | ||
537 | curl_multi_remove_handle (multi, c); | 540 | curl_multi_remove_handle (multi, c); |
538 | curl_easy_cleanup (c); | 541 | curl_easy_cleanup (c); |
542 | c = NULL; | ||
539 | } | 543 | } |
540 | if ((buf[0] != 'O') || (buf[1] != 'K')) | 544 | } |
541 | { | 545 | MHD_run (d); |
542 | curl_multi_cleanup (multi); | ||
543 | MHD_stop_daemon (d); | ||
544 | return 8192; | ||
545 | } | ||
546 | } | 546 | } |
547 | if (c != NULL) | ||
548 | { | ||
549 | curl_multi_remove_handle (multi, c); | ||
550 | curl_easy_cleanup (c); | ||
551 | } | ||
552 | if ((buf[0] != 'O') || (buf[1] != 'K')) | ||
553 | { | ||
554 | curl_multi_cleanup (multi); | ||
555 | MHD_stop_daemon (d); | ||
556 | return 8192; | ||
557 | } | ||
558 | } | ||
547 | curl_multi_cleanup (multi); | 559 | curl_multi_cleanup (multi); |
548 | MHD_stop_daemon (d); | 560 | MHD_stop_daemon (d); |
549 | if (LOOPCOUNT >= 99) | 561 | if (LOOPCOUNT >= 99) |
@@ -569,8 +581,8 @@ now () | |||
569 | struct timeval tv; | 581 | struct timeval tv; |
570 | 582 | ||
571 | gettimeofday (&tv, NULL); | 583 | gettimeofday (&tv, NULL); |
572 | return (((unsigned long long) tv.tv_sec * 1000LL) + | 584 | return (((unsigned long long) tv.tv_sec * 1000LL) |
573 | ((unsigned long long) tv.tv_usec / 1000LL)); | 585 | + ((unsigned long long) tv.tv_usec / 1000LL)); |
574 | } | 586 | } |
575 | 587 | ||
576 | 588 | ||
@@ -578,56 +590,64 @@ int | |||
578 | main (int argc, char *const *argv) | 590 | main (int argc, char *const *argv) |
579 | { | 591 | { |
580 | unsigned int errorCount = 0; | 592 | unsigned int errorCount = 0; |
581 | (void)argc; /* Unused. Silent compiler warning. */ | 593 | (void) argc; /* Unused. Silent compiler warning. */ |
582 | 594 | ||
583 | if (NULL == argv || 0 == argv[0]) | 595 | if ((NULL == argv)||(0 == argv[0])) |
584 | return 99; | 596 | return 99; |
585 | oneone = has_in_name (argv[0], "11"); | 597 | oneone = has_in_name (argv[0], "11"); |
586 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 598 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
587 | return 2; | 599 | return 2; |
588 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 600 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
589 | { | 601 | { |
590 | start_time = now(); | 602 | start_time = now (); |
591 | errorCount += testInternalPost (); | 603 | errorCount += testInternalPost (); |
592 | fprintf (stderr, | 604 | fprintf (stderr, |
593 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", | 605 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : |
594 | "internal select", | 606 | "%s: Sequential POSTs (http/1.0) %f/s\n", |
595 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); | 607 | "internal select", |
596 | GAUGER ("internal select", | 608 | (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0)); |
597 | oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", | 609 | GAUGER ("internal select", |
598 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), | 610 | oneone ? "Sequential POSTs (http/1.1)" : |
599 | "requests/s"); | 611 | "Sequential POSTs (http/1.0)", |
600 | start_time = now(); | 612 | (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0), |
601 | errorCount += testMultithreadedPost (); | 613 | "requests/s"); |
602 | fprintf (stderr, | 614 | start_time = now (); |
603 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", | 615 | errorCount += testMultithreadedPost (); |
604 | "multithreaded post", | 616 | fprintf (stderr, |
605 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); | 617 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : |
606 | GAUGER ("Multithreaded select", | 618 | "%s: Sequential POSTs (http/1.0) %f/s\n", |
607 | oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", | 619 | "multithreaded post", |
608 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), | 620 | (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0)); |
609 | "requests/s"); | 621 | GAUGER ("Multithreaded select", |
610 | start_time = now(); | 622 | oneone ? "Sequential POSTs (http/1.1)" : |
611 | errorCount += testMultithreadedPoolPost (); | 623 | "Sequential POSTs (http/1.0)", |
612 | fprintf (stderr, | 624 | (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0), |
613 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", | 625 | "requests/s"); |
614 | "thread with pool", | 626 | start_time = now (); |
615 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); | 627 | errorCount += testMultithreadedPoolPost (); |
616 | GAUGER ("thread with pool", | 628 | fprintf (stderr, |
617 | oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", | 629 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : |
618 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), | 630 | "%s: Sequential POSTs (http/1.0) %f/s\n", |
619 | "requests/s"); | 631 | "thread with pool", |
620 | } | 632 | (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0)); |
621 | start_time = now(); | 633 | GAUGER ("thread with pool", |
634 | oneone ? "Sequential POSTs (http/1.1)" : | ||
635 | "Sequential POSTs (http/1.0)", | ||
636 | (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0), | ||
637 | "requests/s"); | ||
638 | } | ||
639 | start_time = now (); | ||
622 | errorCount += testExternalPost (); | 640 | errorCount += testExternalPost (); |
623 | fprintf (stderr, | 641 | fprintf (stderr, |
624 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", | 642 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : |
625 | "external select", | 643 | "%s: Sequential POSTs (http/1.0) %f/s\n", |
626 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); | 644 | "external select", |
645 | (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0)); | ||
627 | GAUGER ("external select", | 646 | GAUGER ("external select", |
628 | oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", | 647 | oneone ? "Sequential POSTs (http/1.1)" : |
629 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), | 648 | "Sequential POSTs (http/1.0)", |
630 | "requests/s"); | 649 | (double) 1000 * LOOPCOUNT / (now () - start_time + 1.0), |
650 | "requests/s"); | ||
631 | if (errorCount != 0) | 651 | if (errorCount != 0) |
632 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 652 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
633 | curl_global_cleanup (); | 653 | curl_global_cleanup (); |
diff --git a/src/testcurl/test_postform.c b/src/testcurl/test_postform.c index 723bde0f..c4fbd5d5 100644 --- a/src/testcurl/test_postform.c +++ b/src/testcurl/test_postform.c | |||
@@ -43,10 +43,10 @@ | |||
43 | 43 | ||
44 | #include "mhd_has_in_name.h" | 44 | #include "mhd_has_in_name.h" |
45 | 45 | ||
46 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 46 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
47 | #undef CPU_COUNT | 47 | #undef CPU_COUNT |
48 | #endif | 48 | #endif |
49 | #if !defined(CPU_COUNT) | 49 | #if ! defined(CPU_COUNT) |
50 | #define CPU_COUNT 2 | 50 | #define CPU_COUNT 2 |
51 | #endif | 51 | #endif |
52 | 52 | ||
@@ -62,12 +62,12 @@ struct CBC | |||
62 | 62 | ||
63 | static void | 63 | static void |
64 | completed_cb (void *cls, | 64 | completed_cb (void *cls, |
65 | struct MHD_Connection *connection, | 65 | struct MHD_Connection *connection, |
66 | void **con_cls, | 66 | void **con_cls, |
67 | enum MHD_RequestTerminationCode toe) | 67 | enum MHD_RequestTerminationCode toe) |
68 | { | 68 | { |
69 | struct MHD_PostProcessor *pp = *con_cls; | 69 | struct MHD_PostProcessor *pp = *con_cls; |
70 | (void)cls;(void)connection;(void)toe; /* Unused. Silent compiler warning. */ | 70 | (void) cls; (void) connection; (void) toe; /* Unused. Silent compiler warning. */ |
71 | 71 | ||
72 | if (NULL != pp) | 72 | if (NULL != pp) |
73 | MHD_destroy_post_processor (pp); | 73 | MHD_destroy_post_processor (pp); |
@@ -103,8 +103,8 @@ post_iterator (void *cls, | |||
103 | const char *value, uint64_t off, size_t size) | 103 | const char *value, uint64_t off, size_t size) |
104 | { | 104 | { |
105 | int *eok = cls; | 105 | int *eok = cls; |
106 | (void)kind;(void)filename;(void)content_type; /* Unused. Silent compiler warning. */ | 106 | (void) kind; (void) filename; (void) content_type; /* Unused. Silent compiler warning. */ |
107 | (void)transfer_encoding;(void)off; /* Unused. Silent compiler warning. */ | 107 | (void) transfer_encoding; (void) off; /* Unused. Silent compiler warning. */ |
108 | 108 | ||
109 | #if 0 | 109 | #if 0 |
110 | fprintf (stderr, "PI sees %s-%.*s\n", key, size, value); | 110 | fprintf (stderr, "PI sees %s-%.*s\n", key, size, value); |
@@ -132,34 +132,34 @@ ahc_echo (void *cls, | |||
132 | struct MHD_Response *response; | 132 | struct MHD_Response *response; |
133 | struct MHD_PostProcessor *pp; | 133 | struct MHD_PostProcessor *pp; |
134 | int ret; | 134 | int ret; |
135 | (void)cls;(void)version; /* Unused. Silent compiler warning. */ | 135 | (void) cls; (void) version; /* Unused. Silent compiler warning. */ |
136 | 136 | ||
137 | if (0 != strcmp ("POST", method)) | 137 | if (0 != strcmp ("POST", method)) |
138 | { | 138 | { |
139 | printf ("METHOD: %s\n", method); | 139 | printf ("METHOD: %s\n", method); |
140 | return MHD_NO; /* unexpected method */ | 140 | return MHD_NO; /* unexpected method */ |
141 | } | 141 | } |
142 | pp = *unused; | 142 | pp = *unused; |
143 | if (pp == NULL) | 143 | if (pp == NULL) |
144 | { | 144 | { |
145 | eok = 0; | 145 | eok = 0; |
146 | pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); | 146 | pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); |
147 | if (pp == NULL) | 147 | if (pp == NULL) |
148 | abort (); | 148 | abort (); |
149 | *unused = pp; | 149 | *unused = pp; |
150 | } | 150 | } |
151 | MHD_post_process (pp, upload_data, *upload_data_size); | 151 | MHD_post_process (pp, upload_data, *upload_data_size); |
152 | if ((eok == 3) && (0 == *upload_data_size)) | 152 | if ((eok == 3) && (0 == *upload_data_size)) |
153 | { | 153 | { |
154 | response = MHD_create_response_from_buffer (strlen (url), | 154 | response = MHD_create_response_from_buffer (strlen (url), |
155 | (void *) url, | 155 | (void *) url, |
156 | MHD_RESPMEM_MUST_COPY); | 156 | MHD_RESPMEM_MUST_COPY); |
157 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 157 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
158 | MHD_destroy_response (response); | 158 | MHD_destroy_response (response); |
159 | MHD_destroy_post_processor (pp); | 159 | MHD_destroy_post_processor (pp); |
160 | *unused = NULL; | 160 | *unused = NULL; |
161 | return ret; | 161 | return ret; |
162 | } | 162 | } |
163 | *upload_data_size = 0; | 163 | *upload_data_size = 0; |
164 | return MHD_YES; | 164 | return MHD_YES; |
165 | } | 165 | } |
@@ -192,32 +192,34 @@ testInternalPost () | |||
192 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 192 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
193 | port = 0; | 193 | port = 0; |
194 | else | 194 | else |
195 | { | 195 | { |
196 | port = 1390; | 196 | port = 1390; |
197 | if (oneone) | 197 | if (oneone) |
198 | port += 10; | 198 | port += 10; |
199 | } | 199 | } |
200 | 200 | ||
201 | cbc.buf = buf; | 201 | cbc.buf = buf; |
202 | cbc.size = 2048; | 202 | cbc.size = 2048; |
203 | cbc.pos = 0; | 203 | cbc.pos = 0; |
204 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 204 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
205 | port, NULL, NULL, &ahc_echo, NULL, | 205 | port, NULL, NULL, &ahc_echo, NULL, |
206 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, | 206 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, |
207 | MHD_OPTION_END); | 207 | MHD_OPTION_END); |
208 | if (d == NULL) | 208 | if (d == NULL) |
209 | return 1; | 209 | return 1; |
210 | if (0 == port) | 210 | if (0 == port) |
211 | { | ||
212 | const union MHD_DaemonInfo *dinfo; | ||
213 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
214 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
211 | { | 215 | { |
212 | const union MHD_DaemonInfo *dinfo; | 216 | MHD_stop_daemon (d); return 32; |
213 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
214 | if (NULL == dinfo || 0 == dinfo->port) | ||
215 | { MHD_stop_daemon (d); return 32; } | ||
216 | port = (int)dinfo->port; | ||
217 | } | 217 | } |
218 | port = (int) dinfo->port; | ||
219 | } | ||
218 | c = curl_easy_init (); | 220 | c = curl_easy_init (); |
219 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 221 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
220 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 222 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
221 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 223 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
222 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 224 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
223 | pd = make_form (); | 225 | pd = make_form (); |
@@ -234,15 +236,15 @@ testInternalPost () | |||
234 | * crashes on my system! */ | 236 | * crashes on my system! */ |
235 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 237 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
236 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 238 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
237 | { | 239 | { |
238 | fprintf (stderr, | 240 | fprintf (stderr, |
239 | "curl_easy_perform failed: `%s'\n", | 241 | "curl_easy_perform failed: `%s'\n", |
240 | curl_easy_strerror (errornum)); | 242 | curl_easy_strerror (errornum)); |
241 | curl_easy_cleanup (c); | 243 | curl_easy_cleanup (c); |
242 | curl_formfree (pd); | 244 | curl_formfree (pd); |
243 | MHD_stop_daemon (d); | 245 | MHD_stop_daemon (d); |
244 | return 2; | 246 | return 2; |
245 | } | 247 | } |
246 | curl_easy_cleanup (c); | 248 | curl_easy_cleanup (c); |
247 | curl_formfree (pd); | 249 | curl_formfree (pd); |
248 | MHD_stop_daemon (d); | 250 | MHD_stop_daemon (d); |
@@ -267,32 +269,35 @@ testMultithreadedPost () | |||
267 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 269 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
268 | port = 0; | 270 | port = 0; |
269 | else | 271 | else |
270 | { | 272 | { |
271 | port = 1390; | 273 | port = 1390; |
272 | if (oneone) | 274 | if (oneone) |
273 | port += 10; | 275 | port += 10; |
274 | } | 276 | } |
275 | 277 | ||
276 | cbc.buf = buf; | 278 | cbc.buf = buf; |
277 | cbc.size = 2048; | 279 | cbc.size = 2048; |
278 | cbc.pos = 0; | 280 | cbc.pos = 0; |
279 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 281 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
282 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
280 | port, NULL, NULL, &ahc_echo, NULL, | 283 | port, NULL, NULL, &ahc_echo, NULL, |
281 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, | 284 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, |
282 | MHD_OPTION_END); | 285 | MHD_OPTION_END); |
283 | if (d == NULL) | 286 | if (d == NULL) |
284 | return 16; | 287 | return 16; |
285 | if (0 == port) | 288 | if (0 == port) |
289 | { | ||
290 | const union MHD_DaemonInfo *dinfo; | ||
291 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
292 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
286 | { | 293 | { |
287 | const union MHD_DaemonInfo *dinfo; | 294 | MHD_stop_daemon (d); return 32; |
288 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
289 | if (NULL == dinfo || 0 == dinfo->port) | ||
290 | { MHD_stop_daemon (d); return 32; } | ||
291 | port = (int)dinfo->port; | ||
292 | } | 295 | } |
296 | port = (int) dinfo->port; | ||
297 | } | ||
293 | c = curl_easy_init (); | 298 | c = curl_easy_init (); |
294 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 299 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
295 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 300 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
296 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 301 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
297 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 302 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
298 | pd = make_form (); | 303 | pd = make_form (); |
@@ -309,15 +314,15 @@ testMultithreadedPost () | |||
309 | * crashes on my system! */ | 314 | * crashes on my system! */ |
310 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 315 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
311 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 316 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
312 | { | 317 | { |
313 | fprintf (stderr, | 318 | fprintf (stderr, |
314 | "curl_easy_perform failed: `%s'\n", | 319 | "curl_easy_perform failed: `%s'\n", |
315 | curl_easy_strerror (errornum)); | 320 | curl_easy_strerror (errornum)); |
316 | curl_easy_cleanup (c); | 321 | curl_easy_cleanup (c); |
317 | curl_formfree (pd); | 322 | curl_formfree (pd); |
318 | MHD_stop_daemon (d); | 323 | MHD_stop_daemon (d); |
319 | return 32; | 324 | return 32; |
320 | } | 325 | } |
321 | curl_easy_cleanup (c); | 326 | curl_easy_cleanup (c); |
322 | curl_formfree (pd); | 327 | curl_formfree (pd); |
323 | MHD_stop_daemon (d); | 328 | MHD_stop_daemon (d); |
@@ -342,11 +347,11 @@ testMultithreadedPoolPost () | |||
342 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 347 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
343 | port = 0; | 348 | port = 0; |
344 | else | 349 | else |
345 | { | 350 | { |
346 | port = 1391; | 351 | port = 1391; |
347 | if (oneone) | 352 | if (oneone) |
348 | port += 10; | 353 | port += 10; |
349 | } | 354 | } |
350 | 355 | ||
351 | cbc.buf = buf; | 356 | cbc.buf = buf; |
352 | cbc.size = 2048; | 357 | cbc.size = 2048; |
@@ -354,21 +359,23 @@ testMultithreadedPoolPost () | |||
354 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 359 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
355 | port, NULL, NULL, &ahc_echo, NULL, | 360 | port, NULL, NULL, &ahc_echo, NULL, |
356 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, | 361 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, |
357 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, | 362 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, |
358 | MHD_OPTION_END); | 363 | MHD_OPTION_END); |
359 | if (d == NULL) | 364 | if (d == NULL) |
360 | return 16; | 365 | return 16; |
361 | if (0 == port) | 366 | if (0 == port) |
367 | { | ||
368 | const union MHD_DaemonInfo *dinfo; | ||
369 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
370 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
362 | { | 371 | { |
363 | const union MHD_DaemonInfo *dinfo; | 372 | MHD_stop_daemon (d); return 32; |
364 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
365 | if (NULL == dinfo || 0 == dinfo->port) | ||
366 | { MHD_stop_daemon (d); return 32; } | ||
367 | port = (int)dinfo->port; | ||
368 | } | 373 | } |
374 | port = (int) dinfo->port; | ||
375 | } | ||
369 | c = curl_easy_init (); | 376 | c = curl_easy_init (); |
370 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 377 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
371 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 378 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
372 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 379 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
373 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 380 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
374 | pd = make_form (); | 381 | pd = make_form (); |
@@ -385,15 +392,15 @@ testMultithreadedPoolPost () | |||
385 | * crashes on my system! */ | 392 | * crashes on my system! */ |
386 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 393 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
387 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 394 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
388 | { | 395 | { |
389 | fprintf (stderr, | 396 | fprintf (stderr, |
390 | "curl_easy_perform failed: `%s'\n", | 397 | "curl_easy_perform failed: `%s'\n", |
391 | curl_easy_strerror (errornum)); | 398 | curl_easy_strerror (errornum)); |
392 | curl_easy_cleanup (c); | 399 | curl_easy_cleanup (c); |
393 | curl_formfree (pd); | 400 | curl_formfree (pd); |
394 | MHD_stop_daemon (d); | 401 | MHD_stop_daemon (d); |
395 | return 32; | 402 | return 32; |
396 | } | 403 | } |
397 | curl_easy_cleanup (c); | 404 | curl_easy_cleanup (c); |
398 | curl_formfree (pd); | 405 | curl_formfree (pd); |
399 | MHD_stop_daemon (d); | 406 | MHD_stop_daemon (d); |
@@ -432,11 +439,11 @@ testExternalPost () | |||
432 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 439 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
433 | port = 0; | 440 | port = 0; |
434 | else | 441 | else |
435 | { | 442 | { |
436 | port = 1392; | 443 | port = 1392; |
437 | if (oneone) | 444 | if (oneone) |
438 | port += 10; | 445 | port += 10; |
439 | } | 446 | } |
440 | 447 | ||
441 | multi = NULL; | 448 | multi = NULL; |
442 | cbc.buf = buf; | 449 | cbc.buf = buf; |
@@ -444,21 +451,23 @@ testExternalPost () | |||
444 | cbc.pos = 0; | 451 | cbc.pos = 0; |
445 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, | 452 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, |
446 | port, NULL, NULL, &ahc_echo, NULL, | 453 | port, NULL, NULL, &ahc_echo, NULL, |
447 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, | 454 | MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, |
448 | MHD_OPTION_END); | 455 | MHD_OPTION_END); |
449 | if (d == NULL) | 456 | if (d == NULL) |
450 | return 256; | 457 | return 256; |
451 | if (0 == port) | 458 | if (0 == port) |
459 | { | ||
460 | const union MHD_DaemonInfo *dinfo; | ||
461 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
462 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
452 | { | 463 | { |
453 | const union MHD_DaemonInfo *dinfo; | 464 | MHD_stop_daemon (d); return 32; |
454 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
455 | if (NULL == dinfo || 0 == dinfo->port) | ||
456 | { MHD_stop_daemon (d); return 32; } | ||
457 | port = (int)dinfo->port; | ||
458 | } | 465 | } |
466 | port = (int) dinfo->port; | ||
467 | } | ||
459 | c = curl_easy_init (); | 468 | c = curl_easy_init (); |
460 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 469 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
461 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 470 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
462 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 471 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
463 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 472 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
464 | pd = make_form (); | 473 | pd = make_form (); |
@@ -478,91 +487,93 @@ testExternalPost () | |||
478 | 487 | ||
479 | multi = curl_multi_init (); | 488 | multi = curl_multi_init (); |
480 | if (multi == NULL) | 489 | if (multi == NULL) |
490 | { | ||
491 | curl_easy_cleanup (c); | ||
492 | curl_formfree (pd); | ||
493 | MHD_stop_daemon (d); | ||
494 | return 512; | ||
495 | } | ||
496 | mret = curl_multi_add_handle (multi, c); | ||
497 | if (mret != CURLM_OK) | ||
498 | { | ||
499 | curl_multi_cleanup (multi); | ||
500 | curl_formfree (pd); | ||
501 | curl_easy_cleanup (c); | ||
502 | MHD_stop_daemon (d); | ||
503 | return 1024; | ||
504 | } | ||
505 | start = time (NULL); | ||
506 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
507 | { | ||
508 | maxsock = MHD_INVALID_SOCKET; | ||
509 | maxposixs = -1; | ||
510 | FD_ZERO (&rs); | ||
511 | FD_ZERO (&ws); | ||
512 | FD_ZERO (&es); | ||
513 | curl_multi_perform (multi, &running); | ||
514 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
515 | if (mret != CURLM_OK) | ||
481 | { | 516 | { |
517 | curl_multi_remove_handle (multi, c); | ||
518 | curl_multi_cleanup (multi); | ||
482 | curl_easy_cleanup (c); | 519 | curl_easy_cleanup (c); |
483 | curl_formfree (pd); | ||
484 | MHD_stop_daemon (d); | 520 | MHD_stop_daemon (d); |
485 | return 512; | 521 | curl_formfree (pd); |
522 | return 2048; | ||
486 | } | 523 | } |
487 | mret = curl_multi_add_handle (multi, c); | 524 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
488 | if (mret != CURLM_OK) | ||
489 | { | 525 | { |
526 | curl_multi_remove_handle (multi, c); | ||
490 | curl_multi_cleanup (multi); | 527 | curl_multi_cleanup (multi); |
491 | curl_formfree (pd); | ||
492 | curl_easy_cleanup (c); | 528 | curl_easy_cleanup (c); |
529 | curl_formfree (pd); | ||
493 | MHD_stop_daemon (d); | 530 | MHD_stop_daemon (d); |
494 | return 1024; | 531 | return 4096; |
495 | } | 532 | } |
496 | start = time (NULL); | 533 | tv.tv_sec = 0; |
497 | while ((time (NULL) - start < 5) && (multi != NULL)) | 534 | tv.tv_usec = 1000; |
535 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
498 | { | 536 | { |
499 | maxsock = MHD_INVALID_SOCKET; | ||
500 | maxposixs = -1; | ||
501 | FD_ZERO (&rs); | ||
502 | FD_ZERO (&ws); | ||
503 | FD_ZERO (&es); | ||
504 | curl_multi_perform (multi, &running); | ||
505 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
506 | if (mret != CURLM_OK) | ||
507 | { | ||
508 | curl_multi_remove_handle (multi, c); | ||
509 | curl_multi_cleanup (multi); | ||
510 | curl_easy_cleanup (c); | ||
511 | MHD_stop_daemon (d); | ||
512 | curl_formfree (pd); | ||
513 | return 2048; | ||
514 | } | ||
515 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
516 | { | ||
517 | curl_multi_remove_handle (multi, c); | ||
518 | curl_multi_cleanup (multi); | ||
519 | curl_easy_cleanup (c); | ||
520 | curl_formfree (pd); | ||
521 | MHD_stop_daemon (d); | ||
522 | return 4096; | ||
523 | } | ||
524 | tv.tv_sec = 0; | ||
525 | tv.tv_usec = 1000; | ||
526 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
527 | { | ||
528 | #ifdef MHD_POSIX_SOCKETS | 537 | #ifdef MHD_POSIX_SOCKETS |
529 | if (EINTR != errno) | 538 | if (EINTR != errno) |
530 | abort (); | 539 | abort (); |
531 | #else | 540 | #else |
532 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 541 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
533 | abort (); | 542 | ws.fd_count) |
534 | Sleep (1000); | 543 | ||(0 != es.fd_count) ) |
544 | abort (); | ||
545 | Sleep (1000); | ||
535 | #endif | 546 | #endif |
536 | } | ||
537 | curl_multi_perform (multi, &running); | ||
538 | if (running == 0) | ||
539 | { | ||
540 | msg = curl_multi_info_read (multi, &running); | ||
541 | if (msg == NULL) | ||
542 | break; | ||
543 | if (msg->msg == CURLMSG_DONE) | ||
544 | { | ||
545 | if (msg->data.result != CURLE_OK) | ||
546 | printf ("%s failed at %s:%d: `%s'\n", | ||
547 | "curl_multi_perform", | ||
548 | __FILE__, | ||
549 | __LINE__, | ||
550 | curl_easy_strerror (msg->data.result)); | ||
551 | curl_multi_remove_handle (multi, c); | ||
552 | curl_multi_cleanup (multi); | ||
553 | curl_easy_cleanup (c); | ||
554 | c = NULL; | ||
555 | multi = NULL; | ||
556 | } | ||
557 | } | ||
558 | MHD_run (d); | ||
559 | } | 547 | } |
560 | if (multi != NULL) | 548 | curl_multi_perform (multi, &running); |
549 | if (running == 0) | ||
561 | { | 550 | { |
562 | curl_multi_remove_handle (multi, c); | 551 | msg = curl_multi_info_read (multi, &running); |
563 | curl_easy_cleanup (c); | 552 | if (msg == NULL) |
564 | curl_multi_cleanup (multi); | 553 | break; |
554 | if (msg->msg == CURLMSG_DONE) | ||
555 | { | ||
556 | if (msg->data.result != CURLE_OK) | ||
557 | printf ("%s failed at %s:%d: `%s'\n", | ||
558 | "curl_multi_perform", | ||
559 | __FILE__, | ||
560 | __LINE__, | ||
561 | curl_easy_strerror (msg->data.result)); | ||
562 | curl_multi_remove_handle (multi, c); | ||
563 | curl_multi_cleanup (multi); | ||
564 | curl_easy_cleanup (c); | ||
565 | c = NULL; | ||
566 | multi = NULL; | ||
567 | } | ||
565 | } | 568 | } |
569 | MHD_run (d); | ||
570 | } | ||
571 | if (multi != NULL) | ||
572 | { | ||
573 | curl_multi_remove_handle (multi, c); | ||
574 | curl_easy_cleanup (c); | ||
575 | curl_multi_cleanup (multi); | ||
576 | } | ||
566 | curl_formfree (pd); | 577 | curl_formfree (pd); |
567 | MHD_stop_daemon (d); | 578 | MHD_stop_daemon (d); |
568 | if (cbc.pos != strlen ("/hello_world")) | 579 | if (cbc.pos != strlen ("/hello_world")) |
@@ -577,7 +588,7 @@ int | |||
577 | main (int argc, char *const *argv) | 588 | main (int argc, char *const *argv) |
578 | { | 589 | { |
579 | unsigned int errorCount = 0; | 590 | unsigned int errorCount = 0; |
580 | (void)argc; /* Unused. Silent compiler warning. */ | 591 | (void) argc; /* Unused. Silent compiler warning. */ |
581 | 592 | ||
582 | #ifdef MHD_HTTPS_REQUIRE_GRYPT | 593 | #ifdef MHD_HTTPS_REQUIRE_GRYPT |
583 | #ifdef HAVE_GCRYPT_H | 594 | #ifdef HAVE_GCRYPT_H |
@@ -587,17 +598,17 @@ main (int argc, char *const *argv) | |||
587 | #endif | 598 | #endif |
588 | #endif | 599 | #endif |
589 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ | 600 | #endif /* MHD_HTTPS_REQUIRE_GRYPT */ |
590 | if (NULL == argv || 0 == argv[0]) | 601 | if ((NULL == argv)||(0 == argv[0])) |
591 | return 99; | 602 | return 99; |
592 | oneone = has_in_name (argv[0], "11"); | 603 | oneone = has_in_name (argv[0], "11"); |
593 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 604 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
594 | return 2; | 605 | return 2; |
595 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 606 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
596 | { | 607 | { |
597 | errorCount += testInternalPost (); | 608 | errorCount += testInternalPost (); |
598 | errorCount += testMultithreadedPost (); | 609 | errorCount += testMultithreadedPost (); |
599 | errorCount += testMultithreadedPoolPost (); | 610 | errorCount += testMultithreadedPoolPost (); |
600 | } | 611 | } |
601 | errorCount += testExternalPost (); | 612 | errorCount += testExternalPost (); |
602 | if (errorCount != 0) | 613 | if (errorCount != 0) |
603 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 614 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
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, ©Buffer); | 168 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
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 | |||
273 | main (int argc, char *const *argv) | 277 | main (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)) |
diff --git a/src/testcurl/test_process_headers.c b/src/testcurl/test_process_headers.c index a1237c78..a2d7485b 100644 --- a/src/testcurl/test_process_headers.c +++ b/src/testcurl/test_process_headers.c | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | /* | 1 | /* |
3 | This file is part of libmicrohttpd | 2 | This file is part of libmicrohttpd |
4 | Copyright (C) 2007 Christian Grothoff | 3 | Copyright (C) 2007 Christian Grothoff |
@@ -38,10 +37,10 @@ | |||
38 | #include <unistd.h> | 37 | #include <unistd.h> |
39 | #endif | 38 | #endif |
40 | 39 | ||
41 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 40 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
42 | #undef CPU_COUNT | 41 | #undef CPU_COUNT |
43 | #endif | 42 | #endif |
44 | #if !defined(CPU_COUNT) | 43 | #if ! defined(CPU_COUNT) |
45 | #define CPU_COUNT 2 | 44 | #define CPU_COUNT 2 |
46 | #endif | 45 | #endif |
47 | 46 | ||
@@ -70,11 +69,12 @@ static int | |||
70 | kv_cb (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) | 69 | kv_cb (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) |
71 | { | 70 | { |
72 | if ((0 == strcmp (key, MHD_HTTP_HEADER_HOST)) && | 71 | if ((0 == strcmp (key, MHD_HTTP_HEADER_HOST)) && |
73 | (0 == strncmp (value, "127.0.0.1", strlen("127.0.0.1"))) && (kind == MHD_HEADER_KIND)) | 72 | (0 == strncmp (value, "127.0.0.1", strlen ("127.0.0.1"))) && (kind == |
74 | { | 73 | MHD_HEADER_KIND)) |
75 | *((int *) cls) = 1; | 74 | { |
76 | return MHD_NO; | 75 | *((int *) cls) = 1; |
77 | } | 76 | return MHD_NO; |
77 | } | ||
78 | return MHD_YES; | 78 | return MHD_YES; |
79 | } | 79 | } |
80 | 80 | ||
@@ -92,15 +92,15 @@ ahc_echo (void *cls, | |||
92 | struct MHD_Response *response; | 92 | struct MHD_Response *response; |
93 | int ret; | 93 | int ret; |
94 | const char *hdr; | 94 | const char *hdr; |
95 | (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 95 | (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
96 | 96 | ||
97 | if (0 != strcmp (me, method)) | 97 | if (0 != strcmp (me, method)) |
98 | return MHD_NO; /* unexpected method */ | 98 | return MHD_NO; /* unexpected method */ |
99 | if (&ptr != *unused) | 99 | if (&ptr != *unused) |
100 | { | 100 | { |
101 | *unused = &ptr; | 101 | *unused = &ptr; |
102 | return MHD_YES; | 102 | return MHD_YES; |
103 | } | 103 | } |
104 | *unused = NULL; | 104 | *unused = NULL; |
105 | ret = 0; | 105 | ret = 0; |
106 | MHD_get_connection_values (connection, MHD_HEADER_KIND, &kv_cb, &ret); | 106 | MHD_get_connection_values (connection, MHD_HEADER_KIND, &kv_cb, &ret); |
@@ -115,7 +115,7 @@ ahc_echo (void *cls, | |||
115 | abort (); | 115 | abort (); |
116 | hdr = MHD_lookup_connection_value (connection, | 116 | hdr = MHD_lookup_connection_value (connection, |
117 | MHD_HEADER_KIND, MHD_HTTP_HEADER_HOST); | 117 | MHD_HEADER_KIND, MHD_HTTP_HEADER_HOST); |
118 | if ((hdr == NULL) || (0 != strncmp (hdr, "127.0.0.1", strlen("127.0.0.1")))) | 118 | if ((hdr == NULL) || (0 != strncmp (hdr, "127.0.0.1", strlen ("127.0.0.1")))) |
119 | abort (); | 119 | abort (); |
120 | MHD_set_connection_value (connection, | 120 | MHD_set_connection_value (connection, |
121 | MHD_HEADER_KIND, "FakeHeader", "NowPresent"); | 121 | MHD_HEADER_KIND, "FakeHeader", "NowPresent"); |
@@ -125,8 +125,8 @@ ahc_echo (void *cls, | |||
125 | abort (); | 125 | abort (); |
126 | 126 | ||
127 | response = MHD_create_response_from_buffer (strlen (url), | 127 | response = MHD_create_response_from_buffer (strlen (url), |
128 | (void *) url, | 128 | (void *) url, |
129 | MHD_RESPMEM_MUST_COPY); | 129 | MHD_RESPMEM_MUST_COPY); |
130 | if (NULL == response) | 130 | if (NULL == response) |
131 | abort (); | 131 | abort (); |
132 | MHD_add_response_header (response, "MyHeader", "MyValue"); | 132 | MHD_add_response_header (response, "MyHeader", "MyValue"); |
@@ -162,11 +162,11 @@ testInternalGet () | |||
162 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 162 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
163 | port = 0; | 163 | port = 0; |
164 | else | 164 | else |
165 | { | 165 | { |
166 | port = 1420; | 166 | port = 1420; |
167 | if (oneone) | 167 | if (oneone) |
168 | port += 10; | 168 | port += 10; |
169 | } | 169 | } |
170 | 170 | ||
171 | cbc.buf = buf; | 171 | cbc.buf = buf; |
172 | cbc.size = 2048; | 172 | cbc.size = 2048; |
@@ -176,16 +176,18 @@ testInternalGet () | |||
176 | if (d == NULL) | 176 | if (d == NULL) |
177 | return 1; | 177 | return 1; |
178 | if (0 == port) | 178 | if (0 == port) |
179 | { | ||
180 | const union MHD_DaemonInfo *dinfo; | ||
181 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
182 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
179 | { | 183 | { |
180 | const union MHD_DaemonInfo *dinfo; | 184 | MHD_stop_daemon (d); return 32; |
181 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
182 | if (NULL == dinfo || 0 == dinfo->port) | ||
183 | { MHD_stop_daemon (d); return 32; } | ||
184 | port = (int)dinfo->port; | ||
185 | } | 185 | } |
186 | port = (int) dinfo->port; | ||
187 | } | ||
186 | c = curl_easy_init (); | 188 | c = curl_easy_init (); |
187 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 189 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
188 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 190 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
189 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 191 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
190 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 192 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
191 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 193 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -200,14 +202,14 @@ testInternalGet () | |||
200 | crashes on my system! */ | 202 | crashes on my system! */ |
201 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 203 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
202 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 204 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
203 | { | 205 | { |
204 | fprintf (stderr, | 206 | fprintf (stderr, |
205 | "curl_easy_perform failed: `%s'\n", | 207 | "curl_easy_perform failed: `%s'\n", |
206 | curl_easy_strerror (errornum)); | 208 | curl_easy_strerror (errornum)); |
207 | curl_easy_cleanup (c); | 209 | curl_easy_cleanup (c); |
208 | MHD_stop_daemon (d); | 210 | MHD_stop_daemon (d); |
209 | return 2; | 211 | return 2; |
210 | } | 212 | } |
211 | curl_easy_cleanup (c); | 213 | curl_easy_cleanup (c); |
212 | MHD_stop_daemon (d); | 214 | MHD_stop_daemon (d); |
213 | if (cbc.pos != strlen ("/hello_world")) | 215 | if (cbc.pos != strlen ("/hello_world")) |
@@ -230,30 +232,33 @@ testMultithreadedGet () | |||
230 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 232 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
231 | port = 0; | 233 | port = 0; |
232 | else | 234 | else |
233 | { | 235 | { |
234 | port = 1421; | 236 | port = 1421; |
235 | if (oneone) | 237 | if (oneone) |
236 | port += 10; | 238 | port += 10; |
237 | } | 239 | } |
238 | 240 | ||
239 | cbc.buf = buf; | 241 | cbc.buf = buf; |
240 | cbc.size = 2048; | 242 | cbc.size = 2048; |
241 | cbc.pos = 0; | 243 | cbc.pos = 0; |
242 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 244 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
245 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
243 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 246 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
244 | if (d == NULL) | 247 | if (d == NULL) |
245 | return 16; | 248 | return 16; |
246 | if (0 == port) | 249 | if (0 == port) |
250 | { | ||
251 | const union MHD_DaemonInfo *dinfo; | ||
252 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
253 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
247 | { | 254 | { |
248 | const union MHD_DaemonInfo *dinfo; | 255 | MHD_stop_daemon (d); return 32; |
249 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
250 | if (NULL == dinfo || 0 == dinfo->port) | ||
251 | { MHD_stop_daemon (d); return 32; } | ||
252 | port = (int)dinfo->port; | ||
253 | } | 256 | } |
257 | port = (int) dinfo->port; | ||
258 | } | ||
254 | c = curl_easy_init (); | 259 | c = curl_easy_init (); |
255 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 260 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
256 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 261 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
257 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 262 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
258 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 263 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
259 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 264 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -268,14 +273,14 @@ testMultithreadedGet () | |||
268 | crashes on my system! */ | 273 | crashes on my system! */ |
269 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 274 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
270 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 275 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
271 | { | 276 | { |
272 | fprintf (stderr, | 277 | fprintf (stderr, |
273 | "curl_easy_perform failed: `%s'\n", | 278 | "curl_easy_perform failed: `%s'\n", |
274 | curl_easy_strerror (errornum)); | 279 | curl_easy_strerror (errornum)); |
275 | curl_easy_cleanup (c); | 280 | curl_easy_cleanup (c); |
276 | MHD_stop_daemon (d); | 281 | MHD_stop_daemon (d); |
277 | return 32; | 282 | return 32; |
278 | } | 283 | } |
279 | curl_easy_cleanup (c); | 284 | curl_easy_cleanup (c); |
280 | MHD_stop_daemon (d); | 285 | MHD_stop_daemon (d); |
281 | if (cbc.pos != strlen ("/hello_world")) | 286 | if (cbc.pos != strlen ("/hello_world")) |
@@ -298,11 +303,11 @@ testMultithreadedPoolGet () | |||
298 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 303 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
299 | port = 0; | 304 | port = 0; |
300 | else | 305 | else |
301 | { | 306 | { |
302 | port = 1422; | 307 | port = 1422; |
303 | if (oneone) | 308 | if (oneone) |
304 | port += 10; | 309 | port += 10; |
305 | } | 310 | } |
306 | 311 | ||
307 | cbc.buf = buf; | 312 | cbc.buf = buf; |
308 | cbc.size = 2048; | 313 | cbc.size = 2048; |
@@ -313,16 +318,18 @@ testMultithreadedPoolGet () | |||
313 | if (d == NULL) | 318 | if (d == NULL) |
314 | return 16; | 319 | return 16; |
315 | if (0 == port) | 320 | if (0 == port) |
321 | { | ||
322 | const union MHD_DaemonInfo *dinfo; | ||
323 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
324 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
316 | { | 325 | { |
317 | const union MHD_DaemonInfo *dinfo; | 326 | MHD_stop_daemon (d); return 32; |
318 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
319 | if (NULL == dinfo || 0 == dinfo->port) | ||
320 | { MHD_stop_daemon (d); return 32; } | ||
321 | port = (int)dinfo->port; | ||
322 | } | 327 | } |
328 | port = (int) dinfo->port; | ||
329 | } | ||
323 | c = curl_easy_init (); | 330 | c = curl_easy_init (); |
324 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 331 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
325 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 332 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
326 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 333 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
327 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 334 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
328 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 335 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -337,14 +344,14 @@ testMultithreadedPoolGet () | |||
337 | crashes on my system! */ | 344 | crashes on my system! */ |
338 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 345 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
339 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 346 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
340 | { | 347 | { |
341 | fprintf (stderr, | 348 | fprintf (stderr, |
342 | "curl_easy_perform failed: `%s'\n", | 349 | "curl_easy_perform failed: `%s'\n", |
343 | curl_easy_strerror (errornum)); | 350 | curl_easy_strerror (errornum)); |
344 | curl_easy_cleanup (c); | 351 | curl_easy_cleanup (c); |
345 | MHD_stop_daemon (d); | 352 | MHD_stop_daemon (d); |
346 | return 32; | 353 | return 32; |
347 | } | 354 | } |
348 | curl_easy_cleanup (c); | 355 | curl_easy_cleanup (c); |
349 | MHD_stop_daemon (d); | 356 | MHD_stop_daemon (d); |
350 | if (cbc.pos != strlen ("/hello_world")) | 357 | if (cbc.pos != strlen ("/hello_world")) |
@@ -381,11 +388,11 @@ testExternalGet () | |||
381 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 388 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
382 | port = 0; | 389 | port = 0; |
383 | else | 390 | else |
384 | { | 391 | { |
385 | port = 1423; | 392 | port = 1423; |
386 | if (oneone) | 393 | if (oneone) |
387 | port += 10; | 394 | port += 10; |
388 | } | 395 | } |
389 | 396 | ||
390 | multi = NULL; | 397 | multi = NULL; |
391 | cbc.buf = buf; | 398 | cbc.buf = buf; |
@@ -396,16 +403,18 @@ testExternalGet () | |||
396 | if (d == NULL) | 403 | if (d == NULL) |
397 | return 256; | 404 | return 256; |
398 | if (0 == port) | 405 | if (0 == port) |
406 | { | ||
407 | const union MHD_DaemonInfo *dinfo; | ||
408 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
409 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
399 | { | 410 | { |
400 | const union MHD_DaemonInfo *dinfo; | 411 | MHD_stop_daemon (d); return 32; |
401 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
402 | if (NULL == dinfo || 0 == dinfo->port) | ||
403 | { MHD_stop_daemon (d); return 32; } | ||
404 | port = (int)dinfo->port; | ||
405 | } | 412 | } |
413 | port = (int) dinfo->port; | ||
414 | } | ||
406 | c = curl_easy_init (); | 415 | c = curl_easy_init (); |
407 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 416 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
408 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 417 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
409 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 418 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
410 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 419 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
411 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 420 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -423,86 +432,88 @@ testExternalGet () | |||
423 | 432 | ||
424 | multi = curl_multi_init (); | 433 | multi = curl_multi_init (); |
425 | if (multi == NULL) | 434 | if (multi == NULL) |
435 | { | ||
436 | curl_easy_cleanup (c); | ||
437 | MHD_stop_daemon (d); | ||
438 | return 512; | ||
439 | } | ||
440 | mret = curl_multi_add_handle (multi, c); | ||
441 | if (mret != CURLM_OK) | ||
442 | { | ||
443 | curl_multi_cleanup (multi); | ||
444 | curl_easy_cleanup (c); | ||
445 | MHD_stop_daemon (d); | ||
446 | return 1024; | ||
447 | } | ||
448 | start = time (NULL); | ||
449 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
450 | { | ||
451 | maxsock = MHD_INVALID_SOCKET; | ||
452 | maxposixs = -1; | ||
453 | FD_ZERO (&rs); | ||
454 | FD_ZERO (&ws); | ||
455 | FD_ZERO (&es); | ||
456 | curl_multi_perform (multi, &running); | ||
457 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
458 | if (mret != CURLM_OK) | ||
426 | { | 459 | { |
460 | curl_multi_remove_handle (multi, c); | ||
461 | curl_multi_cleanup (multi); | ||
427 | curl_easy_cleanup (c); | 462 | curl_easy_cleanup (c); |
428 | MHD_stop_daemon (d); | 463 | MHD_stop_daemon (d); |
429 | return 512; | 464 | return 2048; |
430 | } | 465 | } |
431 | mret = curl_multi_add_handle (multi, c); | 466 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
432 | if (mret != CURLM_OK) | ||
433 | { | 467 | { |
468 | curl_multi_remove_handle (multi, c); | ||
434 | curl_multi_cleanup (multi); | 469 | curl_multi_cleanup (multi); |
435 | curl_easy_cleanup (c); | 470 | curl_easy_cleanup (c); |
436 | MHD_stop_daemon (d); | 471 | MHD_stop_daemon (d); |
437 | return 1024; | 472 | return 4096; |
438 | } | 473 | } |
439 | start = time (NULL); | 474 | tv.tv_sec = 0; |
440 | while ((time (NULL) - start < 5) && (multi != NULL)) | 475 | tv.tv_usec = 1000; |
476 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
441 | { | 477 | { |
442 | maxsock = MHD_INVALID_SOCKET; | ||
443 | maxposixs = -1; | ||
444 | FD_ZERO (&rs); | ||
445 | FD_ZERO (&ws); | ||
446 | FD_ZERO (&es); | ||
447 | curl_multi_perform (multi, &running); | ||
448 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
449 | if (mret != CURLM_OK) | ||
450 | { | ||
451 | curl_multi_remove_handle (multi, c); | ||
452 | curl_multi_cleanup (multi); | ||
453 | curl_easy_cleanup (c); | ||
454 | MHD_stop_daemon (d); | ||
455 | return 2048; | ||
456 | } | ||
457 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
458 | { | ||
459 | curl_multi_remove_handle (multi, c); | ||
460 | curl_multi_cleanup (multi); | ||
461 | curl_easy_cleanup (c); | ||
462 | MHD_stop_daemon (d); | ||
463 | return 4096; | ||
464 | } | ||
465 | tv.tv_sec = 0; | ||
466 | tv.tv_usec = 1000; | ||
467 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
468 | { | ||
469 | #ifdef MHD_POSIX_SOCKETS | 478 | #ifdef MHD_POSIX_SOCKETS |
470 | if (EINTR != errno) | 479 | if (EINTR != errno) |
471 | abort (); | 480 | abort (); |
472 | #else | 481 | #else |
473 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 482 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
474 | abort (); | 483 | ws.fd_count) |
475 | Sleep (1000); | 484 | ||(0 != es.fd_count) ) |
485 | abort (); | ||
486 | Sleep (1000); | ||
476 | #endif | 487 | #endif |
477 | } | ||
478 | curl_multi_perform (multi, &running); | ||
479 | if (running == 0) | ||
480 | { | ||
481 | msg = curl_multi_info_read (multi, &running); | ||
482 | if (msg == NULL) | ||
483 | break; | ||
484 | if (msg->msg == CURLMSG_DONE) | ||
485 | { | ||
486 | if (msg->data.result != CURLE_OK) | ||
487 | printf ("%s failed at %s:%d: `%s'\n", | ||
488 | "curl_multi_perform", | ||
489 | __FILE__, | ||
490 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
491 | curl_multi_remove_handle (multi, c); | ||
492 | curl_multi_cleanup (multi); | ||
493 | curl_easy_cleanup (c); | ||
494 | c = NULL; | ||
495 | multi = NULL; | ||
496 | } | ||
497 | } | ||
498 | MHD_run (d); | ||
499 | } | 488 | } |
500 | if (multi != NULL) | 489 | curl_multi_perform (multi, &running); |
490 | if (running == 0) | ||
501 | { | 491 | { |
502 | curl_multi_remove_handle (multi, c); | 492 | msg = curl_multi_info_read (multi, &running); |
503 | curl_easy_cleanup (c); | 493 | if (msg == NULL) |
504 | curl_multi_cleanup (multi); | 494 | break; |
495 | if (msg->msg == CURLMSG_DONE) | ||
496 | { | ||
497 | if (msg->data.result != CURLE_OK) | ||
498 | printf ("%s failed at %s:%d: `%s'\n", | ||
499 | "curl_multi_perform", | ||
500 | __FILE__, | ||
501 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
502 | curl_multi_remove_handle (multi, c); | ||
503 | curl_multi_cleanup (multi); | ||
504 | curl_easy_cleanup (c); | ||
505 | c = NULL; | ||
506 | multi = NULL; | ||
507 | } | ||
505 | } | 508 | } |
509 | MHD_run (d); | ||
510 | } | ||
511 | if (multi != NULL) | ||
512 | { | ||
513 | curl_multi_remove_handle (multi, c); | ||
514 | curl_easy_cleanup (c); | ||
515 | curl_multi_cleanup (multi); | ||
516 | } | ||
506 | MHD_stop_daemon (d); | 517 | MHD_stop_daemon (d); |
507 | if (cbc.pos != strlen ("/hello_world")) | 518 | if (cbc.pos != strlen ("/hello_world")) |
508 | return 8192; | 519 | return 8192; |
@@ -517,17 +528,17 @@ int | |||
517 | main (int argc, char *const *argv) | 528 | main (int argc, char *const *argv) |
518 | { | 529 | { |
519 | unsigned int errorCount = 0; | 530 | unsigned int errorCount = 0; |
520 | (void)argc; /* Unused. Silent compiler warning. */ | 531 | (void) argc; /* Unused. Silent compiler warning. */ |
521 | 532 | ||
522 | if (NULL == argv || 0 == argv[0]) | 533 | if ((NULL == argv)||(0 == argv[0])) |
523 | return 99; | 534 | return 99; |
524 | oneone = has_in_name (argv[0], "11"); | 535 | oneone = has_in_name (argv[0], "11"); |
525 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 536 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
526 | { | 537 | { |
527 | errorCount += testInternalGet (); | 538 | errorCount += testInternalGet (); |
528 | errorCount += testMultithreadedGet (); | 539 | errorCount += testMultithreadedGet (); |
529 | errorCount += testMultithreadedPoolGet (); | 540 | errorCount += testMultithreadedPoolGet (); |
530 | } | 541 | } |
531 | errorCount += testExternalGet (); | 542 | errorCount += testExternalGet (); |
532 | if (errorCount != 0) | 543 | if (errorCount != 0) |
533 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 544 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_put.c b/src/testcurl/test_put.c index fd56e2b2..df399268 100644 --- a/src/testcurl/test_put.c +++ b/src/testcurl/test_put.c | |||
@@ -37,10 +37,10 @@ | |||
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 40 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
41 | #undef CPU_COUNT | 41 | #undef CPU_COUNT |
42 | #endif | 42 | #endif |
43 | #if !defined(CPU_COUNT) | 43 | #if ! defined(CPU_COUNT) |
44 | #define CPU_COUNT 2 | 44 | #define CPU_COUNT 2 |
45 | #endif | 45 | #endif |
46 | 46 | ||
@@ -91,28 +91,28 @@ ahc_echo (void *cls, | |||
91 | int *done = cls; | 91 | int *done = cls; |
92 | struct MHD_Response *response; | 92 | struct MHD_Response *response; |
93 | int ret; | 93 | int ret; |
94 | (void)version;(void)unused; /* Unused. Silent compiler warning. */ | 94 | (void) version; (void) unused; /* Unused. Silent compiler warning. */ |
95 | 95 | ||
96 | if (0 != strcasecmp ("PUT", method)) | 96 | if (0 != strcasecmp ("PUT", method)) |
97 | return MHD_NO; /* unexpected method */ | 97 | return MHD_NO; /* unexpected method */ |
98 | if ((*done) == 0) | 98 | if ((*done) == 0) |
99 | { | ||
100 | if (*upload_data_size != 8) | ||
101 | return MHD_YES; /* not yet ready */ | ||
102 | if (0 == memcmp (upload_data, "Hello123", 8)) | ||
99 | { | 103 | { |
100 | if (*upload_data_size != 8) | 104 | *upload_data_size = 0; |
101 | return MHD_YES; /* not yet ready */ | ||
102 | if (0 == memcmp (upload_data, "Hello123", 8)) | ||
103 | { | ||
104 | *upload_data_size = 0; | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | printf ("Invalid upload data `%8s'!\n", upload_data); | ||
109 | return MHD_NO; | ||
110 | } | ||
111 | *done = 1; | ||
112 | return MHD_YES; | ||
113 | } | 105 | } |
106 | else | ||
107 | { | ||
108 | printf ("Invalid upload data `%8s'!\n", upload_data); | ||
109 | return MHD_NO; | ||
110 | } | ||
111 | *done = 1; | ||
112 | return MHD_YES; | ||
113 | } | ||
114 | response = MHD_create_response_from_buffer (strlen (url), (void*) url, | 114 | response = MHD_create_response_from_buffer (strlen (url), (void*) url, |
115 | MHD_RESPMEM_MUST_COPY); | 115 | MHD_RESPMEM_MUST_COPY); |
116 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 116 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
117 | MHD_destroy_response (response); | 117 | MHD_destroy_response (response); |
118 | return ret; | 118 | return ret; |
@@ -134,11 +134,11 @@ testInternalPut () | |||
134 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 134 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
135 | port = 0; | 135 | port = 0; |
136 | else | 136 | else |
137 | { | 137 | { |
138 | port = 1450; | 138 | port = 1450; |
139 | if (oneone) | 139 | if (oneone) |
140 | port += 10; | 140 | port += 10; |
141 | } | 141 | } |
142 | 142 | ||
143 | cbc.buf = buf; | 143 | cbc.buf = buf; |
144 | cbc.size = 2048; | 144 | cbc.size = 2048; |
@@ -149,16 +149,18 @@ testInternalPut () | |||
149 | if (d == NULL) | 149 | if (d == NULL) |
150 | return 1; | 150 | return 1; |
151 | if (0 == port) | 151 | if (0 == port) |
152 | { | ||
153 | const union MHD_DaemonInfo *dinfo; | ||
154 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
155 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
152 | { | 156 | { |
153 | const union MHD_DaemonInfo *dinfo; | 157 | MHD_stop_daemon (d); return 32; |
154 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
155 | if (NULL == dinfo || 0 == dinfo->port) | ||
156 | { MHD_stop_daemon (d); return 32; } | ||
157 | port = (int)dinfo->port; | ||
158 | } | 158 | } |
159 | port = (int) dinfo->port; | ||
160 | } | ||
159 | c = curl_easy_init (); | 161 | c = curl_easy_init (); |
160 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 162 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
161 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 163 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
162 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 164 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
163 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 165 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
164 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 166 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -177,14 +179,14 @@ testInternalPut () | |||
177 | * crashes on my system! */ | 179 | * crashes on my system! */ |
178 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 180 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
179 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 181 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
180 | { | 182 | { |
181 | fprintf (stderr, | 183 | fprintf (stderr, |
182 | "curl_easy_perform failed: `%s'\n", | 184 | "curl_easy_perform failed: `%s'\n", |
183 | curl_easy_strerror (errornum)); | 185 | curl_easy_strerror (errornum)); |
184 | curl_easy_cleanup (c); | 186 | curl_easy_cleanup (c); |
185 | MHD_stop_daemon (d); | 187 | MHD_stop_daemon (d); |
186 | return 2; | 188 | return 2; |
187 | } | 189 | } |
188 | curl_easy_cleanup (c); | 190 | curl_easy_cleanup (c); |
189 | MHD_stop_daemon (d); | 191 | MHD_stop_daemon (d); |
190 | if (cbc.pos != strlen ("/hello_world")) | 192 | if (cbc.pos != strlen ("/hello_world")) |
@@ -209,31 +211,34 @@ testMultithreadedPut () | |||
209 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 211 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
210 | port = 0; | 212 | port = 0; |
211 | else | 213 | else |
212 | { | 214 | { |
213 | port = 1451; | 215 | port = 1451; |
214 | if (oneone) | 216 | if (oneone) |
215 | port += 10; | 217 | port += 10; |
216 | } | 218 | } |
217 | 219 | ||
218 | cbc.buf = buf; | 220 | cbc.buf = buf; |
219 | cbc.size = 2048; | 221 | cbc.size = 2048; |
220 | cbc.pos = 0; | 222 | cbc.pos = 0; |
221 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 223 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
224 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
222 | port, | 225 | port, |
223 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); | 226 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); |
224 | if (d == NULL) | 227 | if (d == NULL) |
225 | return 16; | 228 | return 16; |
226 | if (0 == port) | 229 | if (0 == port) |
230 | { | ||
231 | const union MHD_DaemonInfo *dinfo; | ||
232 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
233 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
227 | { | 234 | { |
228 | const union MHD_DaemonInfo *dinfo; | 235 | MHD_stop_daemon (d); return 32; |
229 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
230 | if (NULL == dinfo || 0 == dinfo->port) | ||
231 | { MHD_stop_daemon (d); return 32; } | ||
232 | port = (int)dinfo->port; | ||
233 | } | 236 | } |
237 | port = (int) dinfo->port; | ||
238 | } | ||
234 | c = curl_easy_init (); | 239 | c = curl_easy_init (); |
235 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 240 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
236 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 241 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
237 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 242 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
238 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 243 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
239 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 244 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -252,14 +257,14 @@ testMultithreadedPut () | |||
252 | * crashes on my system! */ | 257 | * crashes on my system! */ |
253 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 258 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
254 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 259 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
255 | { | 260 | { |
256 | fprintf (stderr, | 261 | fprintf (stderr, |
257 | "curl_easy_perform failed: `%s'\n", | 262 | "curl_easy_perform failed: `%s'\n", |
258 | curl_easy_strerror (errornum)); | 263 | curl_easy_strerror (errornum)); |
259 | curl_easy_cleanup (c); | 264 | curl_easy_cleanup (c); |
260 | MHD_stop_daemon (d); | 265 | MHD_stop_daemon (d); |
261 | return 32; | 266 | return 32; |
262 | } | 267 | } |
263 | curl_easy_cleanup (c); | 268 | curl_easy_cleanup (c); |
264 | MHD_stop_daemon (d); | 269 | MHD_stop_daemon (d); |
265 | if (cbc.pos != strlen ("/hello_world")) | 270 | if (cbc.pos != strlen ("/hello_world")) |
@@ -285,11 +290,11 @@ testMultithreadedPoolPut () | |||
285 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 290 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
286 | port = 0; | 291 | port = 0; |
287 | else | 292 | else |
288 | { | 293 | { |
289 | port = 1452; | 294 | port = 1452; |
290 | if (oneone) | 295 | if (oneone) |
291 | port += 10; | 296 | port += 10; |
292 | } | 297 | } |
293 | 298 | ||
294 | cbc.buf = buf; | 299 | cbc.buf = buf; |
295 | cbc.size = 2048; | 300 | cbc.size = 2048; |
@@ -301,16 +306,18 @@ testMultithreadedPoolPut () | |||
301 | if (d == NULL) | 306 | if (d == NULL) |
302 | return 16; | 307 | return 16; |
303 | if (0 == port) | 308 | if (0 == port) |
309 | { | ||
310 | const union MHD_DaemonInfo *dinfo; | ||
311 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
312 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
304 | { | 313 | { |
305 | const union MHD_DaemonInfo *dinfo; | 314 | MHD_stop_daemon (d); return 32; |
306 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
307 | if (NULL == dinfo || 0 == dinfo->port) | ||
308 | { MHD_stop_daemon (d); return 32; } | ||
309 | port = (int)dinfo->port; | ||
310 | } | 315 | } |
316 | port = (int) dinfo->port; | ||
317 | } | ||
311 | c = curl_easy_init (); | 318 | c = curl_easy_init (); |
312 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 319 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
313 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 320 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
314 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 321 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
315 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 322 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
316 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 323 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -329,14 +336,14 @@ testMultithreadedPoolPut () | |||
329 | * crashes on my system! */ | 336 | * crashes on my system! */ |
330 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 337 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
331 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 338 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
332 | { | 339 | { |
333 | fprintf (stderr, | 340 | fprintf (stderr, |
334 | "curl_easy_perform failed: `%s'\n", | 341 | "curl_easy_perform failed: `%s'\n", |
335 | curl_easy_strerror (errornum)); | 342 | curl_easy_strerror (errornum)); |
336 | curl_easy_cleanup (c); | 343 | curl_easy_cleanup (c); |
337 | MHD_stop_daemon (d); | 344 | MHD_stop_daemon (d); |
338 | return 32; | 345 | return 32; |
339 | } | 346 | } |
340 | curl_easy_cleanup (c); | 347 | curl_easy_cleanup (c); |
341 | MHD_stop_daemon (d); | 348 | MHD_stop_daemon (d); |
342 | if (cbc.pos != strlen ("/hello_world")) | 349 | if (cbc.pos != strlen ("/hello_world")) |
@@ -373,11 +380,11 @@ testExternalPut () | |||
373 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 380 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
374 | port = 0; | 381 | port = 0; |
375 | else | 382 | else |
376 | { | 383 | { |
377 | port = 1453; | 384 | port = 1453; |
378 | if (oneone) | 385 | if (oneone) |
379 | port += 10; | 386 | port += 10; |
380 | } | 387 | } |
381 | 388 | ||
382 | multi = NULL; | 389 | multi = NULL; |
383 | cbc.buf = buf; | 390 | cbc.buf = buf; |
@@ -389,17 +396,19 @@ testExternalPut () | |||
389 | if (d == NULL) | 396 | if (d == NULL) |
390 | return 256; | 397 | return 256; |
391 | if (0 == port) | 398 | if (0 == port) |
399 | { | ||
400 | const union MHD_DaemonInfo *dinfo; | ||
401 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
402 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
392 | { | 403 | { |
393 | const union MHD_DaemonInfo *dinfo; | 404 | MHD_stop_daemon (d); return 32; |
394 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
395 | if (NULL == dinfo || 0 == dinfo->port) | ||
396 | { MHD_stop_daemon (d); return 32; } | ||
397 | port = (int)dinfo->port; | ||
398 | } | 405 | } |
406 | port = (int) dinfo->port; | ||
407 | } | ||
399 | c = curl_easy_init (); | 408 | c = curl_easy_init (); |
400 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 409 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
401 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 410 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
402 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 411 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
403 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 412 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
404 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 413 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
405 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | 414 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); |
@@ -420,90 +429,92 @@ curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | |||
420 | 429 | ||
421 | multi = curl_multi_init (); | 430 | multi = curl_multi_init (); |
422 | if (multi == NULL) | 431 | if (multi == NULL) |
432 | { | ||
433 | curl_easy_cleanup (c); | ||
434 | MHD_stop_daemon (d); | ||
435 | return 512; | ||
436 | } | ||
437 | mret = curl_multi_add_handle (multi, c); | ||
438 | if (mret != CURLM_OK) | ||
439 | { | ||
440 | curl_multi_cleanup (multi); | ||
441 | curl_easy_cleanup (c); | ||
442 | MHD_stop_daemon (d); | ||
443 | return 1024; | ||
444 | } | ||
445 | start = time (NULL); | ||
446 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
447 | { | ||
448 | maxsock = MHD_INVALID_SOCKET; | ||
449 | maxposixs = -1; | ||
450 | FD_ZERO (&rs); | ||
451 | FD_ZERO (&ws); | ||
452 | FD_ZERO (&es); | ||
453 | curl_multi_perform (multi, &running); | ||
454 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
455 | if (mret != CURLM_OK) | ||
423 | { | 456 | { |
457 | curl_multi_remove_handle (multi, c); | ||
458 | curl_multi_cleanup (multi); | ||
424 | curl_easy_cleanup (c); | 459 | curl_easy_cleanup (c); |
425 | MHD_stop_daemon (d); | 460 | MHD_stop_daemon (d); |
426 | return 512; | 461 | return 2048; |
427 | } | 462 | } |
428 | mret = curl_multi_add_handle (multi, c); | 463 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
429 | if (mret != CURLM_OK) | ||
430 | { | 464 | { |
465 | curl_multi_remove_handle (multi, c); | ||
431 | curl_multi_cleanup (multi); | 466 | curl_multi_cleanup (multi); |
432 | curl_easy_cleanup (c); | 467 | curl_easy_cleanup (c); |
433 | MHD_stop_daemon (d); | 468 | MHD_stop_daemon (d); |
434 | return 1024; | 469 | return 4096; |
435 | } | 470 | } |
436 | start = time (NULL); | ||
437 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
438 | { | ||
439 | maxsock = MHD_INVALID_SOCKET; | ||
440 | maxposixs = -1; | ||
441 | FD_ZERO (&rs); | ||
442 | FD_ZERO (&ws); | ||
443 | FD_ZERO (&es); | ||
444 | curl_multi_perform (multi, &running); | ||
445 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
446 | if (mret != CURLM_OK) | ||
447 | { | ||
448 | curl_multi_remove_handle (multi, c); | ||
449 | curl_multi_cleanup (multi); | ||
450 | curl_easy_cleanup (c); | ||
451 | MHD_stop_daemon (d); | ||
452 | return 2048; | ||
453 | } | ||
454 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
455 | { | ||
456 | curl_multi_remove_handle (multi, c); | ||
457 | curl_multi_cleanup (multi); | ||
458 | curl_easy_cleanup (c); | ||
459 | MHD_stop_daemon (d); | ||
460 | return 4096; | ||
461 | } | ||
462 | #ifdef MHD_POSIX_SOCKETS | 471 | #ifdef MHD_POSIX_SOCKETS |
463 | if (maxsock > maxposixs) | 472 | if (maxsock > maxposixs) |
464 | maxposixs = maxsock; | 473 | maxposixs = maxsock; |
465 | #endif /* MHD_POSIX_SOCKETS */ | 474 | #endif /* MHD_POSIX_SOCKETS */ |
466 | tv.tv_sec = 0; | 475 | tv.tv_sec = 0; |
467 | tv.tv_usec = 1000; | 476 | tv.tv_usec = 1000; |
468 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | 477 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) |
469 | { | 478 | { |
470 | #ifdef MHD_POSIX_SOCKETS | 479 | #ifdef MHD_POSIX_SOCKETS |
471 | if (EINTR != errno) | 480 | if (EINTR != errno) |
472 | abort (); | 481 | abort (); |
473 | #else | 482 | #else |
474 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 483 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
475 | _exit (99); | 484 | ws.fd_count) |
476 | Sleep (1000); | 485 | ||(0 != es.fd_count) ) |
486 | _exit (99); | ||
487 | Sleep (1000); | ||
477 | #endif | 488 | #endif |
478 | } | ||
479 | curl_multi_perform (multi, &running); | ||
480 | if (running == 0) | ||
481 | { | ||
482 | msg = curl_multi_info_read (multi, &running); | ||
483 | if (msg == NULL) | ||
484 | break; | ||
485 | if (msg->msg == CURLMSG_DONE) | ||
486 | { | ||
487 | if (msg->data.result != CURLE_OK) | ||
488 | printf ("%s failed at %s:%d: `%s'\n", | ||
489 | "curl_multi_perform", | ||
490 | __FILE__, | ||
491 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
492 | curl_multi_remove_handle (multi, c); | ||
493 | curl_multi_cleanup (multi); | ||
494 | curl_easy_cleanup (c); | ||
495 | c = NULL; | ||
496 | multi = NULL; | ||
497 | } | ||
498 | } | ||
499 | MHD_run (d); | ||
500 | } | 489 | } |
501 | if (multi != NULL) | 490 | curl_multi_perform (multi, &running); |
491 | if (running == 0) | ||
502 | { | 492 | { |
503 | curl_multi_remove_handle (multi, c); | 493 | msg = curl_multi_info_read (multi, &running); |
504 | curl_easy_cleanup (c); | 494 | if (msg == NULL) |
505 | curl_multi_cleanup (multi); | 495 | break; |
496 | if (msg->msg == CURLMSG_DONE) | ||
497 | { | ||
498 | if (msg->data.result != CURLE_OK) | ||
499 | printf ("%s failed at %s:%d: `%s'\n", | ||
500 | "curl_multi_perform", | ||
501 | __FILE__, | ||
502 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
503 | curl_multi_remove_handle (multi, c); | ||
504 | curl_multi_cleanup (multi); | ||
505 | curl_easy_cleanup (c); | ||
506 | c = NULL; | ||
507 | multi = NULL; | ||
508 | } | ||
506 | } | 509 | } |
510 | MHD_run (d); | ||
511 | } | ||
512 | if (multi != NULL) | ||
513 | { | ||
514 | curl_multi_remove_handle (multi, c); | ||
515 | curl_easy_cleanup (c); | ||
516 | curl_multi_cleanup (multi); | ||
517 | } | ||
507 | MHD_stop_daemon (d); | 518 | MHD_stop_daemon (d); |
508 | if (cbc.pos != strlen ("/hello_world")) | 519 | if (cbc.pos != strlen ("/hello_world")) |
509 | return 8192; | 520 | return 8192; |
@@ -518,19 +529,19 @@ int | |||
518 | main (int argc, char *const *argv) | 529 | main (int argc, char *const *argv) |
519 | { | 530 | { |
520 | unsigned int errorCount = 0; | 531 | unsigned int errorCount = 0; |
521 | (void)argc; /* Unused. Silent compiler warning. */ | 532 | (void) argc; /* Unused. Silent compiler warning. */ |
522 | 533 | ||
523 | if (NULL == argv || 0 == argv[0]) | 534 | if ((NULL == argv)||(0 == argv[0])) |
524 | return 99; | 535 | return 99; |
525 | oneone = has_in_name (argv[0], "11"); | 536 | oneone = has_in_name (argv[0], "11"); |
526 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 537 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
527 | return 2; | 538 | return 2; |
528 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 539 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
529 | { | 540 | { |
530 | errorCount += testInternalPut (); | 541 | errorCount += testInternalPut (); |
531 | errorCount += testMultithreadedPut (); | 542 | errorCount += testMultithreadedPut (); |
532 | errorCount += testMultithreadedPoolPut (); | 543 | errorCount += testMultithreadedPoolPut (); |
533 | } | 544 | } |
534 | errorCount += testExternalPut (); | 545 | errorCount += testExternalPut (); |
535 | if (errorCount != 0) | 546 | if (errorCount != 0) |
536 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 547 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_put_chunked.c b/src/testcurl/test_put_chunked.c index 9f875a40..6374f4a7 100644 --- a/src/testcurl/test_put_chunked.c +++ b/src/testcurl/test_put_chunked.c | |||
@@ -37,10 +37,10 @@ | |||
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 40 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
41 | #undef CPU_COUNT | 41 | #undef CPU_COUNT |
42 | #endif | 42 | #endif |
43 | #if !defined(CPU_COUNT) | 43 | #if ! defined(CPU_COUNT) |
44 | #define CPU_COUNT 2 | 44 | #define CPU_COUNT 2 |
45 | #endif | 45 | #endif |
46 | 46 | ||
@@ -92,38 +92,38 @@ ahc_echo (void *cls, | |||
92 | struct MHD_Response *response; | 92 | struct MHD_Response *response; |
93 | int ret; | 93 | int ret; |
94 | int have; | 94 | int have; |
95 | (void)version;(void)unused; /* Unused. Silent compiler warning. */ | 95 | (void) version; (void) unused; /* Unused. Silent compiler warning. */ |
96 | 96 | ||
97 | if (0 != strcmp ("PUT", method)) | 97 | if (0 != strcmp ("PUT", method)) |
98 | return MHD_NO; /* unexpected method */ | 98 | return MHD_NO; /* unexpected method */ |
99 | if ((*done) < 8) | 99 | if ((*done) < 8) |
100 | { | ||
101 | have = *upload_data_size; | ||
102 | if (have + *done > 8) | ||
100 | { | 103 | { |
101 | have = *upload_data_size; | 104 | printf ("Invalid upload data `%8s'!\n", upload_data); |
102 | if (have + *done > 8) | 105 | return MHD_NO; |
103 | { | 106 | } |
104 | printf ("Invalid upload data `%8s'!\n", upload_data); | 107 | if (0 == have) |
105 | return MHD_NO; | ||
106 | } | ||
107 | if (0 == have) | ||
108 | return MHD_YES; | ||
109 | if (0 == memcmp (upload_data, &"Hello123"[*done], have)) | ||
110 | { | ||
111 | *done += have; | ||
112 | *upload_data_size = 0; | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | printf ("Invalid upload data `%8s'!\n", upload_data); | ||
117 | return MHD_NO; | ||
118 | } | ||
119 | #if 0 | ||
120 | fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8); | ||
121 | #endif | ||
122 | return MHD_YES; | 108 | return MHD_YES; |
109 | if (0 == memcmp (upload_data, &"Hello123"[*done], have)) | ||
110 | { | ||
111 | *done += have; | ||
112 | *upload_data_size = 0; | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | printf ("Invalid upload data `%8s'!\n", upload_data); | ||
117 | return MHD_NO; | ||
123 | } | 118 | } |
119 | #if 0 | ||
120 | fprintf (stderr, "Not ready for response: %u/%u\n", *done, 8); | ||
121 | #endif | ||
122 | return MHD_YES; | ||
123 | } | ||
124 | response = MHD_create_response_from_buffer (strlen (url), | 124 | response = MHD_create_response_from_buffer (strlen (url), |
125 | (void *) url, | 125 | (void *) url, |
126 | MHD_RESPMEM_MUST_COPY); | 126 | MHD_RESPMEM_MUST_COPY); |
127 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 127 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
128 | MHD_destroy_response (response); | 128 | MHD_destroy_response (response); |
129 | return ret; | 129 | return ret; |
@@ -156,16 +156,18 @@ testInternalPut () | |||
156 | if (d == NULL) | 156 | if (d == NULL) |
157 | return 1; | 157 | return 1; |
158 | if (0 == port) | 158 | if (0 == port) |
159 | { | ||
160 | const union MHD_DaemonInfo *dinfo; | ||
161 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
162 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
159 | { | 163 | { |
160 | const union MHD_DaemonInfo *dinfo; | 164 | MHD_stop_daemon (d); return 32; |
161 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
162 | if (NULL == dinfo || 0 == dinfo->port) | ||
163 | { MHD_stop_daemon (d); return 32; } | ||
164 | port = (int)dinfo->port; | ||
165 | } | 165 | } |
166 | port = (int) dinfo->port; | ||
167 | } | ||
166 | c = curl_easy_init (); | 168 | c = curl_easy_init (); |
167 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 169 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
168 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 170 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
169 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 171 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
170 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 172 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
171 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 173 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -184,14 +186,14 @@ testInternalPut () | |||
184 | * crashes on my system! */ | 186 | * crashes on my system! */ |
185 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 187 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
186 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 188 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
187 | { | 189 | { |
188 | fprintf (stderr, | 190 | fprintf (stderr, |
189 | "curl_easy_perform failed: `%s'\n", | 191 | "curl_easy_perform failed: `%s'\n", |
190 | curl_easy_strerror (errornum)); | 192 | curl_easy_strerror (errornum)); |
191 | curl_easy_cleanup (c); | 193 | curl_easy_cleanup (c); |
192 | MHD_stop_daemon (d); | 194 | MHD_stop_daemon (d); |
193 | return 2; | 195 | return 2; |
194 | } | 196 | } |
195 | curl_easy_cleanup (c); | 197 | curl_easy_cleanup (c); |
196 | MHD_stop_daemon (d); | 198 | MHD_stop_daemon (d); |
197 | if (cbc.pos != strlen ("/hello_world")) | 199 | if (cbc.pos != strlen ("/hello_world")) |
@@ -221,22 +223,25 @@ testMultithreadedPut () | |||
221 | cbc.buf = buf; | 223 | cbc.buf = buf; |
222 | cbc.size = 2048; | 224 | cbc.size = 2048; |
223 | cbc.pos = 0; | 225 | cbc.pos = 0; |
224 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 226 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
227 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
225 | port, | 228 | port, |
226 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); | 229 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); |
227 | if (d == NULL) | 230 | if (d == NULL) |
228 | return 16; | 231 | return 16; |
229 | if (0 == port) | 232 | if (0 == port) |
233 | { | ||
234 | const union MHD_DaemonInfo *dinfo; | ||
235 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
236 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
230 | { | 237 | { |
231 | const union MHD_DaemonInfo *dinfo; | 238 | MHD_stop_daemon (d); return 32; |
232 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
233 | if (NULL == dinfo || 0 == dinfo->port) | ||
234 | { MHD_stop_daemon (d); return 32; } | ||
235 | port = (int)dinfo->port; | ||
236 | } | 239 | } |
240 | port = (int) dinfo->port; | ||
241 | } | ||
237 | c = curl_easy_init (); | 242 | c = curl_easy_init (); |
238 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 243 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
239 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 244 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
240 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 245 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
241 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 246 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
242 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 247 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -255,14 +260,14 @@ testMultithreadedPut () | |||
255 | * crashes on my system! */ | 260 | * crashes on my system! */ |
256 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 261 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
257 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 262 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
258 | { | 263 | { |
259 | fprintf (stderr, | 264 | fprintf (stderr, |
260 | "curl_easy_perform failed: `%s'\n", | 265 | "curl_easy_perform failed: `%s'\n", |
261 | curl_easy_strerror (errornum)); | 266 | curl_easy_strerror (errornum)); |
262 | curl_easy_cleanup (c); | 267 | curl_easy_cleanup (c); |
263 | MHD_stop_daemon (d); | 268 | MHD_stop_daemon (d); |
264 | return 32; | 269 | return 32; |
265 | } | 270 | } |
266 | curl_easy_cleanup (c); | 271 | curl_easy_cleanup (c); |
267 | MHD_stop_daemon (d); | 272 | MHD_stop_daemon (d); |
268 | if (cbc.pos != strlen ("/hello_world")) | 273 | if (cbc.pos != strlen ("/hello_world")) |
@@ -300,16 +305,18 @@ testMultithreadedPoolPut () | |||
300 | if (d == NULL) | 305 | if (d == NULL) |
301 | return 16; | 306 | return 16; |
302 | if (0 == port) | 307 | if (0 == port) |
308 | { | ||
309 | const union MHD_DaemonInfo *dinfo; | ||
310 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
311 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
303 | { | 312 | { |
304 | const union MHD_DaemonInfo *dinfo; | 313 | MHD_stop_daemon (d); return 32; |
305 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
306 | if (NULL == dinfo || 0 == dinfo->port) | ||
307 | { MHD_stop_daemon (d); return 32; } | ||
308 | port = (int)dinfo->port; | ||
309 | } | 314 | } |
315 | port = (int) dinfo->port; | ||
316 | } | ||
310 | c = curl_easy_init (); | 317 | c = curl_easy_init (); |
311 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 318 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
312 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 319 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
313 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 320 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
314 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 321 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
315 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 322 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -328,14 +335,14 @@ testMultithreadedPoolPut () | |||
328 | * crashes on my system! */ | 335 | * crashes on my system! */ |
329 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 336 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
330 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 337 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
331 | { | 338 | { |
332 | fprintf (stderr, | 339 | fprintf (stderr, |
333 | "curl_easy_perform failed: `%s'\n", | 340 | "curl_easy_perform failed: `%s'\n", |
334 | curl_easy_strerror (errornum)); | 341 | curl_easy_strerror (errornum)); |
335 | curl_easy_cleanup (c); | 342 | curl_easy_cleanup (c); |
336 | MHD_stop_daemon (d); | 343 | MHD_stop_daemon (d); |
337 | return 32; | 344 | return 32; |
338 | } | 345 | } |
339 | curl_easy_cleanup (c); | 346 | curl_easy_cleanup (c); |
340 | MHD_stop_daemon (d); | 347 | MHD_stop_daemon (d); |
341 | if (cbc.pos != strlen ("/hello_world")) | 348 | if (cbc.pos != strlen ("/hello_world")) |
@@ -388,16 +395,18 @@ testExternalPut () | |||
388 | if (d == NULL) | 395 | if (d == NULL) |
389 | return 256; | 396 | return 256; |
390 | if (0 == port) | 397 | if (0 == port) |
398 | { | ||
399 | const union MHD_DaemonInfo *dinfo; | ||
400 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
401 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
391 | { | 402 | { |
392 | const union MHD_DaemonInfo *dinfo; | 403 | MHD_stop_daemon (d); return 32; |
393 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
394 | if (NULL == dinfo || 0 == dinfo->port) | ||
395 | { MHD_stop_daemon (d); return 32; } | ||
396 | port = (int)dinfo->port; | ||
397 | } | 404 | } |
405 | port = (int) dinfo->port; | ||
406 | } | ||
398 | c = curl_easy_init (); | 407 | c = curl_easy_init (); |
399 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 408 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
400 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 409 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
401 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 410 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
402 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 411 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
403 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 412 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -419,87 +428,89 @@ testExternalPut () | |||
419 | 428 | ||
420 | multi = curl_multi_init (); | 429 | multi = curl_multi_init (); |
421 | if (multi == NULL) | 430 | if (multi == NULL) |
431 | { | ||
432 | curl_easy_cleanup (c); | ||
433 | MHD_stop_daemon (d); | ||
434 | return 512; | ||
435 | } | ||
436 | mret = curl_multi_add_handle (multi, c); | ||
437 | if (mret != CURLM_OK) | ||
438 | { | ||
439 | curl_multi_cleanup (multi); | ||
440 | curl_easy_cleanup (c); | ||
441 | MHD_stop_daemon (d); | ||
442 | return 1024; | ||
443 | } | ||
444 | start = time (NULL); | ||
445 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
446 | { | ||
447 | maxsock = MHD_INVALID_SOCKET; | ||
448 | maxposixs = -1; | ||
449 | FD_ZERO (&rs); | ||
450 | FD_ZERO (&ws); | ||
451 | FD_ZERO (&es); | ||
452 | curl_multi_perform (multi, &running); | ||
453 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
454 | if (mret != CURLM_OK) | ||
422 | { | 455 | { |
456 | curl_multi_remove_handle (multi, c); | ||
457 | curl_multi_cleanup (multi); | ||
423 | curl_easy_cleanup (c); | 458 | curl_easy_cleanup (c); |
424 | MHD_stop_daemon (d); | 459 | MHD_stop_daemon (d); |
425 | return 512; | 460 | return 2048; |
426 | } | 461 | } |
427 | mret = curl_multi_add_handle (multi, c); | 462 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
428 | if (mret != CURLM_OK) | ||
429 | { | 463 | { |
464 | curl_multi_remove_handle (multi, c); | ||
430 | curl_multi_cleanup (multi); | 465 | curl_multi_cleanup (multi); |
431 | curl_easy_cleanup (c); | 466 | curl_easy_cleanup (c); |
432 | MHD_stop_daemon (d); | 467 | MHD_stop_daemon (d); |
433 | return 1024; | 468 | return 4096; |
434 | } | 469 | } |
435 | start = time (NULL); | 470 | tv.tv_sec = 0; |
436 | while ((time (NULL) - start < 5) && (multi != NULL)) | 471 | tv.tv_usec = 1000; |
472 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
437 | { | 473 | { |
438 | maxsock = MHD_INVALID_SOCKET; | ||
439 | maxposixs = -1; | ||
440 | FD_ZERO (&rs); | ||
441 | FD_ZERO (&ws); | ||
442 | FD_ZERO (&es); | ||
443 | curl_multi_perform (multi, &running); | ||
444 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | ||
445 | if (mret != CURLM_OK) | ||
446 | { | ||
447 | curl_multi_remove_handle (multi, c); | ||
448 | curl_multi_cleanup (multi); | ||
449 | curl_easy_cleanup (c); | ||
450 | MHD_stop_daemon (d); | ||
451 | return 2048; | ||
452 | } | ||
453 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | ||
454 | { | ||
455 | curl_multi_remove_handle (multi, c); | ||
456 | curl_multi_cleanup (multi); | ||
457 | curl_easy_cleanup (c); | ||
458 | MHD_stop_daemon (d); | ||
459 | return 4096; | ||
460 | } | ||
461 | tv.tv_sec = 0; | ||
462 | tv.tv_usec = 1000; | ||
463 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
464 | { | ||
465 | #ifdef MHD_POSIX_SOCKETS | 474 | #ifdef MHD_POSIX_SOCKETS |
466 | if (EINTR != errno) | 475 | if (EINTR != errno) |
467 | abort (); | 476 | abort (); |
468 | #else | 477 | #else |
469 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 478 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
470 | abort (); | 479 | ws.fd_count) |
471 | Sleep (1000); | 480 | ||(0 != es.fd_count) ) |
481 | abort (); | ||
482 | Sleep (1000); | ||
472 | #endif | 483 | #endif |
473 | } | ||
474 | curl_multi_perform (multi, &running); | ||
475 | if (running == 0) | ||
476 | { | ||
477 | msg = curl_multi_info_read (multi, &running); | ||
478 | if (msg == NULL) | ||
479 | break; | ||
480 | if (msg->msg == CURLMSG_DONE) | ||
481 | { | ||
482 | if (msg->data.result != CURLE_OK) | ||
483 | printf ("%s failed at %s:%d: `%s'\n", | ||
484 | "curl_multi_perform", | ||
485 | __FILE__, | ||
486 | __LINE__, | ||
487 | curl_easy_strerror (msg->data.result)); | ||
488 | curl_multi_remove_handle (multi, c); | ||
489 | curl_multi_cleanup (multi); | ||
490 | curl_easy_cleanup (c); | ||
491 | c = NULL; | ||
492 | multi = NULL; | ||
493 | } | ||
494 | } | ||
495 | MHD_run (d); | ||
496 | } | 484 | } |
497 | if (multi != NULL) | 485 | curl_multi_perform (multi, &running); |
486 | if (running == 0) | ||
498 | { | 487 | { |
499 | curl_multi_remove_handle (multi, c); | 488 | msg = curl_multi_info_read (multi, &running); |
500 | curl_easy_cleanup (c); | 489 | if (msg == NULL) |
501 | curl_multi_cleanup (multi); | 490 | break; |
491 | if (msg->msg == CURLMSG_DONE) | ||
492 | { | ||
493 | if (msg->data.result != CURLE_OK) | ||
494 | printf ("%s failed at %s:%d: `%s'\n", | ||
495 | "curl_multi_perform", | ||
496 | __FILE__, | ||
497 | __LINE__, | ||
498 | curl_easy_strerror (msg->data.result)); | ||
499 | curl_multi_remove_handle (multi, c); | ||
500 | curl_multi_cleanup (multi); | ||
501 | curl_easy_cleanup (c); | ||
502 | c = NULL; | ||
503 | multi = NULL; | ||
504 | } | ||
502 | } | 505 | } |
506 | MHD_run (d); | ||
507 | } | ||
508 | if (multi != NULL) | ||
509 | { | ||
510 | curl_multi_remove_handle (multi, c); | ||
511 | curl_easy_cleanup (c); | ||
512 | curl_multi_cleanup (multi); | ||
513 | } | ||
503 | MHD_stop_daemon (d); | 514 | MHD_stop_daemon (d); |
504 | if (cbc.pos != strlen ("/hello_world")) | 515 | if (cbc.pos != strlen ("/hello_world")) |
505 | return 8192; | 516 | return 8192; |
@@ -514,16 +525,16 @@ int | |||
514 | main (int argc, char *const *argv) | 525 | main (int argc, char *const *argv) |
515 | { | 526 | { |
516 | unsigned int errorCount = 0; | 527 | unsigned int errorCount = 0; |
517 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 528 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
518 | 529 | ||
519 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 530 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
520 | return 2; | 531 | return 2; |
521 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 532 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
522 | { | 533 | { |
523 | errorCount += testInternalPut (); | 534 | errorCount += testInternalPut (); |
524 | errorCount += testMultithreadedPut (); | 535 | errorCount += testMultithreadedPut (); |
525 | errorCount += testMultithreadedPoolPut (); | 536 | errorCount += testMultithreadedPoolPut (); |
526 | } | 537 | } |
527 | errorCount += testExternalPut (); | 538 | errorCount += testExternalPut (); |
528 | if (errorCount != 0) | 539 | if (errorCount != 0) |
529 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 540 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c index 69b07618..c42880ce 100644 --- a/src/testcurl/test_quiesce.c +++ b/src/testcurl/test_quiesce.c | |||
@@ -40,10 +40,10 @@ | |||
40 | #include <sys/socket.h> | 40 | #include <sys/socket.h> |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 43 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
44 | #undef CPU_COUNT | 44 | #undef CPU_COUNT |
45 | #endif | 45 | #endif |
46 | #if !defined(CPU_COUNT) | 46 | #if ! defined(CPU_COUNT) |
47 | #define CPU_COUNT 2 | 47 | #define CPU_COUNT 2 |
48 | #endif | 48 | #endif |
49 | 49 | ||
@@ -83,19 +83,19 @@ ahc_echo (void *cls, | |||
83 | const char *me = cls; | 83 | const char *me = cls; |
84 | struct MHD_Response *response; | 84 | struct MHD_Response *response; |
85 | int ret; | 85 | int ret; |
86 | (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 86 | (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
87 | 87 | ||
88 | if (0 != strcmp (me, method)) | 88 | if (0 != strcmp (me, method)) |
89 | return MHD_NO; /* unexpected method */ | 89 | return MHD_NO; /* unexpected method */ |
90 | if (&ptr != *unused) | 90 | if (&ptr != *unused) |
91 | { | 91 | { |
92 | *unused = &ptr; | 92 | *unused = &ptr; |
93 | return MHD_YES; | 93 | return MHD_YES; |
94 | } | 94 | } |
95 | *unused = NULL; | 95 | *unused = NULL; |
96 | response = MHD_create_response_from_buffer (strlen (url), | 96 | response = MHD_create_response_from_buffer (strlen (url), |
97 | (void *) url, | 97 | (void *) url, |
98 | MHD_RESPMEM_MUST_COPY); | 98 | MHD_RESPMEM_MUST_COPY); |
99 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 99 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
100 | MHD_destroy_response (response); | 100 | MHD_destroy_response (response); |
101 | if (ret == MHD_NO) | 101 | if (ret == MHD_NO) |
@@ -106,16 +106,16 @@ ahc_echo (void *cls, | |||
106 | 106 | ||
107 | static void | 107 | static void |
108 | request_completed (void *cls, struct MHD_Connection *connection, | 108 | request_completed (void *cls, struct MHD_Connection *connection, |
109 | void **con_cls, enum MHD_RequestTerminationCode code) | 109 | void **con_cls, enum MHD_RequestTerminationCode code) |
110 | { | 110 | { |
111 | (void)connection;(void)con_cls;(void)code; /* Unused. Silent compiler warning. */ | 111 | (void) connection; (void) con_cls; (void) code; /* Unused. Silent compiler warning. */ |
112 | int *done = (int *)cls; | 112 | int *done = (int *) cls; |
113 | *done = 1; | 113 | *done = 1; |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | static void * | 117 | static void * |
118 | ServeOneRequest(void *param) | 118 | ServeOneRequest (void *param) |
119 | { | 119 | { |
120 | struct MHD_Daemon *d; | 120 | struct MHD_Daemon *d; |
121 | fd_set rs; | 121 | fd_set rs; |
@@ -138,38 +138,40 @@ ServeOneRequest(void *param) | |||
138 | 138 | ||
139 | start = time (NULL); | 139 | start = time (NULL); |
140 | while ((time (NULL) - start < 5) && done == 0) | 140 | while ((time (NULL) - start < 5) && done == 0) |
141 | { | ||
142 | max = 0; | ||
143 | FD_ZERO (&rs); | ||
144 | FD_ZERO (&ws); | ||
145 | FD_ZERO (&es); | ||
146 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
147 | { | ||
148 | MHD_stop_daemon (d); | ||
149 | MHD_socket_close_chk_ (fd); | ||
150 | return "MHD_get_fdset() failed"; | ||
151 | } | ||
152 | tv.tv_sec = 0; | ||
153 | tv.tv_usec = 1000; | ||
154 | if (-1 == MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv)) | ||
141 | { | 155 | { |
142 | max = 0; | ||
143 | FD_ZERO (&rs); | ||
144 | FD_ZERO (&ws); | ||
145 | FD_ZERO (&es); | ||
146 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
147 | { | ||
148 | MHD_stop_daemon (d); | ||
149 | MHD_socket_close_chk_(fd); | ||
150 | return "MHD_get_fdset() failed"; | ||
151 | } | ||
152 | tv.tv_sec = 0; | ||
153 | tv.tv_usec = 1000; | ||
154 | if (-1 == MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv)) | ||
155 | { | ||
156 | #ifdef MHD_POSIX_SOCKETS | 156 | #ifdef MHD_POSIX_SOCKETS |
157 | if (EINTR != errno) | 157 | if (EINTR != errno) |
158 | abort (); | 158 | abort (); |
159 | #else | 159 | #else |
160 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 160 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
161 | abort (); | 161 | ws.fd_count) |
162 | Sleep (1000); | 162 | ||(0 != es.fd_count) ) |
163 | abort (); | ||
164 | Sleep (1000); | ||
163 | #endif | 165 | #endif |
164 | } | ||
165 | MHD_run (d); | ||
166 | } | 166 | } |
167 | MHD_run (d); | ||
168 | } | ||
167 | fd = MHD_quiesce_daemon (d); | 169 | fd = MHD_quiesce_daemon (d); |
168 | if (MHD_INVALID_SOCKET == fd) | 170 | if (MHD_INVALID_SOCKET == fd) |
169 | { | 171 | { |
170 | MHD_stop_daemon (d); | 172 | MHD_stop_daemon (d); |
171 | return "MHD_quiesce_daemon() failed in ServeOneRequest()"; | 173 | return "MHD_quiesce_daemon() failed in ServeOneRequest()"; |
172 | } | 174 | } |
173 | MHD_stop_daemon (d); | 175 | MHD_stop_daemon (d); |
174 | return done ? NULL : "Requests was not served by ServeOneRequest()"; | 176 | return done ? NULL : "Requests was not served by ServeOneRequest()"; |
175 | } | 177 | } |
@@ -182,7 +184,7 @@ setupCURL (void *cbc) | |||
182 | 184 | ||
183 | c = curl_easy_init (); | 185 | c = curl_easy_init (); |
184 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 186 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
185 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 187 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
186 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 188 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
187 | curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc); | 189 | curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc); |
188 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 190 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -218,44 +220,51 @@ testGet (int type, int pool_count, int poll_flag) | |||
218 | cbc.buf = buf; | 220 | cbc.buf = buf; |
219 | cbc.size = 2048; | 221 | cbc.size = 2048; |
220 | cbc.pos = 0; | 222 | cbc.pos = 0; |
221 | if (pool_count > 0) { | 223 | if (pool_count > 0) |
224 | { | ||
222 | d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, | 225 | d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, |
223 | port, NULL, NULL, &ahc_echo, "GET", | 226 | port, NULL, NULL, &ahc_echo, "GET", |
224 | MHD_OPTION_THREAD_POOL_SIZE, pool_count, MHD_OPTION_END); | 227 | MHD_OPTION_THREAD_POOL_SIZE, pool_count, |
228 | MHD_OPTION_END); | ||
225 | 229 | ||
226 | } else { | 230 | } |
231 | else { | ||
227 | d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, | 232 | d = MHD_start_daemon (type | MHD_USE_ERROR_LOG | MHD_USE_ITC | poll_flag, |
228 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 233 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
229 | } | 234 | } |
230 | if (d == NULL) | 235 | if (d == NULL) |
231 | return 1; | 236 | return 1; |
232 | if (0 == port) | 237 | if (0 == port) |
238 | { | ||
239 | const union MHD_DaemonInfo *dinfo; | ||
240 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
241 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
233 | { | 242 | { |
234 | const union MHD_DaemonInfo *dinfo; | 243 | MHD_stop_daemon (d); return 32; |
235 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
236 | if (NULL == dinfo || 0 == dinfo->port) | ||
237 | { MHD_stop_daemon (d); return 32; } | ||
238 | port = (int)dinfo->port; | ||
239 | } | 244 | } |
245 | port = (int) dinfo->port; | ||
246 | } | ||
240 | 247 | ||
241 | c = setupCURL(&cbc); | 248 | c = setupCURL (&cbc); |
242 | 249 | ||
243 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 250 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
244 | { | 251 | { |
245 | fprintf (stderr, | 252 | fprintf (stderr, |
246 | "curl_easy_perform failed: `%s'\n", | 253 | "curl_easy_perform failed: `%s'\n", |
247 | curl_easy_strerror (errornum)); | 254 | curl_easy_strerror (errornum)); |
248 | curl_easy_cleanup (c); | 255 | curl_easy_cleanup (c); |
249 | MHD_stop_daemon (d); | 256 | MHD_stop_daemon (d); |
250 | return 2; | 257 | return 2; |
251 | } | 258 | } |
252 | 259 | ||
253 | if (cbc.pos != strlen ("/hello_world")) { | 260 | if (cbc.pos != strlen ("/hello_world")) |
261 | { | ||
254 | curl_easy_cleanup (c); | 262 | curl_easy_cleanup (c); |
255 | MHD_stop_daemon (d); | 263 | MHD_stop_daemon (d); |
256 | return 4; | 264 | return 4; |
257 | } | 265 | } |
258 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) { | 266 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
267 | { | ||
259 | curl_easy_cleanup (c); | 268 | curl_easy_cleanup (c); |
260 | MHD_stop_daemon (d); | 269 | MHD_stop_daemon (d); |
261 | return 8; | 270 | return 8; |
@@ -263,78 +272,79 @@ testGet (int type, int pool_count, int poll_flag) | |||
263 | 272 | ||
264 | fd = MHD_quiesce_daemon (d); | 273 | fd = MHD_quiesce_daemon (d); |
265 | if (MHD_INVALID_SOCKET == fd) | 274 | if (MHD_INVALID_SOCKET == fd) |
266 | { | 275 | { |
267 | fprintf (stderr, | 276 | fprintf (stderr, |
268 | "MHD_quiesce_daemon failed.\n"); | 277 | "MHD_quiesce_daemon failed.\n"); |
269 | curl_easy_cleanup (c); | 278 | curl_easy_cleanup (c); |
270 | MHD_stop_daemon (d); | 279 | MHD_stop_daemon (d); |
271 | return 2; | 280 | return 2; |
272 | } | 281 | } |
273 | if (0 != pthread_create(&thrd, NULL, &ServeOneRequest, (void*)(intptr_t) fd)) | 282 | if (0 != pthread_create (&thrd, NULL, &ServeOneRequest, |
274 | { | 283 | (void*) (intptr_t) fd)) |
275 | fprintf (stderr, "pthread_create failed\n"); | 284 | { |
276 | curl_easy_cleanup (c); | 285 | fprintf (stderr, "pthread_create failed\n"); |
277 | MHD_stop_daemon (d); | 286 | curl_easy_cleanup (c); |
278 | return 16; | 287 | MHD_stop_daemon (d); |
279 | } | 288 | return 16; |
289 | } | ||
280 | 290 | ||
281 | cbc.pos = 0; | 291 | cbc.pos = 0; |
282 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 292 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
283 | { | 293 | { |
284 | fprintf (stderr, | 294 | fprintf (stderr, |
285 | "curl_easy_perform failed: `%s'\n", | 295 | "curl_easy_perform failed: `%s'\n", |
286 | curl_easy_strerror (errornum)); | 296 | curl_easy_strerror (errornum)); |
287 | curl_easy_cleanup (c); | 297 | curl_easy_cleanup (c); |
288 | MHD_stop_daemon (d); | 298 | MHD_stop_daemon (d); |
289 | return 2; | 299 | return 2; |
290 | } | 300 | } |
291 | 301 | ||
292 | if (0 != pthread_join(thrd, (void**)&thrdRet)) | 302 | if (0 != pthread_join (thrd, (void**) &thrdRet)) |
293 | { | 303 | { |
294 | fprintf (stderr, "pthread_join failed\n"); | 304 | fprintf (stderr, "pthread_join failed\n"); |
295 | curl_easy_cleanup (c); | 305 | curl_easy_cleanup (c); |
296 | MHD_stop_daemon (d); | 306 | MHD_stop_daemon (d); |
297 | return 16; | 307 | return 16; |
298 | } | 308 | } |
299 | if (NULL != thrdRet) | 309 | if (NULL != thrdRet) |
300 | { | 310 | { |
301 | fprintf (stderr, "ServeOneRequest() error: %s\n", thrdRet); | 311 | fprintf (stderr, "ServeOneRequest() error: %s\n", thrdRet); |
302 | curl_easy_cleanup (c); | 312 | curl_easy_cleanup (c); |
303 | MHD_stop_daemon (d); | 313 | MHD_stop_daemon (d); |
304 | return 16; | 314 | return 16; |
305 | } | 315 | } |
306 | 316 | ||
307 | if (cbc.pos != strlen ("/hello_world")) | 317 | if (cbc.pos != strlen ("/hello_world")) |
308 | { | 318 | { |
309 | fprintf(stderr, "%s\n", cbc.buf); | 319 | fprintf (stderr, "%s\n", cbc.buf); |
310 | curl_easy_cleanup (c); | 320 | curl_easy_cleanup (c); |
311 | MHD_stop_daemon (d); | 321 | MHD_stop_daemon (d); |
312 | MHD_socket_close_chk_(fd); | 322 | MHD_socket_close_chk_ (fd); |
313 | return 4; | 323 | return 4; |
314 | } | 324 | } |
315 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 325 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) |
316 | { | 326 | { |
317 | fprintf(stderr, "%s\n", cbc.buf); | 327 | fprintf (stderr, "%s\n", cbc.buf); |
318 | curl_easy_cleanup (c); | 328 | curl_easy_cleanup (c); |
319 | MHD_stop_daemon (d); | 329 | MHD_stop_daemon (d); |
320 | MHD_socket_close_chk_(fd); | 330 | MHD_socket_close_chk_ (fd); |
321 | return 8; | 331 | return 8; |
322 | } | 332 | } |
323 | 333 | ||
324 | /* at this point, the forked server quit, and the new | 334 | /* at this point, the forked server quit, and the new |
325 | * server has quiesced, so new requests should fail | 335 | * server has quiesced, so new requests should fail |
326 | */ | 336 | */ |
327 | if (CURLE_OK == (errornum = curl_easy_perform (c))) | 337 | if (CURLE_OK == (errornum = curl_easy_perform (c))) |
328 | { | 338 | { |
329 | fprintf (stderr, "curl_easy_perform should fail\n"); | 339 | fprintf (stderr, "curl_easy_perform should fail\n"); |
330 | curl_easy_cleanup (c); | 340 | curl_easy_cleanup (c); |
331 | MHD_stop_daemon (d); | 341 | MHD_stop_daemon (d); |
332 | MHD_socket_close_chk_(fd); | 342 | MHD_socket_close_chk_ (fd); |
333 | return 2; | 343 | return 2; |
334 | } | 344 | } |
335 | curl_easy_cleanup (c); | 345 | curl_easy_cleanup (c); |
336 | MHD_stop_daemon (d); | 346 | MHD_stop_daemon (d); |
337 | MHD_socket_close_chk_(fd); | 347 | MHD_socket_close_chk_ (fd); |
338 | 348 | ||
339 | return 0; | 349 | return 0; |
340 | } | 350 | } |
@@ -382,136 +392,141 @@ testExternalGet () | |||
382 | if (d == NULL) | 392 | if (d == NULL) |
383 | return 256; | 393 | return 256; |
384 | if (0 == port) | 394 | if (0 == port) |
395 | { | ||
396 | const union MHD_DaemonInfo *dinfo; | ||
397 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
398 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
385 | { | 399 | { |
386 | const union MHD_DaemonInfo *dinfo; | 400 | MHD_stop_daemon (d); return 32; |
387 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
388 | if (NULL == dinfo || 0 == dinfo->port) | ||
389 | { MHD_stop_daemon (d); return 32; } | ||
390 | port = (int)dinfo->port; | ||
391 | } | 401 | } |
392 | c = setupCURL(&cbc); | 402 | port = (int) dinfo->port; |
403 | } | ||
404 | c = setupCURL (&cbc); | ||
393 | 405 | ||
394 | multi = curl_multi_init (); | 406 | multi = curl_multi_init (); |
395 | if (multi == NULL) | 407 | if (multi == NULL) |
396 | { | 408 | { |
397 | curl_easy_cleanup (c); | 409 | curl_easy_cleanup (c); |
398 | MHD_stop_daemon (d); | 410 | MHD_stop_daemon (d); |
399 | return 512; | 411 | return 512; |
400 | } | 412 | } |
401 | mret = curl_multi_add_handle (multi, c); | 413 | mret = curl_multi_add_handle (multi, c); |
402 | if (mret != CURLM_OK) | 414 | if (mret != CURLM_OK) |
403 | { | 415 | { |
404 | curl_multi_cleanup (multi); | 416 | curl_multi_cleanup (multi); |
405 | curl_easy_cleanup (c); | 417 | curl_easy_cleanup (c); |
406 | MHD_stop_daemon (d); | 418 | MHD_stop_daemon (d); |
407 | return 1024; | 419 | return 1024; |
408 | } | 420 | } |
409 | 421 | ||
410 | for (i = 0; i < 2; i++) | 422 | for (i = 0; i < 2; i++) |
423 | { | ||
424 | start = time (NULL); | ||
425 | while ( (time (NULL) - start < 5) && | ||
426 | (NULL != multi) ) | ||
411 | { | 427 | { |
412 | start = time (NULL); | 428 | maxsock = MHD_INVALID_SOCKET; |
413 | while ( (time (NULL) - start < 5) && | 429 | maxposixs = -1; |
414 | (NULL != multi) ) | 430 | FD_ZERO (&rs); |
415 | { | 431 | FD_ZERO (&ws); |
416 | maxsock = MHD_INVALID_SOCKET; | 432 | FD_ZERO (&es); |
417 | maxposixs = -1; | 433 | curl_multi_perform (multi, &running); |
418 | FD_ZERO (&rs); | 434 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); |
419 | FD_ZERO (&ws); | 435 | if (mret != CURLM_OK) |
420 | FD_ZERO (&es); | 436 | { |
421 | curl_multi_perform (multi, &running); | 437 | curl_multi_remove_handle (multi, c); |
422 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs); | 438 | curl_multi_cleanup (multi); |
423 | if (mret != CURLM_OK) | 439 | curl_easy_cleanup (c); |
424 | { | 440 | MHD_stop_daemon (d); |
425 | curl_multi_remove_handle (multi, c); | 441 | return 2048; |
426 | curl_multi_cleanup (multi); | 442 | } |
427 | curl_easy_cleanup (c); | 443 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) |
428 | MHD_stop_daemon (d); | 444 | { |
429 | return 2048; | 445 | curl_multi_remove_handle (multi, c); |
430 | } | 446 | curl_multi_cleanup (multi); |
431 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock)) | 447 | curl_easy_cleanup (c); |
432 | { | 448 | MHD_stop_daemon (d); |
433 | curl_multi_remove_handle (multi, c); | 449 | return 4096; |
434 | curl_multi_cleanup (multi); | 450 | } |
435 | curl_easy_cleanup (c); | 451 | tv.tv_sec = 0; |
436 | MHD_stop_daemon (d); | 452 | tv.tv_usec = 1000; |
437 | return 4096; | 453 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) |
438 | } | 454 | { |
439 | tv.tv_sec = 0; | ||
440 | tv.tv_usec = 1000; | ||
441 | if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv)) | ||
442 | { | ||
443 | #ifdef MHD_POSIX_SOCKETS | 455 | #ifdef MHD_POSIX_SOCKETS |
444 | if (EINTR != errno) | 456 | if (EINTR != errno) |
445 | abort (); | 457 | abort (); |
446 | #else | 458 | #else |
447 | if (WSAEINVAL != WSAGetLastError() || 0 != rs.fd_count || 0 != ws.fd_count || 0 != es.fd_count) | 459 | if ((WSAEINVAL != WSAGetLastError ()) ||(0 != rs.fd_count) ||(0 != |
448 | abort (); | 460 | ws. |
449 | Sleep (1000); | 461 | fd_count) |
462 | ||(0 != es.fd_count) ) | ||
463 | abort (); | ||
464 | Sleep (1000); | ||
450 | #endif | 465 | #endif |
451 | } | 466 | } |
452 | curl_multi_perform (multi, &running); | 467 | curl_multi_perform (multi, &running); |
453 | if (0 == running) | 468 | if (0 == running) |
454 | { | 469 | { |
455 | msg = curl_multi_info_read (multi, &running); | 470 | msg = curl_multi_info_read (multi, &running); |
456 | if (NULL == msg) | 471 | if (NULL == msg) |
457 | break; | 472 | break; |
458 | if (msg->msg == CURLMSG_DONE) | 473 | if (msg->msg == CURLMSG_DONE) |
459 | { | ||
460 | if (i == 0 && msg->data.result != CURLE_OK) | ||
461 | printf ("%s failed at %s:%d: `%s'\n", | ||
462 | "curl_multi_perform", | ||
463 | __FILE__, | ||
464 | __LINE__, | ||
465 | curl_easy_strerror (msg->data.result)); | ||
466 | else if ( (i == 1) && | ||
467 | (msg->data.result == CURLE_OK) ) | ||
468 | printf ("%s should have failed at %s:%d\n", | ||
469 | "curl_multi_perform", | ||
470 | __FILE__, | ||
471 | __LINE__); | ||
472 | curl_multi_remove_handle (multi, c); | ||
473 | curl_multi_cleanup (multi); | ||
474 | curl_easy_cleanup (c); | ||
475 | c = NULL; | ||
476 | multi = NULL; | ||
477 | } | ||
478 | } | ||
479 | MHD_run (d); | ||
480 | } | ||
481 | |||
482 | if (0 == i) | ||
483 | { | 474 | { |
484 | /* quiesce the daemon on the 1st iteration, so the 2nd should fail */ | 475 | if ((i == 0) &&(msg->data.result != CURLE_OK) ) |
485 | fd = MHD_quiesce_daemon(d); | 476 | printf ("%s failed at %s:%d: `%s'\n", |
486 | if (MHD_INVALID_SOCKET == fd) | 477 | "curl_multi_perform", |
487 | { | 478 | __FILE__, |
488 | fprintf (stderr, | 479 | __LINE__, |
489 | "MHD_quiesce_daemon failed.\n"); | 480 | curl_easy_strerror (msg->data.result)); |
490 | curl_multi_remove_handle (multi, c); | 481 | else if ( (i == 1) && |
491 | curl_multi_cleanup (multi); | 482 | (msg->data.result == CURLE_OK) ) |
492 | curl_easy_cleanup (c); | 483 | printf ("%s should have failed at %s:%d\n", |
493 | MHD_stop_daemon (d); | 484 | "curl_multi_perform", |
494 | return 2; | 485 | __FILE__, |
495 | } | 486 | __LINE__); |
496 | c = setupCURL (&cbc); | 487 | curl_multi_remove_handle (multi, c); |
497 | multi = curl_multi_init (); | 488 | curl_multi_cleanup (multi); |
498 | mret = curl_multi_add_handle (multi, c); | 489 | curl_easy_cleanup (c); |
499 | if (mret != CURLM_OK) | 490 | c = NULL; |
500 | { | 491 | multi = NULL; |
501 | curl_multi_remove_handle (multi, c); | ||
502 | curl_multi_cleanup (multi); | ||
503 | curl_easy_cleanup (c); | ||
504 | MHD_stop_daemon (d); | ||
505 | return 32768; | ||
506 | } | ||
507 | } | 492 | } |
493 | } | ||
494 | MHD_run (d); | ||
508 | } | 495 | } |
509 | if (NULL != multi) | 496 | |
497 | if (0 == i) | ||
510 | { | 498 | { |
511 | curl_multi_remove_handle (multi, c); | 499 | /* quiesce the daemon on the 1st iteration, so the 2nd should fail */ |
512 | curl_easy_cleanup (c); | 500 | fd = MHD_quiesce_daemon (d); |
513 | curl_multi_cleanup (multi); | 501 | if (MHD_INVALID_SOCKET == fd) |
502 | { | ||
503 | fprintf (stderr, | ||
504 | "MHD_quiesce_daemon failed.\n"); | ||
505 | curl_multi_remove_handle (multi, c); | ||
506 | curl_multi_cleanup (multi); | ||
507 | curl_easy_cleanup (c); | ||
508 | MHD_stop_daemon (d); | ||
509 | return 2; | ||
510 | } | ||
511 | c = setupCURL (&cbc); | ||
512 | multi = curl_multi_init (); | ||
513 | mret = curl_multi_add_handle (multi, c); | ||
514 | if (mret != CURLM_OK) | ||
515 | { | ||
516 | curl_multi_remove_handle (multi, c); | ||
517 | curl_multi_cleanup (multi); | ||
518 | curl_easy_cleanup (c); | ||
519 | MHD_stop_daemon (d); | ||
520 | return 32768; | ||
521 | } | ||
514 | } | 522 | } |
523 | } | ||
524 | if (NULL != multi) | ||
525 | { | ||
526 | curl_multi_remove_handle (multi, c); | ||
527 | curl_easy_cleanup (c); | ||
528 | curl_multi_cleanup (multi); | ||
529 | } | ||
515 | MHD_stop_daemon (d); | 530 | MHD_stop_daemon (d); |
516 | MHD_socket_close_chk_ (fd); | 531 | MHD_socket_close_chk_ (fd); |
517 | if (cbc.pos != strlen ("/hello_world")) | 532 | if (cbc.pos != strlen ("/hello_world")) |
@@ -526,32 +541,37 @@ int | |||
526 | main (int argc, char *const *argv) | 541 | main (int argc, char *const *argv) |
527 | { | 542 | { |
528 | unsigned int errorCount = 0; | 543 | unsigned int errorCount = 0; |
529 | (void)argc; (void)argv; /* Unused. Silent compiler warning. */ | 544 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
530 | 545 | ||
531 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 546 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
532 | return 2; | 547 | return 2; |
533 | errorCount += testExternalGet (); | 548 | errorCount += testExternalGet (); |
534 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) | 549 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) |
550 | { | ||
551 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); | ||
552 | errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION | ||
553 | | MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); | ||
554 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, 0); | ||
555 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL)) | ||
535 | { | 556 | { |
536 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); | 557 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_POLL); |
537 | errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, 0, 0); | 558 | errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION |
538 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, 0); | 559 | | MHD_USE_INTERNAL_POLLING_THREAD, 0, |
539 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_POLL)) | 560 | MHD_USE_POLL); |
540 | { | 561 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, |
541 | errorCount += testGet(MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_POLL); | 562 | MHD_USE_POLL); |
542 | errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_POLL); | ||
543 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, MHD_USE_POLL); | ||
544 | } | ||
545 | if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_EPOLL)) | ||
546 | { | ||
547 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_EPOLL); | ||
548 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, MHD_USE_EPOLL); | ||
549 | } | ||
550 | } | 563 | } |
564 | if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL)) | ||
565 | { | ||
566 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, 0, MHD_USE_EPOLL); | ||
567 | errorCount += testGet (MHD_USE_INTERNAL_POLLING_THREAD, CPU_COUNT, | ||
568 | MHD_USE_EPOLL); | ||
569 | } | ||
570 | } | ||
551 | if (0 != errorCount) | 571 | if (0 != errorCount) |
552 | fprintf (stderr, | 572 | fprintf (stderr, |
553 | "Error (code: %u)\n", | 573 | "Error (code: %u)\n", |
554 | errorCount); | 574 | errorCount); |
555 | curl_global_cleanup (); | 575 | curl_global_cleanup (); |
556 | return errorCount != 0; /* 0 == pass */ | 576 | return errorCount != 0; /* 0 == pass */ |
557 | } | 577 | } |
diff --git a/src/testcurl/test_quiesce_stream.c b/src/testcurl/test_quiesce_stream.c index bccb5890..821f1102 100644 --- a/src/testcurl/test_quiesce_stream.c +++ b/src/testcurl/test_quiesce_stream.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include <unistd.h> | 35 | #include <unistd.h> |
36 | #elif defined(_WIN32) | 36 | #elif defined(_WIN32) |
37 | #include <windows.h> | 37 | #include <windows.h> |
38 | #define sleep(s) (Sleep((s)*1000), 0) | 38 | #define sleep(s) (Sleep ((s) * 1000), 0) |
39 | #endif /* _WIN32 */ | 39 | #endif /* _WIN32 */ |
40 | 40 | ||
41 | 41 | ||
@@ -48,8 +48,8 @@ http_PanicCallback (void *cls, | |||
48 | unsigned int line, | 48 | unsigned int line, |
49 | const char *reason) | 49 | const char *reason) |
50 | { | 50 | { |
51 | (void)cls; /* Unused. Silent compiler warning. */ | 51 | (void) cls; /* Unused. Silent compiler warning. */ |
52 | fprintf( stderr, | 52 | fprintf (stderr, |
53 | "PANIC: exit process: %s at %s:%u\n", | 53 | "PANIC: exit process: %s at %s:%u\n", |
54 | reason, | 54 | reason, |
55 | file, | 55 | file, |
@@ -81,11 +81,11 @@ suspend_connection (struct MHD_Connection *connection) | |||
81 | &resume_connection, | 81 | &resume_connection, |
82 | connection); | 82 | connection); |
83 | if (0 != status) | 83 | if (0 != status) |
84 | { | 84 | { |
85 | fprintf (stderr, | 85 | fprintf (stderr, |
86 | "Could not create thead\n"); | 86 | "Could not create thead\n"); |
87 | exit( EXIT_FAILURE ); | 87 | exit (EXIT_FAILURE); |
88 | } | 88 | } |
89 | pthread_detach (thread_id); | 89 | pthread_detach (thread_id); |
90 | } | 90 | } |
91 | 91 | ||
@@ -103,17 +103,18 @@ http_ContentReaderCallback (void *cls, | |||
103 | char *buf, | 103 | char *buf, |
104 | size_t max) | 104 | size_t max) |
105 | { | 105 | { |
106 | static const char alphabet[] = "\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | 106 | static const char alphabet[] = |
107 | "\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
107 | struct ContentReaderUserdata *userdata = cls; | 108 | struct ContentReaderUserdata *userdata = cls; |
108 | (void)pos;(void)max; /* Unused. Silent compiler warning. */ | 109 | (void) pos; (void) max; /* Unused. Silent compiler warning. */ |
109 | 110 | ||
110 | if( userdata->bytes_written >= 1024) | 111 | if ( userdata->bytes_written >= 1024) |
111 | { | 112 | { |
112 | fprintf( stderr, | 113 | fprintf (stderr, |
113 | "finish: %d\n", | 114 | "finish: %d\n", |
114 | request_counter); | 115 | request_counter); |
115 | return MHD_CONTENT_READER_END_OF_STREAM; | 116 | return MHD_CONTENT_READER_END_OF_STREAM; |
116 | } | 117 | } |
117 | userdata->bytes_written++; | 118 | userdata->bytes_written++; |
118 | buf[0] = alphabet[userdata->bytes_written % (sizeof(alphabet) - 1)]; | 119 | buf[0] = alphabet[userdata->bytes_written % (sizeof(alphabet) - 1)]; |
119 | suspend_connection (userdata->connection); | 120 | suspend_connection (userdata->connection); |
@@ -139,21 +140,22 @@ http_AccessHandlerCallback (void *cls, | |||
139 | const char *version, | 140 | const char *version, |
140 | const char *upload_data, | 141 | const char *upload_data, |
141 | size_t *upload_data_size, | 142 | size_t *upload_data_size, |
142 | void **con_cls ) | 143 | void **con_cls) |
143 | { | 144 | { |
144 | int ret; | 145 | int ret; |
145 | (void)cls;(void)url; /* Unused. Silent compiler warning. */ | 146 | (void) cls; (void) url; /* Unused. Silent compiler warning. */ |
146 | (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ | 147 | (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ |
147 | (void)upload_data_size; /* Unused. Silent compiler warning. */ | 148 | (void) upload_data_size; /* Unused. Silent compiler warning. */ |
148 | 149 | ||
149 | /* Never respond on first call */ | 150 | /* Never respond on first call */ |
150 | if (NULL == *con_cls) | 151 | if (NULL == *con_cls) |
151 | { | 152 | { |
152 | fprintf (stderr, | 153 | fprintf (stderr, |
153 | "start: %d\n", | 154 | "start: %d\n", |
154 | ++request_counter); | 155 | ++request_counter); |
155 | 156 | ||
156 | struct ContentReaderUserdata *userdata = malloc (sizeof(struct ContentReaderUserdata)); | 157 | struct ContentReaderUserdata *userdata = malloc (sizeof(struct |
158 | ContentReaderUserdata)); | ||
157 | 159 | ||
158 | if (NULL == userdata) | 160 | if (NULL == userdata) |
159 | return MHD_NO; | 161 | return MHD_NO; |
@@ -181,7 +183,7 @@ http_AccessHandlerCallback (void *cls, | |||
181 | 183 | ||
182 | 184 | ||
183 | int | 185 | int |
184 | main(void) | 186 | main (void) |
185 | { | 187 | { |
186 | int port; | 188 | int port; |
187 | char command_line[1024]; | 189 | char command_line[1024]; |
@@ -198,9 +200,9 @@ main(void) | |||
198 | /* Flags */ | 200 | /* Flags */ |
199 | unsigned int daemon_flags | 201 | unsigned int daemon_flags |
200 | = MHD_USE_INTERNAL_POLLING_THREAD | 202 | = MHD_USE_INTERNAL_POLLING_THREAD |
201 | | MHD_USE_AUTO | 203 | | MHD_USE_AUTO |
202 | | MHD_ALLOW_SUSPEND_RESUME | 204 | | MHD_ALLOW_SUSPEND_RESUME |
203 | | MHD_USE_ITC; | 205 | | MHD_USE_ITC; |
204 | 206 | ||
205 | /* Create daemon */ | 207 | /* Create daemon */ |
206 | struct MHD_Daemon *daemon = MHD_start_daemon (daemon_flags, | 208 | struct MHD_Daemon *daemon = MHD_start_daemon (daemon_flags, |
@@ -213,33 +215,35 @@ main(void) | |||
213 | if (NULL == daemon) | 215 | if (NULL == daemon) |
214 | return 1; | 216 | return 1; |
215 | if (0 == port) | 217 | if (0 == port) |
218 | { | ||
219 | const union MHD_DaemonInfo *dinfo; | ||
220 | dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT); | ||
221 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
216 | { | 222 | { |
217 | const union MHD_DaemonInfo *dinfo; | 223 | MHD_stop_daemon (daemon); return 32; |
218 | dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT); | ||
219 | if (NULL == dinfo || 0 == dinfo->port) | ||
220 | { MHD_stop_daemon (daemon); return 32; } | ||
221 | port = (int)dinfo->port; | ||
222 | } | 224 | } |
225 | port = (int) dinfo->port; | ||
226 | } | ||
223 | snprintf (command_line, | 227 | snprintf (command_line, |
224 | sizeof (command_line), | 228 | sizeof (command_line), |
225 | "curl -s http://127.0.0.1:%d", | 229 | "curl -s http://127.0.0.1:%d", |
226 | port); | 230 | port); |
227 | 231 | ||
228 | if (0 != system (command_line)) | 232 | if (0 != system (command_line)) |
229 | { | 233 | { |
230 | MHD_stop_daemon (daemon); | 234 | MHD_stop_daemon (daemon); |
231 | return 1; | 235 | return 1; |
232 | } | 236 | } |
233 | /* wait for a request */ | 237 | /* wait for a request */ |
234 | while (0 == request_counter) | 238 | while (0 == request_counter) |
235 | (void)sleep (1); | 239 | (void) sleep (1); |
236 | 240 | ||
237 | fprintf (stderr, | 241 | fprintf (stderr, |
238 | "quiesce\n"); | 242 | "quiesce\n"); |
239 | MHD_quiesce_daemon (daemon); | 243 | MHD_quiesce_daemon (daemon); |
240 | 244 | ||
241 | /* wait a second */ | 245 | /* wait a second */ |
242 | (void)sleep (1); | 246 | (void) sleep (1); |
243 | 247 | ||
244 | fprintf (stderr, | 248 | fprintf (stderr, |
245 | "stopping daemon\n"); | 249 | "stopping daemon\n"); |
diff --git a/src/testcurl/test_termination.c b/src/testcurl/test_termination.c index 5be74303..cd99e0af 100644 --- a/src/testcurl/test_termination.c +++ b/src/testcurl/test_termination.c | |||
@@ -53,29 +53,29 @@ connection_handler (void *cls, | |||
53 | const char *url, | 53 | const char *url, |
54 | const char *method, | 54 | const char *method, |
55 | const char *version, | 55 | const char *version, |
56 | const char *upload_data, size_t * upload_data_size, | 56 | const char *upload_data, size_t *upload_data_size, |
57 | void **ptr) | 57 | void **ptr) |
58 | { | 58 | { |
59 | static int i; | 59 | static int i; |
60 | (void)cls;(void)url; /* Unused. Silent compiler warning. */ | 60 | (void) cls; (void) url; /* Unused. Silent compiler warning. */ |
61 | (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ | 61 | (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ |
62 | (void)upload_data_size; /* Unused. Silent compiler warning. */ | 62 | (void) upload_data_size; /* Unused. Silent compiler warning. */ |
63 | 63 | ||
64 | if (*ptr == NULL) | 64 | if (*ptr == NULL) |
65 | { | 65 | { |
66 | *ptr = &i; | 66 | *ptr = &i; |
67 | return MHD_YES; | 67 | return MHD_YES; |
68 | } | 68 | } |
69 | 69 | ||
70 | if (*upload_data_size != 0) | 70 | if (*upload_data_size != 0) |
71 | { | 71 | { |
72 | (*upload_data_size) = 0; | 72 | (*upload_data_size) = 0; |
73 | return MHD_YES; | 73 | return MHD_YES; |
74 | } | 74 | } |
75 | 75 | ||
76 | struct MHD_Response *response = | 76 | struct MHD_Response *response = |
77 | MHD_create_response_from_buffer (strlen ("Response"), "Response", | 77 | MHD_create_response_from_buffer (strlen ("Response"), "Response", |
78 | MHD_RESPMEM_PERSISTENT); | 78 | MHD_RESPMEM_PERSISTENT); |
79 | int ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 79 | int ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
80 | MHD_destroy_response (response); | 80 | MHD_destroy_response (response); |
81 | 81 | ||
@@ -85,7 +85,7 @@ connection_handler (void *cls, | |||
85 | static size_t | 85 | static size_t |
86 | write_data (void *ptr, size_t size, size_t nmemb, void *stream) | 86 | write_data (void *ptr, size_t size, size_t nmemb, void *stream) |
87 | { | 87 | { |
88 | (void)ptr;(void)stream; /* Unused. Silent compiler warning. */ | 88 | (void) ptr; (void) stream; /* Unused. Silent compiler warning. */ |
89 | return size * nmemb; | 89 | return size * nmemb; |
90 | } | 90 | } |
91 | 91 | ||
@@ -103,24 +103,28 @@ main (void) | |||
103 | port = 1490; | 103 | port = 1490; |
104 | 104 | ||
105 | 105 | ||
106 | daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 106 | daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
107 | | MHD_USE_INTERNAL_POLLING_THREAD | ||
108 | | MHD_USE_ERROR_LOG, | ||
107 | port, | 109 | port, |
108 | NULL, | 110 | NULL, |
109 | NULL, connection_handler, NULL, MHD_OPTION_END); | 111 | NULL, connection_handler, NULL, MHD_OPTION_END); |
110 | 112 | ||
111 | if (daemon == NULL) | 113 | if (daemon == NULL) |
112 | { | 114 | { |
113 | fprintf (stderr, "Daemon cannot be started!"); | 115 | fprintf (stderr, "Daemon cannot be started!"); |
114 | exit (1); | 116 | exit (1); |
115 | } | 117 | } |
116 | if (0 == port) | 118 | if (0 == port) |
119 | { | ||
120 | const union MHD_DaemonInfo *dinfo; | ||
121 | dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT); | ||
122 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
117 | { | 123 | { |
118 | const union MHD_DaemonInfo *dinfo; | 124 | MHD_stop_daemon (daemon); return 32; |
119 | dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT); | ||
120 | if (NULL == dinfo || 0 == dinfo->port) | ||
121 | { MHD_stop_daemon (daemon); return 32; } | ||
122 | port = (int)dinfo->port; | ||
123 | } | 125 | } |
126 | port = (int) dinfo->port; | ||
127 | } | ||
124 | 128 | ||
125 | curl = curl_easy_init (); | 129 | curl = curl_easy_init (); |
126 | /* curl_easy_setopt(curl, CURLOPT_POST, 1L); */ | 130 | /* curl_easy_setopt(curl, CURLOPT_POST, 1L); */ |
@@ -133,12 +137,12 @@ main (void) | |||
133 | 137 | ||
134 | CURLcode success = curl_easy_perform (curl); | 138 | CURLcode success = curl_easy_perform (curl); |
135 | if (success != 0) | 139 | if (success != 0) |
136 | { | 140 | { |
137 | fprintf (stderr, "CURL Error"); | 141 | fprintf (stderr, "CURL Error"); |
138 | exit (1); | 142 | exit (1); |
139 | } | 143 | } |
140 | /* CPU used to go crazy here */ | 144 | /* CPU used to go crazy here */ |
141 | (void)sleep (1); | 145 | (void) sleep (1); |
142 | 146 | ||
143 | curl_easy_cleanup (curl); | 147 | curl_easy_cleanup (curl); |
144 | MHD_stop_daemon (daemon); | 148 | MHD_stop_daemon (daemon); |
diff --git a/src/testcurl/test_timeout.c b/src/testcurl/test_timeout.c index d87bb368..a17b0fb8 100644 --- a/src/testcurl/test_timeout.c +++ b/src/testcurl/test_timeout.c | |||
@@ -51,37 +51,37 @@ struct CBC | |||
51 | }; | 51 | }; |
52 | 52 | ||
53 | 53 | ||
54 | static void | 54 | static void |
55 | termination_cb (void *cls, | 55 | termination_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 | int *test = cls; | 60 | int *test = cls; |
61 | (void)connection;(void)con_cls; /* Unused. Silent compiler warning. */ | 61 | (void) connection; (void) con_cls; /* Unused. Silent compiler warning. */ |
62 | 62 | ||
63 | switch (toe) | 63 | switch (toe) |
64 | { | ||
65 | case MHD_REQUEST_TERMINATED_COMPLETED_OK: | ||
66 | if (test == &withoutTimeout) | ||
64 | { | 67 | { |
65 | case MHD_REQUEST_TERMINATED_COMPLETED_OK : | 68 | withoutTimeout = 0; |
66 | if (test == &withoutTimeout) | ||
67 | { | ||
68 | withoutTimeout = 0; | ||
69 | } | ||
70 | break; | ||
71 | case MHD_REQUEST_TERMINATED_WITH_ERROR : | ||
72 | case MHD_REQUEST_TERMINATED_READ_ERROR : | ||
73 | break; | ||
74 | case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED : | ||
75 | if (test == &withTimeout) | ||
76 | { | ||
77 | withTimeout = 0; | ||
78 | } | ||
79 | break; | ||
80 | case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: | ||
81 | break; | ||
82 | case MHD_REQUEST_TERMINATED_CLIENT_ABORT: | ||
83 | break; | ||
84 | } | 69 | } |
70 | break; | ||
71 | case MHD_REQUEST_TERMINATED_WITH_ERROR: | ||
72 | case MHD_REQUEST_TERMINATED_READ_ERROR: | ||
73 | break; | ||
74 | case MHD_REQUEST_TERMINATED_TIMEOUT_REACHED: | ||
75 | if (test == &withTimeout) | ||
76 | { | ||
77 | withTimeout = 0; | ||
78 | } | ||
79 | break; | ||
80 | case MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN: | ||
81 | break; | ||
82 | case MHD_REQUEST_TERMINATED_CLIENT_ABORT: | ||
83 | break; | ||
84 | } | ||
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
@@ -93,7 +93,7 @@ putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) | |||
93 | 93 | ||
94 | wrt = size * nmemb; | 94 | wrt = size * nmemb; |
95 | if (wrt > 8 - (*pos)) | 95 | if (wrt > 8 - (*pos)) |
96 | wrt = 8 - (*pos); | 96 | wrt = 8 - (*pos); |
97 | memcpy (stream, &("Hello123"[*pos]), wrt); | 97 | memcpy (stream, &("Hello123"[*pos]), wrt); |
98 | (*pos) += wrt; | 98 | (*pos) += wrt; |
99 | return wrt; | 99 | return wrt; |
@@ -103,7 +103,7 @@ putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) | |||
103 | static size_t | 103 | static size_t |
104 | putBuffer_fail (void *stream, size_t size, size_t nmemb, void *ptr) | 104 | putBuffer_fail (void *stream, size_t size, size_t nmemb, void *ptr) |
105 | { | 105 | { |
106 | (void)stream;(void)size;(void)nmemb;(void)ptr; /* Unused. Silent compiler warning. */ | 106 | (void) stream; (void) size; (void) nmemb; (void) ptr; /* Unused. Silent compiler warning. */ |
107 | return 0; | 107 | return 0; |
108 | } | 108 | } |
109 | 109 | ||
@@ -133,29 +133,29 @@ ahc_echo (void *cls, | |||
133 | int *done = cls; | 133 | int *done = cls; |
134 | struct MHD_Response *response; | 134 | struct MHD_Response *response; |
135 | int ret; | 135 | int ret; |
136 | (void)version;(void)unused; /* Unused. Silent compiler warning. */ | 136 | (void) version; (void) unused; /* Unused. Silent compiler warning. */ |
137 | 137 | ||
138 | if (0 != strcmp ("PUT", method)) | 138 | if (0 != strcmp ("PUT", method)) |
139 | return MHD_NO; /* unexpected method */ | 139 | return MHD_NO; /* unexpected method */ |
140 | if ((*done) == 0) | 140 | if ((*done) == 0) |
141 | { | ||
142 | if (*upload_data_size != 8) | ||
143 | return MHD_YES; /* not yet ready */ | ||
144 | if (0 == memcmp (upload_data, "Hello123", 8)) | ||
145 | { | ||
146 | *upload_data_size = 0; | ||
147 | } | ||
148 | else | ||
141 | { | 149 | { |
142 | if (*upload_data_size != 8) | 150 | printf ("Invalid upload data `%8s'!\n", upload_data); |
143 | return MHD_YES; /* not yet ready */ | 151 | return MHD_NO; |
144 | if (0 == memcmp (upload_data, "Hello123", 8)) | ||
145 | { | ||
146 | *upload_data_size = 0; | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | printf ("Invalid upload data `%8s'!\n", upload_data); | ||
151 | return MHD_NO; | ||
152 | } | ||
153 | *done = 1; | ||
154 | return MHD_YES; | ||
155 | } | 152 | } |
153 | *done = 1; | ||
154 | return MHD_YES; | ||
155 | } | ||
156 | response = MHD_create_response_from_buffer (strlen (url), | 156 | response = MHD_create_response_from_buffer (strlen (url), |
157 | (void *) url, | 157 | (void *) url, |
158 | MHD_RESPMEM_MUST_COPY); | 158 | MHD_RESPMEM_MUST_COPY); |
159 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 159 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
160 | MHD_destroy_response (response); | 160 | MHD_destroy_response (response); |
161 | return ret; | 161 | return ret; |
@@ -177,11 +177,11 @@ testWithoutTimeout () | |||
177 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 177 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
178 | port = 0; | 178 | port = 0; |
179 | else | 179 | else |
180 | { | 180 | { |
181 | port = 1500; | 181 | port = 1500; |
182 | if (oneone) | 182 | if (oneone) |
183 | port += 5; | 183 | port += 5; |
184 | } | 184 | } |
185 | 185 | ||
186 | cbc.buf = buf; | 186 | cbc.buf = buf; |
187 | cbc.size = 2048; | 187 | cbc.size = 2048; |
@@ -190,21 +190,24 @@ testWithoutTimeout () | |||
190 | port, | 190 | port, |
191 | NULL, NULL, &ahc_echo, &done_flag, | 191 | NULL, NULL, &ahc_echo, &done_flag, |
192 | MHD_OPTION_CONNECTION_TIMEOUT, 2, | 192 | MHD_OPTION_CONNECTION_TIMEOUT, 2, |
193 | MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, &withTimeout, | 193 | MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, |
194 | &withTimeout, | ||
194 | MHD_OPTION_END); | 195 | MHD_OPTION_END); |
195 | if (d == NULL) | 196 | if (d == NULL) |
196 | return 1; | 197 | return 1; |
197 | if (0 == port) | 198 | if (0 == port) |
199 | { | ||
200 | const union MHD_DaemonInfo *dinfo; | ||
201 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
202 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
198 | { | 203 | { |
199 | const union MHD_DaemonInfo *dinfo; | 204 | MHD_stop_daemon (d); return 32; |
200 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
201 | if (NULL == dinfo || 0 == dinfo->port) | ||
202 | { MHD_stop_daemon (d); return 32; } | ||
203 | port = (int)dinfo->port; | ||
204 | } | 205 | } |
206 | port = (int) dinfo->port; | ||
207 | } | ||
205 | c = curl_easy_init (); | 208 | c = curl_easy_init (); |
206 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 209 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
207 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 210 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
208 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 211 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
209 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 212 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
210 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | 213 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); |
@@ -223,11 +226,11 @@ testWithoutTimeout () | |||
223 | * crashes on my system! */ | 226 | * crashes on my system! */ |
224 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 227 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
225 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 228 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
226 | { | 229 | { |
227 | curl_easy_cleanup (c); | 230 | curl_easy_cleanup (c); |
228 | MHD_stop_daemon (d); | 231 | MHD_stop_daemon (d); |
229 | return 2; | 232 | return 2; |
230 | } | 233 | } |
231 | curl_easy_cleanup (c); | 234 | curl_easy_cleanup (c); |
232 | MHD_stop_daemon (d); | 235 | MHD_stop_daemon (d); |
233 | if (cbc.pos != strlen ("/hello_world")) | 236 | if (cbc.pos != strlen ("/hello_world")) |
@@ -251,11 +254,11 @@ testWithTimeout () | |||
251 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 254 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
252 | port = 0; | 255 | port = 0; |
253 | else | 256 | else |
254 | { | 257 | { |
255 | port = 1501; | 258 | port = 1501; |
256 | if (oneone) | 259 | if (oneone) |
257 | port += 5; | 260 | port += 5; |
258 | } | 261 | } |
259 | 262 | ||
260 | cbc.buf = buf; | 263 | cbc.buf = buf; |
261 | cbc.size = 2048; | 264 | cbc.size = 2048; |
@@ -264,21 +267,24 @@ testWithTimeout () | |||
264 | port, | 267 | port, |
265 | NULL, NULL, &ahc_echo, &done_flag, | 268 | NULL, NULL, &ahc_echo, &done_flag, |
266 | MHD_OPTION_CONNECTION_TIMEOUT, 2, | 269 | MHD_OPTION_CONNECTION_TIMEOUT, 2, |
267 | MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, &withoutTimeout, | 270 | MHD_OPTION_NOTIFY_COMPLETED, &termination_cb, |
271 | &withoutTimeout, | ||
268 | MHD_OPTION_END); | 272 | MHD_OPTION_END); |
269 | if (d == NULL) | 273 | if (d == NULL) |
270 | return 16; | 274 | return 16; |
271 | if (0 == port) | 275 | if (0 == port) |
276 | { | ||
277 | const union MHD_DaemonInfo *dinfo; | ||
278 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
279 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
272 | { | 280 | { |
273 | const union MHD_DaemonInfo *dinfo; | 281 | MHD_stop_daemon (d); return 32; |
274 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
275 | if (NULL == dinfo || 0 == dinfo->port) | ||
276 | { MHD_stop_daemon (d); return 32; } | ||
277 | port = (int)dinfo->port; | ||
278 | } | 282 | } |
283 | port = (int) dinfo->port; | ||
284 | } | ||
279 | c = curl_easy_init (); | 285 | c = curl_easy_init (); |
280 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 286 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
281 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 287 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
282 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 288 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
283 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 289 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
284 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer_fail); | 290 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer_fail); |
@@ -297,16 +303,16 @@ testWithTimeout () | |||
297 | * crashes on my system! */ | 303 | * crashes on my system! */ |
298 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 304 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
299 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 305 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
300 | { | 306 | { |
301 | curl_easy_cleanup (c); | 307 | curl_easy_cleanup (c); |
302 | MHD_stop_daemon (d); | 308 | MHD_stop_daemon (d); |
303 | if (errornum == CURLE_GOT_NOTHING) | 309 | if (errornum == CURLE_GOT_NOTHING) |
304 | /* mhd had the timeout */ | 310 | /* mhd had the timeout */ |
305 | return 0; | 311 | return 0; |
306 | else | 312 | else |
307 | /* curl had the timeout first */ | 313 | /* curl had the timeout first */ |
308 | return 32; | 314 | return 32; |
309 | } | 315 | } |
310 | curl_easy_cleanup (c); | 316 | curl_easy_cleanup (c); |
311 | MHD_stop_daemon (d); | 317 | MHD_stop_daemon (d); |
312 | return 64; | 318 | return 64; |
@@ -317,9 +323,9 @@ int | |||
317 | main (int argc, char *const *argv) | 323 | main (int argc, char *const *argv) |
318 | { | 324 | { |
319 | unsigned int errorCount = 0; | 325 | unsigned int errorCount = 0; |
320 | (void)argc; /* Unused. Silent compiler warning. */ | 326 | (void) argc; /* Unused. Silent compiler warning. */ |
321 | 327 | ||
322 | if (NULL == argv || 0 == argv[0]) | 328 | if ((NULL == argv)||(0 == argv[0])) |
323 | return 99; | 329 | return 99; |
324 | oneone = has_in_name (argv[0], "11"); | 330 | oneone = has_in_name (argv[0], "11"); |
325 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 331 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
@@ -327,9 +333,9 @@ main (int argc, char *const *argv) | |||
327 | errorCount += testWithoutTimeout (); | 333 | errorCount += testWithoutTimeout (); |
328 | errorCount += testWithTimeout (); | 334 | errorCount += testWithTimeout (); |
329 | if (errorCount != 0) | 335 | if (errorCount != 0) |
330 | fprintf (stderr, | 336 | fprintf (stderr, |
331 | "Error during test execution (code: %u)\n", | 337 | "Error during test execution (code: %u)\n", |
332 | errorCount); | 338 | errorCount); |
333 | curl_global_cleanup (); | 339 | curl_global_cleanup (); |
334 | if ((withTimeout == 0) && (withoutTimeout == 0)) | 340 | if ((withTimeout == 0) && (withoutTimeout == 0)) |
335 | return 0; | 341 | return 0; |
diff --git a/src/testcurl/test_urlparse.c b/src/testcurl/test_urlparse.c index d7c133ae..f1bab3d1 100644 --- a/src/testcurl/test_urlparse.c +++ b/src/testcurl/test_urlparse.c | |||
@@ -68,13 +68,13 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
68 | return size * nmemb; | 68 | return size * nmemb; |
69 | } | 69 | } |
70 | 70 | ||
71 | static int | 71 | static int |
72 | test_values (void *cls, | 72 | test_values (void *cls, |
73 | enum MHD_ValueKind kind, | 73 | enum MHD_ValueKind kind, |
74 | const char *key, | 74 | const char *key, |
75 | const char *value) | 75 | const char *value) |
76 | { | 76 | { |
77 | (void)cls;(void)kind; /* Unused. Silent compiler warning. */ | 77 | (void) cls; (void) kind; /* Unused. Silent compiler warning. */ |
78 | if ( (0 == strcmp (key, "a")) && | 78 | if ( (0 == strcmp (key, "a")) && |
79 | (0 == strcmp (value, "b")) ) | 79 | (0 == strcmp (value, "b")) ) |
80 | matches += 1; | 80 | matches += 1; |
@@ -100,23 +100,23 @@ ahc_echo (void *cls, | |||
100 | const char *me = cls; | 100 | const char *me = cls; |
101 | struct MHD_Response *response; | 101 | struct MHD_Response *response; |
102 | int ret; | 102 | int ret; |
103 | (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 103 | (void) version; (void) upload_data; (void) upload_data_size; /* Unused. Silent compiler warning. */ |
104 | 104 | ||
105 | if (0 != strcmp (me, method)) | 105 | if (0 != strcmp (me, method)) |
106 | return MHD_NO; /* unexpected method */ | 106 | return MHD_NO; /* unexpected method */ |
107 | if (&ptr != *unused) | 107 | if (&ptr != *unused) |
108 | { | 108 | { |
109 | *unused = &ptr; | 109 | *unused = &ptr; |
110 | return MHD_YES; | 110 | return MHD_YES; |
111 | } | 111 | } |
112 | MHD_get_connection_values (connection, | 112 | MHD_get_connection_values (connection, |
113 | MHD_GET_ARGUMENT_KIND, | 113 | MHD_GET_ARGUMENT_KIND, |
114 | &test_values, | 114 | &test_values, |
115 | NULL); | 115 | NULL); |
116 | *unused = NULL; | 116 | *unused = NULL; |
117 | response = MHD_create_response_from_buffer (strlen (url), | 117 | response = MHD_create_response_from_buffer (strlen (url), |
118 | (void *) url, | 118 | (void *) url, |
119 | MHD_RESPMEM_MUST_COPY); | 119 | MHD_RESPMEM_MUST_COPY); |
120 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 120 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
121 | MHD_destroy_response (response); | 121 | MHD_destroy_response (response); |
122 | if (ret == MHD_NO) | 122 | if (ret == MHD_NO) |
@@ -138,30 +138,33 @@ testInternalGet (int poll_flag) | |||
138 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 138 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
139 | port = 0; | 139 | port = 0; |
140 | else | 140 | else |
141 | { | 141 | { |
142 | port = 1510; | 142 | port = 1510; |
143 | if (oneone) | 143 | if (oneone) |
144 | port += 5; | 144 | port += 5; |
145 | } | 145 | } |
146 | 146 | ||
147 | cbc.buf = buf; | 147 | cbc.buf = buf; |
148 | cbc.size = 2048; | 148 | cbc.size = 2048; |
149 | cbc.pos = 0; | 149 | cbc.pos = 0; |
150 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 150 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
151 | | poll_flag, | ||
151 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 152 | port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
152 | if (d == NULL) | 153 | if (d == NULL) |
153 | return 1; | 154 | return 1; |
154 | if (0 == port) | 155 | if (0 == port) |
156 | { | ||
157 | const union MHD_DaemonInfo *dinfo; | ||
158 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
159 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
155 | { | 160 | { |
156 | const union MHD_DaemonInfo *dinfo; | 161 | 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 | } | 162 | } |
163 | port = (int) dinfo->port; | ||
164 | } | ||
162 | c = curl_easy_init (); | 165 | c = curl_easy_init (); |
163 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world?a=b&c=&d"); | 166 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world?a=b&c=&d"); |
164 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 167 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
165 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 168 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
166 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 169 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
167 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 170 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -176,14 +179,14 @@ testInternalGet (int poll_flag) | |||
176 | crashes on my system!*/ | 179 | crashes on my system!*/ |
177 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 180 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
178 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 181 | if (CURLE_OK != (errornum = curl_easy_perform (c))) |
179 | { | 182 | { |
180 | fprintf (stderr, | 183 | fprintf (stderr, |
181 | "curl_easy_perform failed: `%s'\n", | 184 | "curl_easy_perform failed: `%s'\n", |
182 | curl_easy_strerror (errornum)); | 185 | curl_easy_strerror (errornum)); |
183 | curl_easy_cleanup (c); | 186 | curl_easy_cleanup (c); |
184 | MHD_stop_daemon (d); | 187 | MHD_stop_daemon (d); |
185 | return 2; | 188 | return 2; |
186 | } | 189 | } |
187 | curl_easy_cleanup (c); | 190 | curl_easy_cleanup (c); |
188 | MHD_stop_daemon (d); | 191 | MHD_stop_daemon (d); |
189 | if (cbc.pos != strlen ("/hello_world")) | 192 | if (cbc.pos != strlen ("/hello_world")) |
@@ -200,9 +203,9 @@ int | |||
200 | main (int argc, char *const *argv) | 203 | main (int argc, char *const *argv) |
201 | { | 204 | { |
202 | unsigned int errorCount = 0; | 205 | unsigned int errorCount = 0; |
203 | (void)argc; /* Unused. Silent compiler warning. */ | 206 | (void) argc; /* Unused. Silent compiler warning. */ |
204 | 207 | ||
205 | if (NULL == argv || 0 == argv[0]) | 208 | if ((NULL == argv)||(0 == argv[0])) |
206 | return 99; | 209 | return 99; |
207 | oneone = has_in_name (argv[0], "11"); | 210 | oneone = has_in_name (argv[0], "11"); |
208 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 211 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |