GNURLOPT_SHARE(3)
π¦ GNURLOPT_SHARE(3) π¦
okay bestie, welcome to the GNURLOPT_SHARE(3) page from the curl_easy_setopt options manual β this is the one about making curl handles share their stuff π
πΈ NAME πΈ
CURLOPT_SHAREβ specify share handle to use π«Ά
β¨ SYNOPSIS β¨
the include and the function signature are literally giving:
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SHARE, CURLSH *share);
π DESCRIPTION π
You literally pass a share handle as the parameter, bestie π«Ά. That share handle must have been created by a previous call to curl_share_init(3) β no DIY-ing it, okay? Setting this option makes this curl handle use the data from the shared handle instead of keeping the data to itself. Thatβs the whole point: it enables several curl handles to share data π₯.
If the curl handles are used simultaneously in multiple threads, you MUST use the locking methods in the share handle. See curl_share_setopt(3) for details. No cap, this is the serious thread part π.
If you add a share that is set to share cookies, your easy handle will use that cookie cache and get the cookie engine enabled πͺ. If you unshare an object that was using cookies (or change to another object that doesn't share cookies), the easy handle will get its cookie engine disabled. The cookie glow-up is reversible, bestie.
Data that the share object is not set to share will be dealt with the usual way, as if no share was used. So the non-shared stuff just stays in its own lane, as usual.
Set this option to NULL again to stop using that share object. Thatβs the unshare button, basically π.
π DEFAULT π
The default is NULL β no share handle, no shared data, just you and your handle π
.
π PROTOCOLS π
All β every protocol, periodt β.
π§ EXAMPLE π§
Hereβs the example in all its glory β code stays exactly as it needs to be, bestie:
CURL *curl = curl_easy_init();
CURL *curl2 = curl_easy_init(); /* a second handle */
if(curl) {
CURLSH *shobject = curl_share_init();
curl_share_setopt(shobject, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
curl_easy_setopt(curl, CURLOPT_SHARE, shobject);
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
/* the second handle shares cookies from the first */
curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/second");
curl_easy_setopt(curl2, CURLOPT_COOKIEFILE, "");
curl_easy_setopt(curl2, CURLOPT_SHARE, shobject);
ret = curl_easy_perform(curl2);
curl_easy_cleanup(curl2);
curl_share_cleanup(shobject);
}
π AVAILABILITY π
Always β itβs always there for you, bestie π.
β RETURN VALUE β
Returns CURLE_OK β slay, the call is happy β
.
π SEE ALSO π
CURLOPT_COOKIE(3),β go peek at this one too, iykyk π
β xoxo, your libcurl 7.37.0 bestie, dated 17 Jun 2014, signing off from the GNURLOPT_SHARE(3) page ππ
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms