xref: /curl/docs/libcurl/libcurl-share.md (revision e3fe0200)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: libcurl-share
5Section: 3
6Source: libcurl
7See-also:
8  - curl_share_cleanup (3)
9  - curl_share_init (3)
10  - curl_share_setopt (3)
11  - libcurl-easy (3)
12  - libcurl-errors (3)
13  - libcurl-multi (3)
14Protocol:
15  - All
16---
17
18# NAME
19
20libcurl-share - how to use the share interface
21
22# DESCRIPTION
23
24This is an overview on how to use the libcurl share interface in your C
25programs. There are specific man pages for each function mentioned in
26here.
27
28All functions in the share interface are prefixed with curl_share.
29
30# OBJECTIVES
31
32The share interface was added to enable sharing of data between curl handles.
33
34# ONE SET OF DATA - MANY TRANSFERS
35
36You can have multiple easy handles share data between them. Have them update
37and use the **same** cookie database, DNS cache, TLS session cache and/or
38connection cache! This way, each single transfer takes advantage from data
39updates made by the other transfer(s).
40
41# SHARE OBJECT
42
43You create a shared object with curl_share_init(3). It returns a handle
44for a newly created one.
45
46You tell the shared object what data you want it to share by using
47curl_share_setopt(3).
48
49Since you can use this share from multiple threads, and libcurl has no
50internal thread synchronization, you must provide mutex callbacks if you are
51using this multi-threaded. You set lock and unlock functions with
52curl_share_setopt(3) too.
53
54Then, you make an easy handle to use this share, you set the
55CURLOPT_SHARE(3) option with curl_easy_setopt(3), and pass in
56share handle. You can make any number of easy handles share the same share
57handle.
58
59To make an easy handle stop using that particular share, you set
60CURLOPT_SHARE(3) to NULL for that easy handle. To make a handle stop
61sharing a particular data, you can CURLSHOPT_UNSHARE(3) it.
62
63When you are done using the share, make sure that no easy handle is still using
64it, and call curl_share_cleanup(3) on the handle.
65