CURLSHOPT_SHARE(3)
π CURLSHOPT_SHARE(3) β bestie edition
okay so real quick, this page lives in the Library Functions Manual and it's called CURLSHOPT_SHARE β like, the whole page is about adding data to a share object. let's go π«Ά
β¨ NAME β¨
CURLSHOPT_SHARE β add data to share π
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLSHcode curl_share_setopt(CURLSH *share, CURLSHOPT_SHARE, long type);
π¦ DESCRIPTION π¦
okay so the type parameter is the whole main character here β it tells everyone exactly which specific data should get shared and kept inside the share object that you made earlier with curl_share_init(3). β¨ and the type you pass has to be one of the values listed below, no improvising bestie. π
you can totally call CURLSHOPT_SHARE(3) multiple times with different data arguments so your share object ends up sharing multiple types of data β very "collect them all" of you. π and if you ever wanna un-share a type again, you do that by setting CURLSHOPT_UNSHARE(3).
lowkey important: if any of that data is gonna be shared across multiple threads, then you must set mutex callbacks as well. seeCURLSHOPT_LOCKFUNC(3)andCURLSHOPT_UNLOCKFUNC(3). no cap. π₯
Now for the values β buckle up, there's a whole lineup:
CURL_LOCK_DATA_COOKIEβ cookie data gets shared across all the easy handles using this shared object. πͺ but heads up, this does not turn on an easy handle's cookie handling β that's a separate thing you do yourself, like withCURLOPT_COOKIEFILE(3)for example.
ngl this one comes with a rule: it is not supported to share cookies between multiple concurrent threads. π
CURL_LOCK_DATA_DNSβ cached DNS hosts get shared across the easy handles using this shared object. π but like, note that when you're using the multi interface, all easy handles added to the same multi handle already share the DNS cache by default without using this option. iykyk.CURL_LOCK_DATA_SSL_SESSIONβ SSL sessions get shared across all the easy handles using this shared object. π the vibe here is that it reduces the time spent in the SSL handshake when you're reconnecting to the same server. obsessed with efficiency fr fr.
again β when you use the multi interface, all easy handles added to the same multi handle share the SSL session cache by default without using this option. β
CURL_LOCK_DATA_CONNECTβ this one puts the connection cache in the share object and makes all easy handles using this share object share the connection cache. π
it is not supported to share connections between multiple concurrent threads. π
also, connections used for HTTP/2 or HTTP/3 multiplexing only get additional transfers added to them if the existing connection is held by the same multi or easy handle. libcurl does not support doing multiplexed streams in different threads using a shared connection. that's just the rules, sorry bestie. π
and yes, same deal: when you use the multi interface, all easy handles added to the same multi handle share the connection cache by default without using this option. π
CURL_LOCK_DATA_PSLβ the Public Suffix List stored in the share object gets made available to all easy handles bound to it (the original says "bound to the later", which is a typo but we're keeping the facts, not the typos π). since the Public Suffix List is periodically refreshed, this avoids updates happening in too many different contexts. πΈ
added in 7.61.0. π
and yup β when you use the multi interface, all easy handles added to the same multi handle share the PSL cache by default without using this option. β¨
CURL_LOCK_DATA_HSTSβ this is the in-memory HSTS cache. π§
it is not supported to share the HSTS between multiple concurrent threads. π
added in 7.88.0 π¦
π PROTOCOLS π
this functionality affects all supported protocols. literally all of them. π
π EXAMPLE π
int main(void)
{
CURLSHcode sh;
CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
if(sh)
printf("Error: %s\n", curl_share_strerror(sh));
}
look at her go ππ«Ά
β AVAILABILITY β
added in curl 7.10.3 β vintage icon behavior, honestly. π
πΈ RETURN VALUE πΈ
CURLSHE_OK (zero) means the option was set properly β slay. β¨ anything non-zero means an error occurred β not slay. π see libcurl-errors(3) for the full list with descriptions.
π¦ SEE ALSO π¦
that's the whole page bestie, go share ur data responsibly π«Ά this was libcurl 2026-10-12, CURLSHOPT_SHARE(3) β mwah, bye! π
β¨π
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms