33 #ifndef WRAPPER_CURL_HPP_ 34 #define WRAPPER_CURL_HPP_ 36 #ifndef CRAWLSERVPP_TESTING 38 #include <curl/curl.h> 42 #include "FakeCurl/FakeCurl.hpp" 82 [[nodiscard]] CURL *
get() noexcept;
83 [[nodiscard]] CURL **
getPtr() noexcept;
84 [[nodiscard]]
bool valid()
const noexcept;
91 void clear() noexcept;
115 static std::atomic<unsigned int> globalInitCounter;
138 if(Curl::globalInitCounter.fetch_add(1) == 0) {
140 const auto curlCode{curl_global_init(CURL_GLOBAL_ALL)};
142 if(curlCode != CURLE_OK) {
143 throw std::runtime_error(curl_easy_strerror(curlCode));
152 if(Curl::globalInitCounter.fetch_sub(1) == 1) {
153 curl_global_cleanup();
177 if(Curl::globalInitCounter.fetch_sub(1) == 1) {
178 curl_global_cleanup();
215 return this->ptr !=
nullptr;
233 this->ptr = curl_easy_init();
235 if(this->ptr ==
nullptr) {
236 throw std::runtime_error(
"curl_easy_init() failed");
256 if(this->ptr !=
nullptr) {
257 curl_easy_cleanup(this->ptr);
282 this->ptr = other.ptr;
316 this->ptr = other.ptr;
void clear() noexcept
Clears the underlying libcurl handle.
Definition: Curl.hpp:255
CURL ** getPtr() noexcept
Gets a pointer to the pointer containing the address of the underlying libcurl handle.
Definition: Curl.hpp:205
void init()
Initializes the underlying libcurl handle.
Definition: Curl.hpp:230
bool valid() const noexcept
Checks whether the underlying libcurl handle is valid.
Definition: Curl.hpp:214
virtual ~Curl()
Destructor cleaning up the libcurl API locally and globally, if necessary.
Definition: Curl.hpp:172
RAII wrapper for handles of the libcurl API.
Definition: Curl.hpp:70
CURL * get() noexcept
Gets a pointer to the underlying libcurl handle.
Definition: Curl.hpp:193
Curl & operator=(Curl &)=delete
Deleted copy assignment operator.
Namespace for RAII wrappers and Wrapper::Database.
Definition: Database.hpp:109
Curl()
Constructor initializing the libcurl API locally and globally, if necessary.
Definition: Curl.hpp:136