CURLOPT_SHARE.3 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_SHARE 3 "January 02, 2023" "libcurl 7.88.1" "curl_easy_setopt options"
  26. .SH NAME
  27. CURLOPT_SHARE \- share handle to use
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SHARE, CURLSH *share);
  32. .fi
  33. .SH DESCRIPTION
  34. Pass a \fIshare\fP handle as a parameter. The share handle must have been
  35. created by a previous call to \fIcurl_share_init(3)\fP. Setting this option,
  36. will make this curl handle use the data from the shared handle instead of
  37. keeping the data to itself. This enables several curl handles to share
  38. data. If the curl handles are used simultaneously in multiple threads, you
  39. \fBMUST\fP use the locking methods in the share handle. See
  40. \fIcurl_share_setopt(3)\fP for details.
  41. If you add a share that is set to share cookies, your easy handle will use
  42. that cookie cache and get the cookie engine enabled. If you stop sharing an
  43. object that was using cookies (or change to another object that does not share
  44. cookies), the easy handle will get its cookie engine disabled.
  45. Data that the share object is not set to share will be dealt with the usual
  46. way, as if no share was used.
  47. Set this option to NULL again to stop using that share object.
  48. .SH DEFAULT
  49. NULL
  50. .SH PROTOCOLS
  51. All
  52. .SH EXAMPLE
  53. .nf
  54. CURL *curl = curl_easy_init();
  55. CURL *curl2 = curl_easy_init(); /* a second handle */
  56. if(curl) {
  57. CURLSH *shobject = curl_share_init();
  58. curl_share_setopt(shobject, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
  59. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  60. curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
  61. curl_easy_setopt(curl, CURLOPT_SHARE, shobject);
  62. ret = curl_easy_perform(curl);
  63. curl_easy_cleanup(curl);
  64. /* the second handle shares cookies from the first */
  65. curl_easy_setopt(curl2, CURLOPT_URL, "https://example.com/second");
  66. curl_easy_setopt(curl2, CURLOPT_COOKIEFILE, "");
  67. curl_easy_setopt(curl2, CURLOPT_SHARE, shobject);
  68. ret = curl_easy_perform(curl2);
  69. curl_easy_cleanup(curl2);
  70. curl_share_cleanup(shobject);
  71. }
  72. .fi
  73. .SH AVAILABILITY
  74. Always
  75. .SH RETURN VALUE
  76. Returns CURLE_OK
  77. .SH "SEE ALSO"
  78. .BR CURLOPT_COOKIE "(3), "