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