diff options
author | Christian Grothoff <christian@grothoff.org> | 2007-06-13 22:24:11 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2007-06-13 22:24:11 +0000 |
commit | 2b07548230e838be2ee82af0afe152abf9a13d13 (patch) | |
tree | ce0a7b8c68e313d31796fa3c907d7d19b10beece /src/daemon/daemontest1.c | |
parent | b6a83f00076a84e9322323031734cadf2930e159 (diff) | |
download | libmicrohttpd-2b07548230e838be2ee82af0afe152abf9a13d13.tar.gz libmicrohttpd-2b07548230e838be2ee82af0afe152abf9a13d13.zip |
using curl properly
Diffstat (limited to 'src/daemon/daemontest1.c')
-rw-r--r-- | src/daemon/daemontest1.c | 78 |
1 files changed, 41 insertions, 37 deletions
diff --git a/src/daemon/daemontest1.c b/src/daemon/daemontest1.c index 34313c78..77abd6c3 100644 --- a/src/daemon/daemontest1.c +++ b/src/daemon/daemontest1.c | |||
@@ -19,14 +19,15 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file daemontest.c | 22 | * @file daemontest1.c |
23 | * @brief Testcase for libmicrohttpd GET operations | 23 | * @brief Testcase for libmicrohttpd GET operations |
24 | * TODO: external select | ||
24 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
25 | */ | 26 | */ |
26 | 27 | ||
27 | #include "config.h" | 28 | #include "config.h" |
28 | #include "curl/curl.h" | 29 | #include <curl/curl.h> |
29 | #include "microhttpd.h" | 30 | #include <microhttpd.h> |
30 | #include <stdlib.h> | 31 | #include <stdlib.h> |
31 | #include <unistd.h> | 32 | #include <unistd.h> |
32 | #include <string.h> | 33 | #include <string.h> |
@@ -92,23 +93,17 @@ static int testInternalGet() { | |||
92 | cbc.size = 2048; | 93 | cbc.size = 2048; |
93 | cbc.pos = 0; | 94 | cbc.pos = 0; |
94 | d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_IPv4 | MHD_USE_DEBUG, | 95 | d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_IPv4 | MHD_USE_DEBUG, |
95 | 1083, | 96 | 1080, |
96 | &apc_all, | 97 | &apc_all, |
97 | NULL, | 98 | NULL, |
98 | &ahc_echo, | 99 | &ahc_echo, |
99 | "GET"); | 100 | "GET"); |
100 | if (d == NULL) | 101 | if (d == NULL) |
101 | return 1; | 102 | return 1; |
102 | |||
103 | if (MHD_run(d) == MHD_NO) { | ||
104 | MHD_stop_daemon(d); | ||
105 | return 2; | ||
106 | } | ||
107 | |||
108 | c = curl_easy_init(); | 103 | c = curl_easy_init(); |
109 | curl_easy_setopt(c, | 104 | curl_easy_setopt(c, |
110 | CURLOPT_URL, | 105 | CURLOPT_URL, |
111 | "http://localhost:1083/hello_world"); | 106 | "http://localhost:1080/hello_world"); |
112 | curl_easy_setopt(c, | 107 | curl_easy_setopt(c, |
113 | CURLOPT_WRITEFUNCTION, | 108 | CURLOPT_WRITEFUNCTION, |
114 | ©Buffer); | 109 | ©Buffer); |
@@ -120,28 +115,33 @@ static int testInternalGet() { | |||
120 | 1); | 115 | 1); |
121 | curl_easy_setopt(c, | 116 | curl_easy_setopt(c, |
122 | CURLOPT_TIMEOUT, | 117 | CURLOPT_TIMEOUT, |
123 | 15L); | 118 | 2L); |
124 | curl_easy_setopt(c, | 119 | curl_easy_setopt(c, |
125 | CURLOPT_CONNECTTIMEOUT, | 120 | CURLOPT_CONNECTTIMEOUT, |
126 | 15L); | 121 | 2L); |
127 | // NOTE: use of CONNECTTIMEOUT without also | 122 | // NOTE: use of CONNECTTIMEOUT without also |
128 | // setting NOSIGNAL results in really weird | 123 | // setting NOSIGNAL results in really weird |
129 | // crashes on my system! | 124 | // crashes on my system! |
130 | curl_easy_setopt(c, | 125 | curl_easy_setopt(c, |
131 | CURLOPT_NOSIGNAL, | 126 | CURLOPT_NOSIGNAL, |
132 | 1); | 127 | 1); |
133 | if (CURLE_OK != curl_easy_perform(c)) | 128 | if (CURLE_OK != curl_easy_perform(c)) { |
134 | return 3; | 129 | curl_easy_cleanup(c); |
135 | 130 | MHD_stop_daemon(d); | |
136 | curl_easy_cleanup(c); | 131 | return 2; |
137 | 132 | } | |
138 | if (cbc.pos != strlen("hello_world")) | 133 | curl_easy_cleanup(c); |
134 | if (cbc.pos != strlen("hello_world")) { | ||
135 | MHD_stop_daemon(d); | ||
139 | return 4; | 136 | return 4; |
137 | } | ||
140 | 138 | ||
141 | if (0 != strncmp("hello_world", | 139 | if (0 != strncmp("hello_world", |
142 | cbc.buf, | 140 | cbc.buf, |
143 | strlen("hello_world"))) | 141 | strlen("hello_world"))) { |
144 | return 5; | 142 | MHD_stop_daemon(d); |
143 | return 8; | ||
144 | } | ||
145 | 145 | ||
146 | MHD_stop_daemon(d); | 146 | MHD_stop_daemon(d); |
147 | 147 | ||
@@ -158,22 +158,17 @@ static int testMultithreadedGet() { | |||
158 | cbc.size = 2048; | 158 | cbc.size = 2048; |
159 | cbc.pos = 0; | 159 | cbc.pos = 0; |
160 | d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv4 | MHD_USE_DEBUG, | 160 | d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv4 | MHD_USE_DEBUG, |
161 | 1084, | 161 | 1081, |
162 | &apc_all, | 162 | &apc_all, |
163 | NULL, | 163 | NULL, |
164 | &ahc_echo, | 164 | &ahc_echo, |
165 | "GET"); | 165 | "GET"); |
166 | if (d == NULL) | 166 | if (d == NULL) |
167 | return 1; | 167 | return 16; |
168 | |||
169 | if(MHD_run(d) == MHD_NO) | ||
170 | return 2; | ||
171 | |||
172 | |||
173 | c = curl_easy_init(); | 168 | c = curl_easy_init(); |
174 | curl_easy_setopt(c, | 169 | curl_easy_setopt(c, |
175 | CURLOPT_URL, | 170 | CURLOPT_URL, |
176 | "http://localhost:1084/hello_world"); | 171 | "http://localhost:1081/hello_world"); |
177 | curl_easy_setopt(c, | 172 | curl_easy_setopt(c, |
178 | CURLOPT_WRITEFUNCTION, | 173 | CURLOPT_WRITEFUNCTION, |
179 | ©Buffer); | 174 | ©Buffer); |
@@ -184,8 +179,11 @@ static int testMultithreadedGet() { | |||
184 | CURLOPT_FAILONERROR, | 179 | CURLOPT_FAILONERROR, |
185 | 1); | 180 | 1); |
186 | curl_easy_setopt(c, | 181 | curl_easy_setopt(c, |
182 | CURLOPT_TIMEOUT, | ||
183 | 2L); | ||
184 | curl_easy_setopt(c, | ||
187 | CURLOPT_CONNECTTIMEOUT, | 185 | CURLOPT_CONNECTTIMEOUT, |
188 | 15L); | 186 | 2L); |
189 | // NOTE: use of CONNECTTIMEOUT without also | 187 | // NOTE: use of CONNECTTIMEOUT without also |
190 | // setting NOSIGNAL results in really weird | 188 | // setting NOSIGNAL results in really weird |
191 | // crashes on my system! | 189 | // crashes on my system! |
@@ -193,16 +191,18 @@ static int testMultithreadedGet() { | |||
193 | CURLOPT_NOSIGNAL, | 191 | CURLOPT_NOSIGNAL, |
194 | 1); | 192 | 1); |
195 | if (CURLE_OK != curl_easy_perform(c)) | 193 | if (CURLE_OK != curl_easy_perform(c)) |
196 | return 3; | 194 | return 32; |
197 | curl_easy_cleanup(c); | 195 | curl_easy_cleanup(c); |
198 | if (cbc.pos != strlen("hello_world")) | 196 | if (cbc.pos != strlen("hello_world")) { |
199 | return 4; | 197 | MHD_stop_daemon(d); |
200 | 198 | return 64; | |
199 | } | ||
201 | if (0 != strncmp("hello_world", | 200 | if (0 != strncmp("hello_world", |
202 | cbc.buf, | 201 | cbc.buf, |
203 | strlen("hello_world"))) | 202 | strlen("hello_world"))) { |
204 | return 5; | 203 | MHD_stop_daemon(d); |
205 | 204 | return 128; | |
205 | } | ||
206 | MHD_stop_daemon(d); | 206 | MHD_stop_daemon(d); |
207 | 207 | ||
208 | return 0; | 208 | return 0; |
@@ -211,11 +211,15 @@ static int testMultithreadedGet() { | |||
211 | int main(int argc, | 211 | int main(int argc, |
212 | char * const * argv) { | 212 | char * const * argv) { |
213 | unsigned int errorCount = 0; | 213 | unsigned int errorCount = 0; |
214 | |||
215 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) | ||
216 | return 2; | ||
214 | errorCount += testInternalGet(); | 217 | errorCount += testInternalGet(); |
215 | errorCount += testMultithreadedGet(); | 218 | errorCount += testMultithreadedGet(); |
216 | if (errorCount != 0) | 219 | if (errorCount != 0) |
217 | fprintf(stderr, | 220 | fprintf(stderr, |
218 | "Error (code: %u)\n", | 221 | "Error (code: %u)\n", |
219 | errorCount); | 222 | errorCount); |
223 | curl_global_cleanup(); | ||
220 | return errorCount != 0; /* 0 == pass */ | 224 | return errorCount != 0; /* 0 == pass */ |
221 | } | 225 | } |