curl-cpp
static c++17 wrapper for curl with -fno-exceptions support
Public Types | Public Member Functions | Protected Attributes | List of all members
curl::Share_base Class Reference
Inheritance diagram for curl::Share_base:
Inheritance graph
Collaboration diagram for curl::Share_base:
Collaboration graph

Public Types

enum  Options {
  none = CURL_LOCK_DATA_NONE, cookie = CURL_LOCK_DATA_COOKIE, Options::dns = CURL_LOCK_DATA_DNS, Options::ssl_session = CURL_LOCK_DATA_SSL_SESSION,
  Options::connection_cache = CURL_LOCK_DATA_CONNECT, Options::psl = CURL_LOCK_DATA_PSL
}
 
using lock_function_t = void(*)(CURL *handle, curl_lock_data data, curl_lock_access access, void *userptr)
 
using unlock_function_t = void(*)(CURL *handle, curl_lock_data data, void *userptr)
 

Public Member Functions

 Share_base (curl_t::Share_t &&share) noexcept
 
 Share_base (const Share_base &)=delete
 
 Share_base (Share_base &&other) noexcept
 
Share_baseoperator= (const Share_base &)=delete
 
Share_baseoperator= (Share_base &&other) noexcept
 
 operator bool () const noexcept
 
void add_lock (lock_function_t lock_func, unlock_function_t unlock_func, void *userptr) noexcept
 
auto enable_sharing (Options option) noexcept -> Ret_except< int, std::bad_alloc >
 
void disable_sharing (Options option) noexcept
 
void add_easy (Easy_ref_t &easy) noexcept
 
void remove_easy (Easy_ref_t &easy) noexcept
 

Protected Attributes

curl_t::Share_t curl_share
 

Detailed Description

Definition at line 21 of file curl_share.hpp.

Member Typedef Documentation

◆ lock_function_t

using curl::Share_base::lock_function_t = void (*)(CURL *handle, curl_lock_data data, curl_lock_access access, void *userptr)

Possible value of data: same as enum class Options

Possible value of access:

  • CURL_LOCK_ACCESS_SHARED,
  • CURL_LOCK_ACCESS_SINGLE, The mutex you used must be pthread_rwlock_t or std::shared_mutex.

Definition at line 126 of file curl_share.hpp.

◆ unlock_function_t

using curl::Share_base::unlock_function_t = void (*)(CURL *handle, curl_lock_data data, void *userptr)

Possible value of data: same as enum class Options

Possible value of access:

  • CURL_LOCK_ACCESS_SHARED,
  • CURL_LOCK_ACCESS_SINGLE, The mutex you used must be pthread_rwlock_t or std::shared_mutex.

Definition at line 135 of file curl_share.hpp.

Member Enumeration Documentation

◆ Options

Defines data to share among Easy_t handles.

Enumerator
dns 

share cached DNS hosts.

If the libcurl has cookies disabled, then enable_sharing(Options::cookie) will return 0.

NOTE that Multi_t interface share this by default without setting this option.

ssl_session 

SSL session IDs will be shared across the easy handles using this shared object.

This will reduce the time spent in the SSL handshake when reconnecting to the same server.

If curl_t::has_ssl_session_sharing_support() == false, setting this option shares nothing.

NOTE SSL session IDs are reused within the same easy handle by default.

connection_cache 

If curl_t::has_connection_cache_sharing_support() == false, setting this option shares nothing.

NOTE that Multi_t interface share this by default without setting this option.

psl 

Share Public Suffix List.

If curl_t::has_psl_sharing_support() == false, setting this option shares nothing.

NOTE that Multi_t interface share this by default without setting this option.

Examples
curl_share.cc.

Definition at line 72 of file curl_share.hpp.

