1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2013, 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, curl_lock_access laccess,
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 if ((curl = curl_easy_init()) == NULL) {
105 fprintf(stderr, "curl_easy_init() failed\n");
109 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
110 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
111 curl_easy_setopt(curl, CURLOPT_URL, tdata->url);
112 printf( "CURLOPT_SHARE\n" );
113 curl_easy_setopt(curl, CURLOPT_SHARE, tdata->share);
115 printf( "PERFORM\n" );
116 code = curl_easy_perform(curl);
117 if( code != CURLE_OK ) {
118 fprintf(stderr, "perform url '%s' repeat %d failed, curlcode %d\n",
119 tdata->url, i, (int)code);
122 printf( "CLEANUP\n" );
123 curl_easy_cleanup(curl);
132 CURLSHcode scode = CURLSHE_OK;
138 struct userdata user;
140 user.text = (char *)"Pigs in space";
143 printf( "GLOBAL_INIT\n" );
144 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
145 fprintf(stderr, "curl_global_init() failed\n");
146 return TEST_ERR_MAJOR_BAD;
150 printf( "SHARE_INIT\n" );
151 if ((share = curl_share_init()) == NULL) {
152 fprintf(stderr, "curl_share_init() failed\n");
153 curl_global_cleanup();
154 return TEST_ERR_MAJOR_BAD;
157 if ( CURLSHE_OK == scode ) {
158 printf( "CURLSHOPT_LOCKFUNC\n" );
159 scode = curl_share_setopt( share, CURLSHOPT_LOCKFUNC, my_lock);
161 if ( CURLSHE_OK == scode ) {
162 printf( "CURLSHOPT_UNLOCKFUNC\n" );
163 scode = curl_share_setopt( share, CURLSHOPT_UNLOCKFUNC, my_unlock);
165 if ( CURLSHE_OK == scode ) {
166 printf( "CURLSHOPT_USERDATA\n" );
167 scode = curl_share_setopt( share, CURLSHOPT_USERDATA, &user);
169 if ( CURLSHE_OK == scode ) {
170 printf( "CURL_LOCK_DATA_SSL_SESSION\n" );
171 scode = curl_share_setopt( share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
174 if ( CURLSHE_OK != scode ) {
175 fprintf(stderr, "curl_share_setopt() failed\n");
176 curl_share_cleanup(share);
177 curl_global_cleanup();
178 return TEST_ERR_MAJOR_BAD;
185 for (i=1; i<=THREADS; i++ ) {
187 /* set thread data */
191 /* simulate thread, direct call of "thread" function */
192 printf( "*** run %d\n",i );
197 /* fetch a another one */
198 printf( "*** run %d\n", i );
199 if ((curl = curl_easy_init()) == NULL) {
200 fprintf(stderr, "curl_easy_init() failed\n");
201 curl_share_cleanup(share);
202 curl_global_cleanup();
203 return TEST_ERR_MAJOR_BAD;
207 test_setopt( curl, CURLOPT_URL, url );
208 printf( "CURLOPT_SHARE\n" );
209 test_setopt( curl, CURLOPT_SHARE, share );
211 printf( "PERFORM\n" );
212 curl_easy_perform( curl );
214 /* try to free share, expect to fail because share is in use*/
215 printf( "try SHARE_CLEANUP...\n" );
216 scode = curl_share_cleanup( share );
217 if ( scode==CURLSHE_OK )
219 fprintf(stderr, "curl_share_cleanup succeed but error expected\n");
222 printf( "SHARE_CLEANUP failed, correct\n" );
227 /* clean up last handle */
228 printf( "CLEANUP\n" );
229 curl_easy_cleanup( curl );
232 printf( "SHARE_CLEANUP\n" );
233 scode = curl_share_cleanup( share );
234 if ( scode!=CURLSHE_OK )
235 fprintf(stderr, "curl_share_cleanup failed, code errno %d\n",
238 printf( "GLOBAL_CLEANUP\n" );
239 curl_global_cleanup();