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