Skip to content

Commit d1c34dd

Browse files
committed
Added curl share options and fixed typos.
1 parent 0c32e8a commit d1c34dd

File tree

5 files changed

+72
-25
lines changed

5 files changed

+72
-25
lines changed

build/.gitkeep

Whitespace-only changes.

include/curl_multi.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ namespace curl {
217217
/**
218218
* Move constructor which moves internal data to another object.
219219
*/
220-
curl_multi(curl_multi&&);
220+
curl_multi(curl_multi&&) NOEXCEPT;
221221
/**
222222
* Move assignment operator which moves internal data to another object.
223223
*/
224-
curl_multi& operator=(curl_multi&&);
224+
curl_multi& operator=(curl_multi&&) NOEXCEPT;
225225
/**
226226
* Destructor to deallocate all the resources using
227227
* libcurl.
@@ -321,12 +321,11 @@ namespace curl {
321321
*/
322322
CURLM *get_curl() const;
323323
private:
324-
struct milti_deleter
325-
{
324+
struct multi_deleter {
326325
void operator()(CURLM* ptr) const;
327326
};
328327

329-
using multi_ptr = std::unique_ptr<CURLM, milti_deleter>;
328+
using multi_ptr = std::unique_ptr<CURLM, multi_deleter>;
330329

331330
int message_queued;
332331
int active_transfers;

include/curl_share.h

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,63 @@
2929
#include "curl_interface.h"
3030
#include "curl_pair.h"
3131

32+
#define CURLCPP_DEFINE_OPTION(opt, value_type)\
33+
template <> struct shoption_t<opt> {\
34+
using type = value_type;\
35+
}
36+
3237
namespace curl {
38+
namespace detail {
39+
template <CURLSHoption>
40+
struct shoption_t;
41+
42+
template <CURLSHoption opt>
43+
using SHOption_type = typename shoption_t<opt>::type;
44+
45+
/*
46+
* The parameter must be a pointer to a function matching the following prototype:
47+
* void lock_function(CURL *handle, curl_lock_data data, curl_lock_access access, void *userptr);
48+
* data defines what data libcurl wants to lock, and you must make sure that only one lock is given
49+
* at any time for each kind of data. access defines what access type libcurl wants, shared or single.
50+
* userptr is the pointer you set with CURLSHOPT_USERDATA.
51+
*/
52+
CURLCPP_DEFINE_OPTION(CURLSHOPT_LOCKFUNC,
53+
void(*)(CURL *handle, curl_lock_data data, curl_lock_access access, void *userptr));
54+
/*
55+
* The parameter must be a pointer to a function matching the following prototype:
56+
* void unlock_function(CURL *handle, curl_lock_data data, void *userptr);
57+
* data defines what data libcurl wants to unlock, and you must make sure that only one lock is given
58+
* at any time for each kind of data.
59+
* userptr is the pointer you set with CURLSHOPT_USERDATA.
60+
*/
61+
CURLCPP_DEFINE_OPTION(CURLSHOPT_UNLOCKFUNC, void(*)(CURL *handle, curl_lock_data data, void *userptr));
62+
63+
/*
64+
* The parameter specifies a type of data that should be shared. This may be set to one of the values described below.
65+
* CURL_LOCK_DATA_COOKIE: Cookie data will be shared across the easy handles using this shared object.
66+
* CURL_LOCK_DATA_DNS: Cached DNS hosts will be shared across the easy handles using this shared object.
67+
* Note that when you use the multi interface, all easy handles added to the same multi handle will share
68+
* DNS cache by default without this having to be used!
69+
* CURL_LOCK_DATA_SSL_SESSION: SSL session IDs will be shared across the easy handles using this shared
70+
* object. This will reduce the time spent in the SSL handshake when reconnecting to the same server.
71+
* Note SSL session IDs are reused within the same easy handle by default. Note this symbol was added
72+
* in 7.10.3 but was not implemented until 7.23.0.
73+
*/
74+
CURLCPP_DEFINE_OPTION(CURLSHOPT_SHARE, int);
75+
76+
/*
77+
* This option does the opposite of CURLSHOPT_SHARE. It specifies that the specified parameter will no longer
78+
* be shared. Valid values are the same as those for CURLSHOPT_SHARE.
79+
*/
80+
CURLCPP_DEFINE_OPTION(CURLSHOPT_UNSHARE, int);
81+
82+
/*
83+
* The parameter allows you to specify a pointer to data that will be passed to the lock_function and
84+
* unlock_function each time it is called.
85+
*/
86+
CURLCPP_DEFINE_OPTION(CURLSHOPT_USERDATA, void *);
87+
}
88+
3389
/**
3490
* Definition of share interface. The purpose of this interface is to
3591
* enable data sharing between curl handlers.
@@ -64,7 +120,7 @@ namespace curl {
64120
/**
65121
* Add method used to add options to the share handle.
66122
*/
67-
template<typename T> void add(const curl_pair<CURLSHoption,T> &);
123+
template <CURLSHoption Opt> void add(const detail::SHOption_type<Opt>);
68124
/**
69125
* Allows users to specify a list of options for the current
70126
* easy handler. In this way, you can specify any iterable data
@@ -87,10 +143,10 @@ namespace curl {
87143
}
88144

89145
// Implementation of add method
90-
template<typename T> void curl_share::add(const curl_pair<CURLSHoption,T> &pair) {
91-
const CURLSHcode code = curl_share_setopt(this->curl,pair.first(),pair.second());
146+
template<CURLSHoption Opt> void curl_share::add(const detail::SHOption_type<Opt> val) {
147+
const auto code = curl_share_setopt(this->curl, Opt, val);
92148
if (code != CURLSHE_OK) {
93-
throw curl_share_exception(code,__FUNCTION__);
149+
throw curl_share_exception(code, __FUNCTION__);
94150
}
95151
}
96152

src/curl_global.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22

33
using curl::curl_global;
44

5-
curl_global::curl_global()
6-
{
5+
curl_global::curl_global() {
76
const CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
87
if (code != CURLE_OK) {
98
throw curl_easy_exception(code, __FUNCTION__);
109
}
1110
}
1211

13-
curl_global::curl_global(const long flag)
14-
{
12+
curl_global::curl_global(const long flag) {
1513
const CURLcode code = curl_global_init(flag);
1614
if (code != CURLE_OK) {
1715
throw curl_easy_exception(code, __FUNCTION__);
1816
}
1917
}
2018

21-
curl_global::~curl_global()
22-
{
19+
curl_global::~curl_global() {
2320
curl_global_cleanup();
2421
}

src/curl_multi.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ using curl::curl_easy;
1111
using std::vector;
1212
using std::unique_ptr;
1313

14-
void curl_multi::milti_deleter::operator()(CURLM* ptr) const
15-
{
14+
void curl_multi::multi_deleter::operator()(CURLM* ptr) const {
1615
curl_multi_cleanup(ptr);
1716
}
1817

19-
curl_multi::curl_multi() : curl_multi(CURL_GLOBAL_ALL) {
20-
}
18+
curl_multi::curl_multi() : curl_multi(CURL_GLOBAL_ALL) {}
2119

2220
curl_multi::curl_multi(const long flag)
2321
: curl_interface(flag),
@@ -29,26 +27,23 @@ curl_multi::curl_multi(const long flag)
2927
this->message_queued = 0;
3028
}
3129

32-
curl_multi::curl_multi(curl_multi&& other)
30+
curl_multi::curl_multi(curl_multi&& other) NOEXCEPT
3331
: curl_interface(std::forward<curl_interface>(other)),
3432
curl(std::move(other.curl)),
3533
active_transfers(other.active_transfers),
3634
message_queued(other.message_queued) {
3735
}
3836

39-
curl_multi &curl_multi::operator=(curl_multi&& other) {
37+
curl_multi &curl_multi::operator=(curl_multi&& other) NOEXCEPT {
4038
if (this != &other) {
4139
curl = std::move(other.curl);
4240
active_transfers = other.active_transfers;
4341
message_queued = other.message_queued;
4442
}
45-
4643
return *this;
4744
}
4845

49-
curl_multi::~curl_multi() NOEXCEPT
50-
{
51-
}
46+
curl_multi::~curl_multi() NOEXCEPT = default;
5247

5348
// Implementation of add method for easy handlers.
5449
void curl_multi::add(const curl_easy &easy) {

0 commit comments

Comments
 (0)