1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
27 /* struct containing data of a thread */
39 static void my_lock(CURL *handle, curl_lock_data data,
40 curl_lock_access laccess, void *useptr)
43 struct userdata *user = (struct userdata *)useptr;
49 case CURL_LOCK_DATA_SHARE:
52 case CURL_LOCK_DATA_DNS:
55 case CURL_LOCK_DATA_COOKIE:
58 case CURL_LOCK_DATA_SSL_SESSION:
62 fprintf(stderr, "lock: no such data: %d\n", (int)data);
65 printf("lock: %-6s [%s]: %d\n", what, user->text, user->counter);
70 static void my_unlock(CURL *handle, curl_lock_data data, void *useptr)
73 struct userdata *user = (struct userdata *)useptr;
76 case CURL_LOCK_DATA_SHARE:
79 case CURL_LOCK_DATA_DNS:
82 case CURL_LOCK_DATA_COOKIE:
85 case CURL_LOCK_DATA_SSL_SESSION:
89 fprintf(stderr, "unlock: no such data: %d\n", (int)data);
92 printf("unlock: %-6s [%s]: %d\n", what, user->text, user->counter);
96 /* the dummy thread function */
97 static void *fire(void *ptr)
100 struct Tdata *tdata = (struct Tdata*)ptr;
104 curl = curl_easy_init();
106 fprintf(stderr, "curl_easy_init() failed\n");
110 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
111 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
112 curl_easy_setopt(curl, CURLOPT_URL, tdata->url);
113 printf("CURLOPT_SHARE\n");
114 curl_easy_setopt(curl, CURLOPT_SHARE, tdata->share);
117 code = curl_easy_perform(curl);
118 if(code != CURLE_OK) {
119 fprintf(stderr, "perform url '%s' repeat %d failed, curlcode %d\n",
120 tdata->url, i, (int)code);
124 curl_easy_cleanup(curl);
133 CURLSHcode scode = CURLSHE_OK;
139 struct userdata user;
141 user.text = (char *)"Pigs in space";
144 printf("GLOBAL_INIT\n");
145 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
146 fprintf(stderr, "curl_global_init() failed\n");
147 return TEST_ERR_MAJOR_BAD;
151 printf("SHARE_INIT\n");
152 share = curl_share_init();
154 fprintf(stderr, "curl_share_init() failed\n");
155 curl_global_cleanup();
156 return TEST_ERR_MAJOR_BAD;
159 if(CURLSHE_OK == scode) {
160 printf("CURLSHOPT_LOCKFUNC\n");
161 scode = curl_share_setopt(share, CURLSHOPT_LOCKFUNC, my_lock);
163 if(CURLSHE_OK == scode) {
164 printf("CURLSHOPT_UNLOCKFUNC\n");
165 scode = curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, my_unlock);
167 if(CURLSHE_OK == scode) {
168 printf("CURLSHOPT_USERDATA\n");
169 scode = curl_share_setopt(share, CURLSHOPT_USERDATA, &user);
171 if(CURLSHE_OK == scode) {
172 printf("CURL_LOCK_DATA_SSL_SESSION\n");
173 scode = curl_share_setopt(share, CURLSHOPT_SHARE,
174 CURL_LOCK_DATA_SSL_SESSION);
177 if(CURLSHE_OK != scode) {
178 fprintf(stderr, "curl_share_setopt() failed\n");
179 curl_share_cleanup(share);
180 curl_global_cleanup();
181 return TEST_ERR_MAJOR_BAD;
188 for(i=1; i<=THREADS; i++) {
190 /* set thread data */
194 /* simulate thread, direct call of "thread" function */
195 printf("*** run %d\n",i);
200 /* fetch a another one */
201 printf("*** run %d\n", i);
202 curl = curl_easy_init();
204 fprintf(stderr, "curl_easy_init() failed\n");
205 curl_share_cleanup(share);
206 curl_global_cleanup();
207 return TEST_ERR_MAJOR_BAD;
211 test_setopt(curl, CURLOPT_URL, url);
212 printf("CURLOPT_SHARE\n");
213 test_setopt(curl, CURLOPT_SHARE, share);
216 curl_easy_perform(curl);
218 /* try to free share, expect to fail because share is in use*/
219 printf("try SHARE_CLEANUP...\n");
220 scode = curl_share_cleanup(share);
221 if(scode==CURLSHE_OK) {
222 fprintf(stderr, "curl_share_cleanup succeed but error expected\n");
226 printf("SHARE_CLEANUP failed, correct\n");
231 /* clean up last handle */
233 curl_easy_cleanup(curl);
236 printf("SHARE_CLEANUP\n");
237 scode = curl_share_cleanup(share);
238 if(scode!=CURLSHE_OK)
239 fprintf(stderr, "curl_share_cleanup failed, code errno %d\n",
242 printf("GLOBAL_CLEANUP\n");
243 curl_global_cleanup();