1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, 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 ***************************************************************************/
25 static void my_lock(CURL *handle, curl_lock_data data,
26 curl_lock_access laccess, void *useptr)
32 printf("-> Mutex lock\n");
35 static void my_unlock(CURL *handle, curl_lock_data data, void *useptr)
40 printf("<- Mutex unlock\n");
47 CURLcode res = CURLE_OK;
51 global_init(CURL_GLOBAL_ALL);
53 share = curl_share_init();
55 fprintf(stderr, "curl_share_init() failed\n");
56 curl_global_cleanup();
57 return TEST_ERR_MAJOR_BAD;
60 curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
61 curl_share_setopt(share, CURLSHOPT_LOCKFUNC, my_lock);
62 curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, my_unlock);
64 /* Loop the transfer and cleanup the handle properly every lap. This will
65 still reuse connections since the pool is in the shared object! */
67 for(i = 0; i < 3; i++) {
68 curl = curl_easy_init();
70 curl_easy_setopt(curl, CURLOPT_URL, URL);
72 /* use the share object */
73 curl_easy_setopt(curl, CURLOPT_SHARE, share);
75 /* Perform the request, res will get the return code */
76 res = curl_easy_perform(curl);
77 /* Check for errors */
79 fprintf(stderr, "curl_easy_perform() failed: %s\n",
80 curl_easy_strerror(res));
83 curl_easy_cleanup(curl);
87 curl_share_cleanup(share);
88 curl_global_cleanup();