GNURLOPT_SHARE(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ¦‹ 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 πŸ‘€


β€” xoxo, your libcurl 7.37.0 bestie, dated 17 Jun 2014, signing off from the GNURLOPT_SHARE(3) page πŸ’–πŸŽ€

πŸ“¦ where this page comes from