Remove premature global curl cleanup, improve documentation.

This commit is contained in:
tastytea 2020-01-04 18:21:20 +01:00
parent a7a861351f
commit 051cf16ceb
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 13 additions and 20 deletions

View File

@ -26,9 +26,6 @@ namespace mastodonpp
using std::string;
//! Internal use only.
extern bool curl_initialized;
/*!
* @brief Handles the details of network connections.
*
@ -40,10 +37,9 @@ class CURLWrapper
{
public:
/*!
* @brief Constructs a CURLWrapper object.
* @brief Initializes curl and sets up connection.
*
* The first construction of an CurlWrapper object will call
* `curl_global_init`, which is not thread-safe. For more information
* Calls `curl_global_init`, which is not thread-safe. For more information
* consult [curl_global_init(3)]
* (https://curl.haxx.se/libcurl/c/curl_global_init.html).
*
@ -57,7 +53,15 @@ public:
//! Move constructor
CURLWrapper(CURLWrapper &&other) noexcept = default;
//! Destructor
/*!
* @brief Cleans up curl and connection.
*
* Calls `curl_global_cleanup`, which is not thread-safe. For more
* information consult [curl_global_cleanup(3)]
* (https://curl.haxx.se/libcurl/c/curl_global_cleanup.html).
*
* @since 0.1.0
*/
virtual ~CURLWrapper() noexcept;
//! Copy assignment operator

View File

@ -20,28 +20,17 @@
namespace mastodonpp
{
bool curl_initialized{false};
CURLWrapper::CURLWrapper()
: _curl_buffer_error{}
{
if (!curl_initialized)
{
curl_global_init(CURL_GLOBAL_ALL); // NOLINT(hicpp-signed-bitwise)
curl_initialized = true;
}
_connection = curl_easy_init();
setup_curl();
}
CURLWrapper::~CURLWrapper() noexcept
{
curl_easy_cleanup(_connection);
if (curl_initialized)
{
curl_global_cleanup();
curl_initialized = false;
}
}
int CURLWrapper::writer(char *data, size_t size, size_t nmemb, string *writerData)