xref: /curl/docs/libcurl/opts/CURLSHOPT_SHARE.md (revision 79677caa)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLSHOPT_SHARE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLSHOPT_UNSHARE (3)
9  - curl_share_cleanup (3)
10  - curl_share_init (3)
11  - curl_share_setopt (3)
12Protocol:
13  - All
14Added-in: 7.10.3
15---
16
17# NAME
18
19CURLSHOPT_SHARE - add data to share
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLSHcode curl_share_setopt(CURLSH *share, CURLSHOPT_SHARE, long type);
27~~~
28
29# DESCRIPTION
30
31The *type* parameter specifies what specific data that should be shared
32and kept in the share object that was created with curl_share_init(3).
33The given *type* must be one of the values described below. You can set
34CURLSHOPT_SHARE(3) multiple times with different data arguments to have
35the share object share multiple types of data. Unset a type again by setting
36CURLSHOPT_UNSHARE(3).
37
38## CURL_LOCK_DATA_COOKIE
39
40Cookie data is shared across the easy handles using this shared object. Note
41that this does not activate an easy handle's cookie handling. You can do that
42separately by using CURLOPT_COOKIEFILE(3) for example.
43
44It is not supported to share cookies between multiple concurrent threads.
45
46## CURL_LOCK_DATA_DNS
47
48Cached DNS hosts are shared across the easy handles using this shared
49object. Note that when you use the multi interface, all easy handles added to
50the same multi handle share DNS cache by default without using this option.
51
52## CURL_LOCK_DATA_SSL_SESSION
53
54SSL session IDs are shared across the easy handles using this shared
55object. This reduces the time spent in the SSL handshake when reconnecting to
56the same server. Note SSL session IDs are reused within the same easy handle
57by default. Note this symbol was added in 7.10.3 but was not implemented until
587.23.0.
59
60It is not supported to share SSL sessions between multiple concurrent threads.
61
62## CURL_LOCK_DATA_CONNECT
63
64Put the connection cache in the share object and make all easy handles using
65this share object share the connection cache.
66
67It is not supported to share connections between multiple concurrent threads.
68
69Connections that are used for HTTP/2 or HTTP/3 multiplexing only get
70additional transfers added to them if the existing connection is held by the
71same multi or easy handle. libcurl does not support doing multiplexed streams
72in different threads using a shared connection.
73
74Support for **CURL_LOCK_DATA_CONNECT** was added in 7.57.0, but the symbol
75existed before this.
76
77Note that when you use the multi interface, all easy handles added to the same
78multi handle shares connection cache by default without using this option.
79
80## CURL_LOCK_DATA_PSL
81
82The Public Suffix List stored in the share object is made available to all
83easy handle bound to the later. Since the Public Suffix List is periodically
84refreshed, this avoids updates in too many different contexts.
85
86Added in 7.61.0.
87
88Note that when you use the multi interface, all easy handles added to the same
89multi handle shares PSL cache by default without using this option.
90
91## CURL_LOCK_DATA_HSTS
92
93The in-memory HSTS cache.
94
95It is not supported to share the HSTS between multiple concurrent threads.
96
97Added in 7.88.0
98
99# %PROTOCOLS%
100
101# EXAMPLE
102
103~~~c
104int main(void)
105{
106  CURLSHcode sh;
107  CURLSH *share = curl_share_init();
108  sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
109  if(sh)
110    printf("Error: %s\n", curl_share_strerror(sh));
111}
112~~~
113
114# %AVAILABILITY%
115
116# RETURN VALUE
117
118CURLSHE_OK (zero) means that the option was set properly, non-zero means an
119error occurred. See libcurl-errors(3) for the full list with
120descriptions.
121