summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortastytea2020-03-20 13:40:59 +0100
committertastytea2020-03-20 13:49:20 +0100
commitfc32e8ac0a05d1bd86246ae9660e2e289a60bb05 (patch)
tree3626c43f637140a221be4671dce14ef9cc0230d7
parentda1c2ba409a4857ab83f42443419b5fa10790291 (diff)
downloadmastodonpp-fc32e8ac0a05d1bd86246ae9660e2e289a60bb05.tar
mastodonpp-fc32e8ac0a05d1bd86246ae9660e2e289a60bb05.tar.gz
mastodonpp-fc32e8ac0a05d1bd86246ae9660e2e289a60bb05.zip
Add copy constructor for CURLWrapper.
The copy constructor does the same as the constructor. A new CURL handle is used for the “copy”.
-rw-r--r--include/curl_wrapper.hpp15
-rw-r--r--src/curl_wrapper.cpp21
2 files changed, 31 insertions, 5 deletions
diff --git a/include/curl_wrapper.hpp b/include/curl_wrapper.hpp
index 6eb9d93..ffe0876 100644
--- a/include/curl_wrapper.hpp
+++ b/include/curl_wrapper.hpp
@@ -70,8 +70,12 @@ public:
*/
CURLWrapper();
- //! Copy constructor
- CURLWrapper(const CURLWrapper &other) = delete;
+ /*!
+ * @brief Copy constructor. Does the same as the Constructor.
+ *
+ * @since 0.5.2
+ */
+ CURLWrapper(const CURLWrapper &);
//! Move constructor
CURLWrapper(CURLWrapper &&other) noexcept = delete;
@@ -254,6 +258,13 @@ private:
bool _stream_cancelled;
/*!
+ * @brief Initializes curl and sets up connection.
+ *
+ * @since 0.5.2
+ */
+ void init();
+
+ /*!
* @brief libcurl write callback function.
*
* @since 0.1.0
diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp
index 9341069..0d78e6d 100644
--- a/src/curl_wrapper.cpp
+++ b/src/curl_wrapper.cpp
@@ -41,9 +41,7 @@ using std::uint16_t;
// No one will ever need more than 65535 connections. 😉
static atomic<uint16_t> curlwrapper_instances{0};
-CURLWrapper::CURLWrapper()
- : _curl_buffer_error{}
- , _stream_cancelled{false}
+void CURLWrapper::init()
{
if (curlwrapper_instances == 0)
{
@@ -55,6 +53,23 @@ CURLWrapper::CURLWrapper()
_connection = curl_easy_init();
setup_curl();
}
+
+CURLWrapper::CURLWrapper()
+ : _connection{}
+ , _curl_buffer_error{}
+ , _stream_cancelled{false}
+{
+ init();
+}
+
+CURLWrapper::CURLWrapper(const CURLWrapper &)
+ : _connection{}
+ , _curl_buffer_error{}
+ , _stream_cancelled{false}
+{
+ init();
+}
+
CURLWrapper::~CURLWrapper() noexcept
{
curl_easy_cleanup(_connection);