libcurl Share Interface

Overview

NOTE:
Though 'multi_share' APIs are made available in Cafe libcurl, they are not tested and are not officially supported.

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. All functions in the share interface are prefixed with curl_share.

Objectives

The share interface was added to enable sharing of data between curl 'handles'.

One Set of Data, Many Transfers

You can have multiple easy handles that share data, update, and use the same cookie database or DNS cache. Each single transfer benefits from data updates made by the other transfer(s).

Share Object

Create a shared object by using the following steps.

  1. Create a shared object with curl_share_init(3). It returns a handle for a newly created object.
  2. Inform the shared object what data you want it to share by using curl_share_setopt(3). Currently, you can only share DNS and/or COOKIE data. The share can be used from multiple threads, and because libcurl has no internal thread synchronization, it is required to provide mutex callbacks if using as multithreaded.
  3. Set the lock and unlock functions with curl_share_setopt.
  4. Make an easy handle to use the share by setting the CURLOPT_SHARE option with curl_easy_setopt, and pass in the share handle. You can make any number of easy handles share the same share handle.
  5. To make an easy handle stop using a particular share, set CURLOPT_SHARE to NULL for the easy handle. To make a handle stop sharing a particular data, use CURLSHOPT_UNSHARE.
  6. When finished using the share, check that an easy handle is not using it and then call curl_share_cleanup.

See Also

HTTP Client Library (libcurl)
curl_share_init
curl_share_setopt
curl_share_cleanup

Revision History

2013/09/12 Converted.


CONFIDENTIAL