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