aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_concurrent_stop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_concurrent_stop.c')
-rw-r--r--src/testcurl/test_concurrent_stop.c126
1 files changed, 69 insertions, 57 deletions
diff --git a/src/testcurl/test_concurrent_stop.c b/src/testcurl/test_concurrent_stop.c
index 88839ffd..1420b7c8 100644
--- a/src/testcurl/test_concurrent_stop.c
+++ b/src/testcurl/test_concurrent_stop.c
@@ -30,6 +30,7 @@
30#include <stdlib.h> 30#include <stdlib.h>
31#include <string.h> 31#include <string.h>
32#include <time.h> 32#include <time.h>
33#include <pthread.h>
33#include "gauger.h" 34#include "gauger.h"
34 35
35#ifdef CPU_COUNT 36#ifdef CPU_COUNT
@@ -100,74 +101,85 @@ ahc_echo (void *cls,
100} 101}
101 102
102 103
103static pid_t 104static void *
104do_gets (int port) 105thread_gets (void *param)
105{ 106{
106 pid_t ret;
107 CURL *c; 107 CURL *c;
108 CURLcode errornum; 108 CURLcode errornum;
109 unsigned int i; 109 unsigned int i;
110 char * const url = (char*) param;
111
112 for (i=0;i<ROUNDS;i++)
113 {
114 c = curl_easy_init ();
115 curl_easy_setopt (c, CURLOPT_URL, url);
116 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
117 curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL);
118 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
119 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
120 if (oneone)
121 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
122 else
123 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
124 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
125 /* NOTE: use of CONNECTTIMEOUT without also
126 setting NOSIGNAL results in really weird
127 crashes on my system! */
128 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
129 if (CURLE_OK != (errornum = curl_easy_perform (c)))
130 {
131 curl_easy_cleanup (c);
132 return NULL;
133 }
134 curl_easy_cleanup (c);
135 }
136
137 return NULL;
138}
139
140#ifndef SIGKILL
141#define SIGKILL SIGTERM
142#endif /* ! SIGKILL */
143
144static void *
145do_gets (void * param)
146{
110 unsigned int j; 147 unsigned int j;
111 pid_t par[PAR]; 148 pthread_t par[PAR];
112 char url[64]; 149 char url[64];
150 int port = (int)(intptr_t)param;
113 151
114 sprintf(url, "http://127.0.0.1:%d/hello_world", port); 152 sprintf(url, "http://127.0.0.1:%d/hello_world", port);
115 153
116 ret = fork ();
117 if (ret == -1) abort ();
118 if (ret != 0)
119 return ret;
120 for (j=0;j<PAR;j++) 154 for (j=0;j<PAR;j++)
121 { 155 {
122 par[j] = fork (); 156 if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url))
123 if (par[j] == 0) 157 {
124 { 158 for (j--; j >= 0; j--)
125 for (i=0;i<ROUNDS;i++) 159 pthread_join(par[j], NULL);
126 { 160
127 c = curl_easy_init (); 161 fprintf(stderr, "pthread_create failed.\n");
128 curl_easy_setopt (c, CURLOPT_URL, url); 162 _exit(99);
129 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 163 }
130 curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL);
131 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
132 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
133 if (oneone)
134 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
135 else
136 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
137 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
138 /* NOTE: use of CONNECTTIMEOUT without also
139 setting NOSIGNAL results in really weird
140 crashes on my system! */
141 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
142 if (CURLE_OK != (errornum = curl_easy_perform (c)))
143 {
144 curl_easy_cleanup (c);
145 _exit (1);
146 }
147 curl_easy_cleanup (c);
148 }
149 _exit (0);
150 }
151 } 164 }
152 sleep (1);
153 for (j=0;j<PAR;j++) 165 for (j=0;j<PAR;j++)
154 { 166 {
155 kill (par[j], SIGKILL); 167 pthread_kill(par[j], SIGKILL);
156 waitpid (par[j], NULL, 0); 168 pthread_join(par[j], NULL);
157 } 169 }
158 _exit (0); 170 return NULL;
159} 171}
160 172
161 173
162static void 174pthread_t start_gets(int port)
163join_gets (pid_t pid)
164{ 175{
165 int status; 176 pthread_t tid;
166 177 if (0 != pthread_create(&tid, NULL, &do_gets, (void*)(intptr_t)port))
167 status = 1; 178 {
168 waitpid (pid, &status, 0); 179 fprintf(stderr, "pthread_create failed.\n");
169 if (0 != status) 180 _exit(99);
170 abort (); 181 }
182 return tid;
171} 183}
172 184
173 185
@@ -176,7 +188,7 @@ testMultithreadedGet (int port,
176 int poll_flag) 188 int poll_flag)
177{ 189{
178 struct MHD_Daemon *d; 190 struct MHD_Daemon *d;
179 pid_t p; 191 pthread_t p;
180 192
181 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag, 193 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag,
182 port, 194 port,
@@ -185,10 +197,10 @@ testMultithreadedGet (int port,
185 MHD_OPTION_END); 197 MHD_OPTION_END);
186 if (d == NULL) 198 if (d == NULL)
187 return 16; 199 return 16;
188 p = do_gets (port); 200 p = start_gets (port);
189 sleep (1); 201 sleep (1);
190 MHD_stop_daemon (d); 202 MHD_stop_daemon (d);
191 join_gets (p); 203 pthread_join (p, NULL);
192 return 0; 204 return 0;
193} 205}
194 206
@@ -198,7 +210,7 @@ testMultithreadedPoolGet (int port,
198 int poll_flag) 210 int poll_flag)
199{ 211{
200 struct MHD_Daemon *d; 212 struct MHD_Daemon *d;
201 pid_t p; 213 pthread_t p;
202 214
203 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, 215 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag,
204 port, 216 port,
@@ -208,10 +220,10 @@ testMultithreadedPoolGet (int port,
208 MHD_OPTION_END); 220 MHD_OPTION_END);
209 if (d == NULL) 221 if (d == NULL)
210 return 16; 222 return 16;
211 p = do_gets (port); 223 p = start_gets (port);
212 sleep (1); 224 sleep (1);
213 MHD_stop_daemon (d); 225 MHD_stop_daemon (d);
214 join_gets (p); 226 pthread_join (p, NULL);
215 return 0; 227 return 0;
216} 228}
217 229