Skip to content

Commit

Permalink
Added curl share options and fixed typos.
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephP91 committed Sep 2, 2017
1 parent 0c32e8a commit d1c34dd
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 25 deletions.
Empty file removed build/.gitkeep
Empty file.
9 changes: 4 additions & 5 deletions include/curl_multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ namespace curl {
/**
* Move constructor which moves internal data to another object.
*/
curl_multi(curl_multi&&);
curl_multi(curl_multi&&) NOEXCEPT;
/**
* Move assignment operator which moves internal data to another object.
*/
curl_multi& operator=(curl_multi&&);
curl_multi& operator=(curl_multi&&) NOEXCEPT;
/**
* Destructor to deallocate all the resources using
* libcurl.
Expand Down Expand Up @@ -321,12 +321,11 @@ namespace curl {
*/
CURLM *get_curl() const;
private:
struct milti_deleter
{
struct multi_deleter {
void operator()(CURLM* ptr) const;
};

using multi_ptr = std::unique_ptr<CURLM, milti_deleter>;
using multi_ptr = std::unique_ptr<CURLM, multi_deleter>;

int message_queued;
int active_transfers;
Expand Down
64 changes: 60 additions & 4 deletions include/curl_share.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,63 @@
#include "curl_interface.h"
#include "curl_pair.h"

#define CURLCPP_DEFINE_OPTION(opt, value_type)\
template <> struct shoption_t<opt> {\
using type = value_type;\
}

namespace curl {
namespace detail {
template <CURLSHoption>
struct shoption_t;

template <CURLSHoption opt>
using SHOption_type = typename shoption_t<opt>::type;

/*
* The parameter must be a pointer to a function matching the following prototype:
* void lock_function(CURL *handle, curl_lock_data data, curl_lock_access access, void *userptr);
* data defines what data libcurl wants to lock, and you must make sure that only one lock is given
* at any time for each kind of data. access defines what access type libcurl wants, shared or single.
* userptr is the pointer you set with CURLSHOPT_USERDATA.
*/
CURLCPP_DEFINE_OPTION(CURLSHOPT_LOCKFUNC,
void(*)(CURL *handle, curl_lock_data data, curl_lock_access access, void *userptr));
/*
* The parameter must be a pointer to a function matching the following prototype:
* void unlock_function(CURL *handle, curl_lock_data data, void *userptr);
* data defines what data libcurl wants to unlock, and you must make sure that only one lock is given
* at any time for each kind of data.
* userptr is the pointer you set with CURLSHOPT_USERDATA.
*/
CURLCPP_DEFINE_OPTION(CURLSHOPT_UNLOCKFUNC, void(*)(CURL *handle, curl_lock_data data, void *userptr));

/*
* The parameter specifies a type of data that should be shared. This may be set to one of the values described below.
* CURL_LOCK_DATA_COOKIE: Cookie data will be shared across the easy handles using this shared object.
* CURL_LOCK_DATA_DNS: Cached DNS hosts will be shared across the easy handles using this shared object.
* Note that when you use the multi interface, all easy handles added to the same multi handle will share
* DNS cache by default without this having to be used!
* CURL_LOCK_DATA_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.
* Note SSL session IDs are reused within the same easy handle by default. Note this symbol was added
* in 7.10.3 but was not implemented until 7.23.0.
*/
CURLCPP_DEFINE_OPTION(CURLSHOPT_SHARE, int);

/*
* This option does the opposite of CURLSHOPT_SHARE. It specifies that the specified parameter will no longer
* be shared. Valid values are the same as those for CURLSHOPT_SHARE.
*/
CURLCPP_DEFINE_OPTION(CURLSHOPT_UNSHARE, int);

/*
* The parameter allows you to specify a pointer to data that will be passed to the lock_function and
* unlock_function each time it is called.
*/
CURLCPP_DEFINE_OPTION(CURLSHOPT_USERDATA, void *);
}

/**
* Definition of share interface. The purpose of this interface is to
* enable data sharing between curl handlers.
Expand Down Expand Up @@ -64,7 +120,7 @@ namespace curl {
/**
* Add method used to add options to the share handle.
*/
template<typename T> void add(const curl_pair<CURLSHoption,T> &);
template <CURLSHoption Opt> void add(const detail::SHOption_type<Opt>);
/**
* Allows users to specify a list of options for the current
* easy handler. In this way, you can specify any iterable data
Expand All @@ -87,10 +143,10 @@ namespace curl {
}

// Implementation of add method
template<typename T> void curl_share::add(const curl_pair<CURLSHoption,T> &pair) {
const CURLSHcode code = curl_share_setopt(this->curl,pair.first(),pair.second());
template<CURLSHoption Opt> void curl_share::add(const detail::SHOption_type<Opt> val) {
const auto code = curl_share_setopt(this->curl, Opt, val);
if (code != CURLSHE_OK) {
throw curl_share_exception(code,__FUNCTION__);
throw curl_share_exception(code, __FUNCTION__);
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/curl_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

using curl::curl_global;

curl_global::curl_global()
{
curl_global::curl_global() {
const CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
if (code != CURLE_OK) {
throw curl_easy_exception(code, __FUNCTION__);
}
}

curl_global::curl_global(const long flag)
{
curl_global::curl_global(const long flag) {
const CURLcode code = curl_global_init(flag);
if (code != CURLE_OK) {
throw curl_easy_exception(code, __FUNCTION__);
}
}

curl_global::~curl_global()
{
curl_global::~curl_global() {
curl_global_cleanup();
}
15 changes: 5 additions & 10 deletions src/curl_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ using curl::curl_easy;
using std::vector;
using std::unique_ptr;

void curl_multi::milti_deleter::operator()(CURLM* ptr) const
{
void curl_multi::multi_deleter::operator()(CURLM* ptr) const {
curl_multi_cleanup(ptr);
}

curl_multi::curl_multi() : curl_multi(CURL_GLOBAL_ALL) {
}
curl_multi::curl_multi() : curl_multi(CURL_GLOBAL_ALL) {}

curl_multi::curl_multi(const long flag)
: curl_interface(flag),
Expand All @@ -29,26 +27,23 @@ curl_multi::curl_multi(const long flag)
this->message_queued = 0;
}

curl_multi::curl_multi(curl_multi&& other)
curl_multi::curl_multi(curl_multi&& other) NOEXCEPT
: curl_interface(std::forward<curl_interface>(other)),
curl(std::move(other.curl)),
active_transfers(other.active_transfers),
message_queued(other.message_queued) {
}

curl_multi &curl_multi::operator=(curl_multi&& other) {
curl_multi &curl_multi::operator=(curl_multi&& other) NOEXCEPT {
if (this != &other) {
curl = std::move(other.curl);
active_transfers = other.active_transfers;
message_queued = other.message_queued;
}

return *this;
}

curl_multi::~curl_multi() NOEXCEPT
{
}
curl_multi::~curl_multi() NOEXCEPT = default;

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

0 comments on commit d1c34dd

Please sign in to comment.