diff options
Diffstat (limited to 'src/daemon/daemontest_post_loop.c')
-rw-r--r-- | src/daemon/daemontest_post_loop.c | 79 |
1 files changed, 60 insertions, 19 deletions
diff --git a/src/daemon/daemontest_post_loop.c b/src/daemon/daemontest_post_loop.c index c24dcf52..8fbc1f70 100644 --- a/src/daemon/daemontest_post_loop.c +++ b/src/daemon/daemontest_post_loop.c | |||
@@ -37,7 +37,7 @@ | |||
37 | 37 | ||
38 | #define POST_DATA "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n" | 38 | #define POST_DATA "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n" |
39 | 39 | ||
40 | #define LOOPCOUNT 100 | 40 | #define LOOPCOUNT 10 |
41 | 41 | ||
42 | static int oneone; | 42 | static int oneone; |
43 | 43 | ||
@@ -67,8 +67,9 @@ ahc_echo (void *cls, | |||
67 | const char *method, | 67 | const char *method, |
68 | const char *version, | 68 | const char *version, |
69 | const char *upload_data, unsigned int *upload_data_size, | 69 | const char *upload_data, unsigned int *upload_data_size, |
70 | void **unused) | 70 | void **mptr) |
71 | { | 71 | { |
72 | static int marker; | ||
72 | struct MHD_Response *response; | 73 | struct MHD_Response *response; |
73 | int ret; | 74 | int ret; |
74 | 75 | ||
@@ -77,15 +78,23 @@ ahc_echo (void *cls, | |||
77 | printf ("METHOD: %s\n", method); | 78 | printf ("METHOD: %s\n", method); |
78 | return MHD_NO; /* unexpected method */ | 79 | return MHD_NO; /* unexpected method */ |
79 | } | 80 | } |
81 | if ( (*mptr != NULL) && | ||
82 | (0 == *upload_data_size) ) { | ||
83 | if (*mptr != &marker) | ||
84 | abort(); | ||
85 | response = MHD_create_response_from_data (2, | ||
86 | "OK", | ||
87 | MHD_NO, MHD_NO); | ||
88 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | ||
89 | MHD_destroy_response (response); | ||
90 | *mptr = NULL; | ||
91 | return ret; | ||
92 | } | ||
80 | if (strlen(POST_DATA) != *upload_data_size) | 93 | if (strlen(POST_DATA) != *upload_data_size) |
81 | return MHD_NO; | 94 | return MHD_YES; |
82 | *upload_data_size = 0; | 95 | *upload_data_size = 0; |
83 | response = MHD_create_response_from_data (2, | 96 | *mptr = ▮ |
84 | "OK", | 97 | return MHD_YES; |
85 | MHD_NO, MHD_NO); | ||
86 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | ||
87 | MHD_destroy_response (response); | ||
88 | return ret; | ||
89 | } | 98 | } |
90 | 99 | ||
91 | 100 | ||
@@ -98,18 +107,22 @@ testInternalPost () | |||
98 | struct CBC cbc; | 107 | struct CBC cbc; |
99 | CURLcode errornum; | 108 | CURLcode errornum; |
100 | int i; | 109 | int i; |
110 | char url[1024]; | ||
101 | 111 | ||
102 | cbc.buf = buf; | 112 | cbc.buf = buf; |
103 | cbc.size = 2048; | 113 | cbc.size = 2048; |
104 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, | 114 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, |
105 | 8008, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 115 | 1080, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
106 | if (d == NULL) | 116 | if (d == NULL) |
107 | return 1; | 117 | return 1; |
108 | for (i=0;i<LOOPCOUNT;i++) { | 118 | for (i=0;i<LOOPCOUNT;i++) { |
119 | if (0 == i % 100) | ||
120 | fprintf(stderr, "."); | ||
109 | c = curl_easy_init (); | 121 | c = curl_easy_init (); |
110 | cbc.pos = 0; | 122 | cbc.pos = 0; |
111 | buf[0] = '\0'; | 123 | buf[0] = '\0'; |
112 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); | 124 | sprintf(url, "http://localhost:1080/hw%d", i); |
125 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
113 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 126 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
114 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 127 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
115 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 128 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
@@ -143,6 +156,7 @@ testInternalPost () | |||
143 | } | 156 | } |
144 | } | 157 | } |
145 | MHD_stop_daemon (d); | 158 | MHD_stop_daemon (d); |
159 | fprintf(stderr, "\n"); | ||
146 | return 0; | 160 | return 0; |
147 | } | 161 | } |
148 | 162 | ||
@@ -155,18 +169,22 @@ testMultithreadedPost () | |||
155 | struct CBC cbc; | 169 | struct CBC cbc; |
156 | CURLcode errornum; | 170 | CURLcode errornum; |
157 | int i; | 171 | int i; |
172 | char url[1024]; | ||
158 | 173 | ||
159 | cbc.buf = buf; | 174 | cbc.buf = buf; |
160 | cbc.size = 2048; | 175 | cbc.size = 2048; |
161 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, | 176 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, |
162 | 8009, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); | 177 | 1081, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END); |
163 | if (d == NULL) | 178 | if (d == NULL) |
164 | return 16; | 179 | return 16; |
165 | for (i=0;i<LOOPCOUNT;i++) { | 180 | for (i=0;i<LOOPCOUNT;i++) { |
181 | if (0 == i % 100) | ||
182 | fprintf(stderr, "."); | ||
166 | c = curl_easy_init (); | 183 | c = curl_easy_init (); |
167 | cbc.pos = 0; | 184 | cbc.pos = 0; |
168 | buf[0] = '\0'; | 185 | buf[0] = '\0'; |
169 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); | 186 | sprintf(url, "http://localhost:1081/hw%d", i); |
187 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
170 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 188 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
171 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 189 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
172 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 190 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
@@ -200,6 +218,7 @@ testMultithreadedPost () | |||
200 | } | 218 | } |
201 | } | 219 | } |
202 | MHD_stop_daemon (d); | 220 | MHD_stop_daemon (d); |
221 | fprintf(stderr, "\n"); | ||
203 | return 0; | 222 | return 0; |
204 | } | 223 | } |
205 | 224 | ||
@@ -222,6 +241,9 @@ testExternalPost () | |||
222 | time_t start; | 241 | time_t start; |
223 | struct timeval tv; | 242 | struct timeval tv; |
224 | int i; | 243 | int i; |
244 | unsigned long long timeout; | ||
245 | long ctimeout; | ||
246 | char url[1024]; | ||
225 | 247 | ||
226 | multi = NULL; | 248 | multi = NULL; |
227 | cbc.buf = buf; | 249 | cbc.buf = buf; |
@@ -238,10 +260,13 @@ testExternalPost () | |||
238 | return 512; | 260 | return 512; |
239 | } | 261 | } |
240 | for (i=0;i<LOOPCOUNT;i++) { | 262 | for (i=0;i<LOOPCOUNT;i++) { |
263 | if (0 == i % 100) | ||
264 | fprintf(stderr, "."); | ||
241 | c = curl_easy_init (); | 265 | c = curl_easy_init (); |
242 | cbc.pos = 0; | 266 | cbc.pos = 0; |
243 | buf[0] = '\0'; | 267 | buf[0] = '\0'; |
244 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); | 268 | sprintf(url, "http://localhost:1082/hw%d", i); |
269 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
245 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 270 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
246 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 271 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
247 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); | 272 | curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA); |
@@ -291,8 +316,23 @@ testExternalPost () | |||
291 | MHD_stop_daemon (d); | 316 | MHD_stop_daemon (d); |
292 | return 4096; | 317 | return 4096; |
293 | } | 318 | } |
294 | tv.tv_sec = 0; | 319 | if (MHD_NO == MHD_get_timeout(d, &timeout)) |
295 | tv.tv_usec = 1000; | 320 | timeout = 1000000; /* 1000s == INFTY */ |
321 | if ( (CURLM_OK == curl_multi_timeout(multi, &ctimeout)) && | ||
322 | (ctimeout < timeout) && | ||
323 | (ctimeout >= 0) ) | ||
324 | timeout = ctimeout; | ||
325 | if (timeout > 0) | ||
326 | timeout = 0; /* this line is needed since CURL seems to have | ||
327 | a bug -- it returns a timeout of -1 even though | ||
328 | it should be attempting to connect -- and the | ||
329 | socket for doing the connection is not yet | ||
330 | in the write-set! If the timeout is too high, | ||
331 | no progress would happen! Even a timeout of | ||
332 | 1 would cause my system to be mostly idle instead | ||
333 | of processing at maximum speed... */ | ||
334 | tv.tv_sec = timeout / 1000; | ||
335 | tv.tv_usec = (timeout % 1000) * 1000; | ||
296 | select (max + 1, &rs, &ws, &es, &tv); | 336 | select (max + 1, &rs, &ws, &es, &tv); |
297 | curl_multi_perform (multi, &running); | 337 | curl_multi_perform (multi, &running); |
298 | if (running == 0) | 338 | if (running == 0) |
@@ -308,25 +348,26 @@ testExternalPost () | |||
308 | __FILE__, | 348 | __FILE__, |
309 | __LINE__, curl_easy_strerror (msg->data.result)); | 349 | __LINE__, curl_easy_strerror (msg->data.result)); |
310 | curl_multi_remove_handle (multi, c); | 350 | curl_multi_remove_handle (multi, c); |
311 | curl_multi_cleanup (multi); | ||
312 | curl_easy_cleanup (c); | 351 | curl_easy_cleanup (c); |
313 | c = NULL; | 352 | c = NULL; |
314 | multi = NULL; | ||
315 | } | 353 | } |
316 | } | 354 | } |
317 | MHD_run (d); | 355 | MHD_run (d); |
318 | } | 356 | } |
357 | if (c != NULL) { | ||
319 | curl_multi_remove_handle (multi, c); | 358 | curl_multi_remove_handle (multi, c); |
320 | curl_easy_cleanup (c); | 359 | curl_easy_cleanup (c); |
360 | } | ||
321 | if ( (buf[0] != 'O') || | 361 | if ( (buf[0] != 'O') || |
322 | (buf[1] != 'K') ) { | 362 | (buf[1] != 'K') ) { |
323 | curl_multi_cleanup (multi); | 363 | curl_multi_cleanup (multi); |
324 | MHD_stop_daemon (d); | 364 | MHD_stop_daemon (d); |
325 | return 8192; | 365 | return 8192; |
326 | } | 366 | } |
327 | } | 367 | } |
328 | curl_multi_cleanup (multi); | 368 | curl_multi_cleanup (multi); |
329 | MHD_stop_daemon (d); | 369 | MHD_stop_daemon (d); |
370 | fprintf(stderr, "\n"); | ||
330 | return 0; | 371 | return 0; |
331 | } | 372 | } |
332 | 373 | ||