72  {
73  none = CURL_LOCK_DATA_NONE,
74  cookie = CURL_LOCK_DATA_COOKIE,
84  dns = CURL_LOCK_DATA_DNS,
97  ssl_session = CURL_LOCK_DATA_SSL_SESSION,
105  connection_cache = CURL_LOCK_DATA_CONNECT,
115  psl = CURL_LOCK_DATA_PSL,
116  };

Constructor & Destructor Documentation

◆ Share_base() [1/3]

curl::Share_base::Share_base ( curl_t::Share_t &&  share)
noexcept
Parameters
sharemust be != nullptr

After this ctor call, share.get() == nullptr, this class will take over the ownership.

Definition at line 15 of file curl_share.cc.

15  :
16  curl_share{std::move(share)}
17 {}

◆ Share_base() [2/3]

curl::Share_base::Share_base ( const Share_base )
delete

Since libcurl doesn't provide a dup function for curl_share, neither will Share_base.

◆ Share_base() [3/3]

curl::Share_base::Share_base ( Share_base &&  other)
noexcept
Parameters
otherbool(other) can be false, but then this new instance of Share_base will be unusable.

Definition at line 19 of file curl_share.cc.

19  :
20  curl_share{std::move(other.curl_share)}
21 {}

Member Function Documentation

◆ operator=() [1/2]

Share_base& curl::Share_base::operator= ( const Share_base )
delete

Since libcurl doesn't provide a dup function for curl_share, neither will Share_base.

◆ operator=() [2/2]

Share_base & curl::Share_base::operator= ( Share_base &&  other)
noexcept
Parameters
otherif bool(other) is true, then it will be unusable after this operation.
Otherwise, this object will also be destroyed.
thisthis object can also be an unusable object which bool(*this) is false.
Calling this function on an unusable object will make that object again usable.

NOTE that if this object still holds easy handler and bool(other) is false, then it is undefined behavior.

Definition at line 22 of file curl_share.cc.

23 {
24  curl_share = std::move(other.curl_share);
25  return *this;
26 }

◆ operator bool()

curl::Share_base::operator bool ( ) const
noexcept
Returns
true if this object is usable, false otherwise.

Definition at line 28 of file curl_share.cc.

29 {
30  return bool(curl_share);
31 }

◆ add_lock()

void curl::Share_base::add_lock ( lock_function_t  lock_func,
unlock_function_t  unlock_func,
void *  userptr 
)
noexcept

Setting lock_func and unlock_func to nullptr disable locking.

Definition at line 33 of file curl_share.cc.

34 {
35  curl_share_setopt(curl_share.get(), CURLSHOPT_LOCKFUNC, lock_func);
36  curl_share_setopt(curl_share.get(), CURLSHOPT_UNLOCKFUNC, unlock_func);
37  curl_share_setopt(curl_share.get(), CURLSHOPT_USERDATA, userptr);
38 }

◆ enable_sharing()

auto curl::Share_base::enable_sharing ( Options  option) -> Ret_except<int, std::bad_alloc>
noexcept
Parameters
optionmust be one of enum class Options.
Cannot be or-ed value.

All sharing enable/disable must be done when no easy is added or all easy is removed.

Definition at line 40 of file curl_share.cc.

41 {
42  auto code = curl_share_setopt(curl_share.get(), CURLSHOPT_SHARE, static_cast<curl_lock_data>(option));
43  if (code == CURLSHE_NOMEM)
44  return {std::bad_alloc{}};
45  else if (code == CURLSHE_NOT_BUILT_IN)
46  return {0};
47 
48  return {1};
49 }

◆ disable_sharing()

void curl::Share_base::disable_sharing ( Options  option)
noexcept
Parameters
optionmust be one of enum class Options.
Cannot be or-ed value.

All sharing enable/disable must be done when no easy is added or all easy is removed.

Definition at line 50 of file curl_share.cc.

51 {
52  curl_share_setopt(curl_share.get(), CURLSHOPT_UNSHARE, static_cast<curl_lock_data>(option));
53 }

The documentation for this class was generated from the following files: