1CURLOPT_SHARE(3)           curl_easy_setopt options           CURLOPT_SHARE(3)
2
3
4

NAME

6       CURLOPT_SHARE - share handle to use
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SHARE, CURLSH *share);
12

DESCRIPTION

14       Pass  a  share  handle  as a parameter. The share handle must have been
15       created by a previous call to curl_share_init(3). Setting this  option,
16       will  make this curl handle use the data from the shared handle instead
17       of keeping the data to itself. This enables  several  curl  handles  to
18       share  data.  If  the  curl handles are used simultaneously in multiple
19       threads, you MUST use the locking methods  in  the  share  handle.  See
20       curl_share_setopt(3) for details.
21
22       If  you add a share that is set to share cookies, your easy handle will
23       use that cookie cache and get the cookie engine enabled.  If  you  stop
24       sharing  an  object that was using cookies (or change to another object
25       that does not share cookies), the easy handle will get its  cookie  en‐
26       gine disabled.
27
28       Data  that  the share object is not set to share will be dealt with the
29       usual way, as if no share was used.
30
31       Set this option to NULL again to stop using that share object.
32

DEFAULT

34       NULL
35

PROTOCOLS

37       All
38

EXAMPLE

40       CURL *curl = curl_easy_init();
41       CURL *curl2 = curl_easy_init(); /* a second handle */
42       if(curl) {
43         CURLSH *shobject = curl_share_init();
44         curl_share_setopt(shobject, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
45
46         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
47         curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
48         curl_easy_setopt(curl, CURLOPT_SHARE, shobject);
49         ret = curl_easy_perform(curl);
50         curl_easy_cleanup(curl);
51
52         /* the second handle shares cookies from the first */
53         curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/second");
54         curl_easy_setopt(curl2, CURLOPT_COOKIEFILE, "");
55         curl_easy_setopt(curl2, CURLOPT_SHARE, shobject);
56         ret = curl_easy_perform(curl2);
57         curl_easy_cleanup(curl2);
58
59         curl_share_cleanup(shobject);
60       }
61

AVAILABILITY

63       Always
64

RETURN VALUE

66       Returns CURLE_OK
67

SEE ALSO

69       CURLOPT_COOKIE(3),
70
71
72
73libcurl 8.0.1                  January 02, 2023               CURLOPT_SHARE(3)
Impressum