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.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/src/testcurl/test_concurrent_stop.c b/src/testcurl/test_concurrent_stop.c
index 1420b7c8..a7799b64 100644
--- a/src/testcurl/test_concurrent_stop.c
+++ b/src/testcurl/test_concurrent_stop.c
@@ -100,6 +100,16 @@ ahc_echo (void *cls,
100 return ret; 100 return ret;
101} 101}
102 102
103static void
104clean_curl(void * param)
105{
106 if (param)
107 {
108 CURL * const c = *((CURL **)param);
109 if (c)
110 curl_easy_cleanup (c);
111 }
112}
103 113
104static void * 114static void *
105thread_gets (void *param) 115thread_gets (void *param)
@@ -108,39 +118,46 @@ thread_gets (void *param)
108 CURLcode errornum; 118 CURLcode errornum;
109 unsigned int i; 119 unsigned int i;
110 char * const url = (char*) param; 120 char * const url = (char*) param;
121 int pth_olst;
122 if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &pth_olst) ||
123 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &pth_olst) )
124 {
125 fprintf(stderr,
126 "pthread_setcancelstate()/pthread_setcanceltype() failed.\n");
127 _exit(99);
128 }
111 129
112 for (i=0;i<ROUNDS;i++) 130 for (i=0;i<ROUNDS;i++)
113 { 131 {
132 pthread_testcancel();
133 c = NULL;
134 pthread_cleanup_push(clean_curl, (void*)&c);
114 c = curl_easy_init (); 135 c = curl_easy_init ();
136 pthread_testcancel();
115 curl_easy_setopt (c, CURLOPT_URL, url); 137 curl_easy_setopt (c, CURLOPT_URL, url);
116 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 138 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
117 curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL); 139 curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL);
118 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); 140 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
119 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); 141 curl_easy_setopt (c, CURLOPT_TIMEOUT, 5L);
120 if (oneone) 142 if (oneone)
121 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 143 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
122 else 144 else
123 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 145 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
124 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); 146 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L);
125 /* NOTE: use of CONNECTTIMEOUT without also 147 /* NOTE: use of CONNECTTIMEOUT without also
126 setting NOSIGNAL results in really weird 148 setting NOSIGNAL results in really weird
127 crashes on my system! */ 149 crashes on my system! */
128 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); 150 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
129 if (CURLE_OK != (errornum = curl_easy_perform (c))) 151 pthread_testcancel();
130 { 152 errornum = curl_easy_perform (c);
131 curl_easy_cleanup (c); 153 pthread_cleanup_pop (1);
132 return NULL; 154 if (CURLE_OK != errornum)
133 } 155 return NULL;
134 curl_easy_cleanup (c);
135 } 156 }
136 157
137 return NULL; 158 return NULL;
138} 159}
139 160
140#ifndef SIGKILL
141#define SIGKILL SIGTERM
142#endif /* ! SIGKILL */
143
144static void * 161static void *
145do_gets (void * param) 162do_gets (void * param)
146{ 163{
@@ -155,16 +172,19 @@ do_gets (void * param)
155 { 172 {
156 if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url)) 173 if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url))
157 { 174 {
158 for (j--; j >= 0; j--)
159 pthread_join(par[j], NULL);
160
161 fprintf(stderr, "pthread_create failed.\n"); 175 fprintf(stderr, "pthread_create failed.\n");
176 for (j--; j >= 0; j--)
177 {
178 pthread_cancel(par[j]);
179 pthread_join(par[j], NULL);
180 }
162 _exit(99); 181 _exit(99);
163 } 182 }
164 } 183 }
184 sleep (1);
165 for (j=0;j<PAR;j++) 185 for (j=0;j<PAR;j++)
166 { 186 {
167 pthread_kill(par[j], SIGKILL); 187 pthread_cancel(par[j]);
168 pthread_join(par[j], NULL); 188 pthread_join(par[j], NULL);
169 } 189 }
170 return NULL; 190 return NULL;