1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_SHARE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_COOKIE (3)
9  - CURLSHOPT_SHARE (3)
10---
11
12# NAME
13
14CURLOPT_SHARE - share handle to use
15
16# SYNOPSIS
17
18~~~c
19#include <curl/curl.h>
20
21CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SHARE, CURLSH *share);
22~~~
23
24# DESCRIPTION
25
26Pass a *share* handle as a parameter. The share handle must have been
27created by a previous call to curl_share_init(3). Setting this option,
28makes this curl handle use the data from the shared handle instead of keeping
29the data to itself. This enables several curl handles to share data. If the
30curl handles are used simultaneously in multiple threads, you **MUST** use
31the locking methods in the share handle. See curl_share_setopt(3) for
32details.
33
34If you add a share that is set to share cookies, your easy handle uses that
35cookie cache and get the cookie engine enabled. If you stop sharing an object
36that was using cookies (or change to another object that does not share
37cookies), the easy handle gets its cookie engine disabled.
38
39Data that the share object is not set to share is dealt with the usual way, as
40if no share was used.
41
42Set this option to NULL again to stop using that share object.
43
44# DEFAULT
45
46NULL
47
48# PROTOCOLS
49
50All
51
52# EXAMPLE
53
54~~~c
55int main(void)
56{
57  CURL *curl = curl_easy_init();
58  CURL *curl2 = curl_easy_init(); /* a second handle */
59  if(curl) {
60    CURLcode res;
61    CURLSH *shobject = curl_share_init();
62    curl_share_setopt(shobject, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
63
64    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
65    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
66    curl_easy_setopt(curl, CURLOPT_SHARE, shobject);
67    res = curl_easy_perform(curl);
68    curl_easy_cleanup(curl);
69
70    /* the second handle shares cookies from the first */
71    curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/second");
72    curl_easy_setopt(curl2, CURLOPT_COOKIEFILE, "");
73    curl_easy_setopt(curl2, CURLOPT_SHARE, shobject);
74    res = curl_easy_perform(curl2);
75    curl_easy_cleanup(curl2);
76
77    curl_share_cleanup(shobject);
78  }
79}
80~~~
81
82# AVAILABILITY
83
84Always
85
86# RETURN VALUE
87
88Returns CURLE_OK
89