CURLOPT_SHARE.3 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. .\" generated by cd2nroff 0.1 from CURLOPT_SHARE.md
  2. .TH CURLOPT_SHARE 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_SHARE \- share handle to use
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SHARE, CURLSH *share);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a \fIshare\fP handle as a parameter. The share handle must have been
  12. created by a previous call to \fIcurl_share_init(3)\fP. Setting this option,
  13. makes this curl handle use the data from the shared handle instead of keeping
  14. the data to itself. This enables several curl handles to share data. If the
  15. curl handles are used simultaneously in multiple threads, you \fBMUST\fP use
  16. the locking methods in the share handle. See \fIcurl_share_setopt(3)\fP for
  17. details.
  18. If you add a share that is set to share cookies, your easy handle uses that
  19. cookie cache and get the cookie engine enabled. If you stop sharing an object
  20. that was using cookies (or change to another object that does not share
  21. cookies), the easy handle gets its cookie engine disabled.
  22. Data that the share object is not set to share is dealt with the usual way, as
  23. if no share was used.
  24. Set this option to NULL again to stop using that share object.
  25. .SH DEFAULT
  26. NULL
  27. .SH PROTOCOLS
  28. This functionality affects all supported protocols
  29. .SH EXAMPLE
  30. .nf
  31. int main(void)
  32. {
  33. CURL *curl = curl_easy_init();
  34. CURL *curl2 = curl_easy_init(); /* a second handle */
  35. if(curl) {
  36. CURLcode res;
  37. CURLSH *shobject = curl_share_init();
  38. curl_share_setopt(shobject, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
  39. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  40. curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
  41. curl_easy_setopt(curl, CURLOPT_SHARE, shobject);
  42. res = curl_easy_perform(curl);
  43. curl_easy_cleanup(curl);
  44. /* the second handle shares cookies from the first */
  45. curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/second");
  46. curl_easy_setopt(curl2, CURLOPT_COOKIEFILE, "");
  47. curl_easy_setopt(curl2, CURLOPT_SHARE, shobject);
  48. res = curl_easy_perform(curl2);
  49. curl_easy_cleanup(curl2);
  50. curl_share_cleanup(shobject);
  51. }
  52. }
  53. .fi
  54. .SH AVAILABILITY
  55. Added in curl 7.10
  56. .SH RETURN VALUE
  57. Returns CURLE_OK
  58. .SH SEE ALSO
  59. .BR CURLOPT_COOKIE (3),
  60. .BR CURLSHOPT_SHARE (3)