Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled copying for curl_global, added curl_global_cleanup call #105

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions include/curl_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,20 @@ namespace curl {
* with user specified flag.
*/
explicit curl_global(const long);

/**
* Copying disabled to follow RAII idiom.
*/
curl_global(const curl_global&) = delete;
curl_global& operator=(const curl_global&) = delete;

/**
* The virtual destructor will provide an easy and clean
* way to deallocate resources, closing curl environment
* correctly.
*/
virtual ~curl_global();
};

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

// Implementation of overloaded constructor.
curl_global::curl_global(const long flag) {
const CURLcode code = curl_global_init(flag);
if (code != CURLE_OK) {
throw curl_easy_exception(code,__FUNCTION__);
}
}

// Implementation of the virtual destructor.
curl_global::~curl_global() {
}
}

#endif /* defined(__curlcpp__curl_global__) */
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(CURLCPP_SOURCE
curl_easy.cpp
curl_header.cpp
curl_global.cpp
curl_form.cpp
curl_multi.cpp
curl_share.cpp
Expand Down
24 changes: 24 additions & 0 deletions src/curl_global.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "curl_global.h"

using curl::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)
{
const CURLcode code = curl_global_init(flag);
if (code != CURLE_OK) {
throw curl_easy_exception(code, __FUNCTION__);
}
}

curl_global::~curl_global()
{
curl_global_cleanup();
}