CINXE.COM
libcurl - share interface overview
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>libcurl - share interface overview</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <link rel="stylesheet" type="text/css" href="/curl.css"> <link rel="shortcut icon" href="/favicon.ico"> <link rel="icon" href="/logo/curl-symbol.svg" type="image/svg+xml"> <link rel="alternate" type="application/rss+xml" title="cURL Releases" href="https://github.com/curl/curl/releases.atom"> <link rel="stylesheet" type="text/css" href="/manpage.css"> </head> <body> <div class="main"> <div class="menu"> <a href="/libcurl/c/libcurl.html" class="menuitem" title="Overview">API Overview</a> <div class="dropdown"> <a class="dropbtn" href="/libcurl/c/">Docs</a> <div class="dropdown-content"> <a href="/libcurl/c/libcurl-easy.html">API: easy</a> <a href="/libcurl/c/libcurl-multi.html">API: multi</a> <a href="/libcurl/c/libcurl-share.html">API: share</a> <a href="/libcurl/c/libcurl-url.html">API: URL</a> <a href="/libcurl/c/libcurl-ws.html">API: WebSocket</a> <a href="/libcurl/c/libcurl-env.html">Environment vars</a> <a href="/libcurl/c/libcurl-errors.html">Errors</a> <a href="/libcurl/c/example.html">Examples</a> <a href="/libcurl/security.html">Security</a> <a href="/libcurl/c/symbols-in-versions.html">Symbols</a> <a href="/libcurl/c/libcurl-tutorial.html">Tutorial</a> <hr> <a href="/libcurl/c/easy_setopt_options.html">easy setopt options</a> <a href="/libcurl/c/easy_getinfo_options.html">easy getinfo options</a> <a href="/libcurl/c/multi_setopt_options.html">multi setopt options</a> <a href="/libcurl/c/tls-options.html">TLS options</a> </div> </div> <div class="dropdown"> <a class="dropbtn" href="/libcurl/c/">Functions</a> <div class="dropdown-content"> <a href="/libcurl/c/allfuncs.html">All functions</a> <a href="/libcurl/c/curl_easy_getinfo.html">curl_easy_getinfo</a> <a href="/libcurl/c/curl_easy_init.html">curl_easy_init</a> <a href="/libcurl/c/curl_easy_perform.html">curl_easy_perform</a> <a href="/libcurl/c/curl_easy_reset.html">curl_easy_reset</a> <a href="/libcurl/c/curl_easy_setopt.html">curl_easy_setopt</a> <a href="/libcurl/c/curl_multi_add_handle.html">curl_multi_add_handle</a> <a href="/libcurl/c/curl_multi_init.html">curl_multi_init</a> <a href="/libcurl/c/curl_multi_perform.html">curl_multi_perform</a> <a href="/libcurl/c/curl_multi_remove_handle.html">curl_multi_remove_handle</a> <a href="/libcurl/c/curl_multi_setopt.html">curl_multi_setopt</a> </div> </div> </div> <div class="contents"> <div class="where"><a href="/">curl</a> / <a href="/libcurl/">libcurl</a> / <a href="/libcurl/c/">API</a> / <b>share interface</b></div> <h1> share interface overview </h1> <div class="relatedbox"> <b>Related:</b> <br><a href="allfuncs.html">All functions</a> <br><a href="./">API</a> <br><a href="example.html">Examples</a> </div> <!-- generated with roffit --> <a name="NAME"></a><h2 class="nroffsh">Name</h2> <p class="level0">libcurl-share - how to use the share interface </p><a name="DESCRIPTION"></a><h2 class="nroffsh">Description</h2> <p class="level0">This is an overview on how to use the libcurl share interface in your C programs. There are specific man pages for each function mentioned in here. </p> <p class="level0">All functions in the share interface are prefixed with curl_share. </p><a name="OBJECTIVES"></a><h2 class="nroffsh">Objectives</h2> <p class="level0">The share interface was added to enable sharing of data between curl handles. </p><a name="ONE"></a><h2 class="nroffsh">One set of data - many transfers</h2> <p class="level0">You can have multiple easy handles share data between them. Have them update and use the <span Class="bold">same</span> cookie database, DNS cache, TLS session cache and/or connection cache. This way, each single transfer takes advantage from data updates made by the other transfer(s). </p><a name="SHARE"></a><h2 class="nroffsh">Share object</h2> <p class="level0">You create a shared object with <a Class="emphasis" href="./curl_share_init.html">curl_share_init</a>. It returns a handle for a newly created one. </p> <p class="level0">You tell the shared object what data you want it to share by using <a Class="emphasis" href="./curl_share_setopt.html">curl_share_setopt</a>. </p> <p class="level0">Since you can use this share from multiple threads, and libcurl has no internal thread synchronization, you must provide mutex callbacks if you are using this multi-threaded. You set lock and unlock functions with <a Class="emphasis" href="./curl_share_setopt.html">curl_share_setopt</a> too. </p> <p class="level0">Then, you make an easy handle to use this share, you set the <a Class="emphasis" href="./CURLOPT_SHARE.html">CURLOPT_SHARE</a> option with <a Class="emphasis" href="./curl_easy_setopt.html">curl_easy_setopt</a>, and pass in share handle. You can make any number of easy handles share the same share handle. </p> <p class="level0">To make an easy handle stop using that particular share, you set <a Class="emphasis" href="./CURLOPT_SHARE.html">CURLOPT_SHARE</a> to NULL for that easy handle. To make a handle stop sharing a particular data, you can <a Class="emphasis" href="./CURLSHOPT_UNSHARE.html">CURLSHOPT_UNSHARE</a> it. </p> <p class="level0">When you are done using the share, make sure that no easy handle is still using it, and call <a Class="emphasis" href="./curl_share_cleanup.html">curl_share_cleanup</a> on the handle. </p><a name="SEE"></a><h2 class="nroffsh">See also</h2> <p class="level0"><a Class="bold" href="./curl_share_cleanup.html">curl_share_cleanup</a>(3), <a Class="bold" href="./curl_share_init.html">curl_share_init</a>(3), <a Class="bold" href="./curl_share_setopt.html">curl_share_setopt</a>(3), <a Class="bold" href="./libcurl-easy.html">libcurl-easy</a>(3), <a Class="bold" href="./libcurl-errors.html">libcurl-errors</a>(3), <a Class="bold" href="./libcurl-multi.html">libcurl-multi</a>(3) </p><p class="roffit"> This HTML page was made with <a href="https://daniel.haxx.se/projects/roffit/">roffit</a>. </div> </div> </body> </html>