aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_quiesce.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_quiesce.c')
-rw-r--r--src/testcurl/test_quiesce.c57
1 files changed, 38 insertions, 19 deletions
diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c
index 068c2364..8a426a61 100644
--- a/src/testcurl/test_quiesce.c
+++ b/src/testcurl/test_quiesce.c
@@ -26,13 +26,13 @@
26 26
27#include "MHD_config.h" 27#include "MHD_config.h"
28#include "platform.h" 28#include "platform.h"
29#include "platform_interface.h"
29#include <curl/curl.h> 30#include <curl/curl.h>
30#include <microhttpd.h> 31#include <microhttpd.h>
31#include <stdlib.h> 32#include <stdlib.h>
32#include <string.h> 33#include <string.h>
33#include <time.h> 34#include <time.h>
34#include <sys/types.h> 35#include <sys/types.h>
35#include <sys/wait.h>
36 36
37#ifndef WINDOWS 37#ifndef WINDOWS
38#include <unistd.h> 38#include <unistd.h>
@@ -105,25 +105,27 @@ request_completed (void *cls, struct MHD_Connection *connection,
105} 105}
106 106
107 107
108static void 108static void *
109ServeOneRequest(int fd) 109ServeOneRequest(void *param)
110{ 110{
111 struct MHD_Daemon *d; 111 struct MHD_Daemon *d;
112 fd_set rs; 112 fd_set rs;
113 fd_set ws; 113 fd_set ws;
114 fd_set es; 114 fd_set es;
115 MHD_socket max; 115 MHD_socket fd, max;
116 time_t start; 116 time_t start;
117 struct timeval tv; 117 struct timeval tv;
118 int done = 0; 118 int done = 0;
119 119
120 fd = (MHD_socket) param;
121
120 d = MHD_start_daemon (MHD_USE_DEBUG, 122 d = MHD_start_daemon (MHD_USE_DEBUG,
121 1082, NULL, NULL, &ahc_echo, "GET", 123 1082, NULL, NULL, &ahc_echo, "GET",
122 MHD_OPTION_LISTEN_SOCKET, fd, 124 MHD_OPTION_LISTEN_SOCKET, fd,
123 MHD_OPTION_NOTIFY_COMPLETED, &request_completed, &done, 125 MHD_OPTION_NOTIFY_COMPLETED, &request_completed, &done,
124 MHD_OPTION_END); 126 MHD_OPTION_END);
125 if (d == NULL) 127 if (d == NULL)
126 _exit(1); 128 return "MHD_start_daemon() failed";
127 129
128 start = time (NULL); 130 start = time (NULL);
129 while ((time (NULL) - start < 5) && done == 0) 131 while ((time (NULL) - start < 5) && done == 0)
@@ -135,17 +137,17 @@ ServeOneRequest(int fd)
135 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 137 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
136 { 138 {
137 MHD_stop_daemon (d); 139 MHD_stop_daemon (d);
138 close(fd); 140 MHD_socket_close_(fd);
139 _exit(4096); 141 return "MHD_get_fdset() failed";
140 } 142 }
141 tv.tv_sec = 0; 143 tv.tv_sec = 0;
142 tv.tv_usec = 1000; 144 tv.tv_usec = 1000;
143 select (max + 1, &rs, &ws, &es, &tv); 145 MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv);
144 MHD_run (d); 146 MHD_run (d);
145 } 147 }
146 MHD_stop_daemon (d); 148 MHD_stop_daemon (d);
147 close(fd); 149 MHD_socket_close_(fd);
148 _exit(0); 150 return NULL;
149} 151}
150 152
151 153
@@ -183,6 +185,8 @@ testGet (int type, int pool_count, int poll_flag)
183 struct CBC cbc; 185 struct CBC cbc;
184 CURLcode errornum; 186 CURLcode errornum;
185 MHD_socket fd; 187 MHD_socket fd;
188 pthread_t thrd;
189 const char *thrdRet;
186 190
187 cbc.buf = buf; 191 cbc.buf = buf;
188 cbc.size = 2048; 192 cbc.size = 2048;
@@ -223,10 +227,12 @@ testGet (int type, int pool_count, int poll_flag)
223 } 227 }
224 228
225 fd = MHD_quiesce_daemon (d); 229 fd = MHD_quiesce_daemon (d);
226 if (fork() == 0) 230 if (0 != pthread_create(&thrd, NULL, ServeOneRequest, (void*)fd))
227 { 231 {
228 ServeOneRequest (fd); 232 fprintf (stderr, "pthread_create failed\n");
229 _exit(1); 233 curl_easy_cleanup (c);
234 MHD_stop_daemon (d);
235 return 16;
230 } 236 }
231 237
232 cbc.pos = 0; 238 cbc.pos = 0;
@@ -240,14 +246,27 @@ testGet (int type, int pool_count, int poll_flag)
240 return 2; 246 return 2;
241 } 247 }
242 248
243 waitpid(-1, NULL, 0); 249 if (0 != pthread_join(thrd, (void**)&thrdRet))
250 {
251 fprintf (stderr, "pthread_join failed\n");
252 curl_easy_cleanup (c);
253 MHD_stop_daemon (d);
254 return 16;
255 }
256 if (NULL != thrdRet)
257 {
258 fprintf (stderr, "ServeOneRequest() error: %s\n", thrdRet);
259 curl_easy_cleanup (c);
260 MHD_stop_daemon (d);
261 return 16;
262 }
244 263
245 if (cbc.pos != strlen ("/hello_world")) 264 if (cbc.pos != strlen ("/hello_world"))
246 { 265 {
247 fprintf(stderr, "%s\n", cbc.buf); 266 fprintf(stderr, "%s\n", cbc.buf);
248 curl_easy_cleanup (c); 267 curl_easy_cleanup (c);
249 MHD_stop_daemon (d); 268 MHD_stop_daemon (d);
250 close(fd); 269 MHD_socket_close_(fd);
251 return 4; 270 return 4;
252 } 271 }
253 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 272 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
@@ -255,7 +274,7 @@ testGet (int type, int pool_count, int poll_flag)
255 fprintf(stderr, "%s\n", cbc.buf); 274 fprintf(stderr, "%s\n", cbc.buf);
256 curl_easy_cleanup (c); 275 curl_easy_cleanup (c);
257 MHD_stop_daemon (d); 276 MHD_stop_daemon (d);
258 close(fd); 277 MHD_socket_close_(fd);
259 return 8; 278 return 8;
260 } 279 }
261 280
@@ -267,12 +286,12 @@ testGet (int type, int pool_count, int poll_flag)
267 fprintf (stderr, "curl_easy_perform should fail\n"); 286 fprintf (stderr, "curl_easy_perform should fail\n");
268 curl_easy_cleanup (c); 287 curl_easy_cleanup (c);
269 MHD_stop_daemon (d); 288 MHD_stop_daemon (d);
270 close(fd); 289 MHD_socket_close_(fd);
271 return 2; 290 return 2;
272 } 291 }
273 curl_easy_cleanup (c); 292 curl_easy_cleanup (c);
274 MHD_stop_daemon (d); 293 MHD_stop_daemon (d);
275 close(fd); 294 MHD_socket_close_(fd);
276 295
277 return 0; 296 return 0;
278} 297}
@@ -386,7 +405,7 @@ testExternalGet ()
386 fd = MHD_quiesce_daemon(d); 405 fd = MHD_quiesce_daemon(d);
387 if (MHD_INVALID_SOCKET == fd) 406 if (MHD_INVALID_SOCKET == fd)
388 abort (); 407 abort ();
389 close (fd); 408 MHD_socket_close_ (fd);
390 c = setupCURL (&cbc); 409 c = setupCURL (&cbc);
391 multi = curl_multi_init (); 410 multi = curl_multi_init ();
392 mret = curl_multi_add_handle (multi, c); 411 mret = curl_multi_add_handle (multi, c);