Skip to content

Commit f758a48

Browse files
author
Sergey Shambir
committed
Disabled copying for curl_global, added curl_global_cleanup call in destructor
Also moved function definitions to cpp file Fix for issue "curl_global should call cleanup in destructor" #103
1 parent 7b8d468 commit f758a48

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

include/curl_global.h

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,20 @@ namespace curl {
4646
* with user specified flag.
4747
*/
4848
explicit curl_global(const long);
49+
50+
/**
51+
* Copying disabled to follow RAII idiom.
52+
*/
53+
curl_global(const curl_global&) = delete;
54+
curl_global& operator=(const curl_global&) = delete;
55+
4956
/**
5057
* The virtual destructor will provide an easy and clean
5158
* way to deallocate resources, closing curl environment
5259
* correctly.
5360
*/
5461
virtual ~curl_global();
5562
};
56-
57-
// Implementation of constructor.
58-
curl_global::curl_global() {
59-
const CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
60-
if (code != CURLE_OK) {
61-
throw curl_easy_exception(code,__FUNCTION__);
62-
}
63-
}
64-
65-
// Implementation of overloaded constructor.
66-
curl_global::curl_global(const long flag) {
67-
const CURLcode code = curl_global_init(flag);
68-
if (code != CURLE_OK) {
69-
throw curl_easy_exception(code,__FUNCTION__);
70-
}
71-
}
72-
73-
// Implementation of the virtual destructor.
74-
curl_global::~curl_global() {
75-
}
7663
}
7764

7865
#endif /* defined(__curlcpp__curl_global__) */

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(CURLCPP_SOURCE
22
curl_easy.cpp
33
curl_header.cpp
4+
curl_global.cpp
45
curl_form.cpp
56
curl_multi.cpp
67
curl_share.cpp

src/curl_global.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "curl_global.h"
2+
3+
using curl::curl_global;
4+
5+
curl_global::curl_global()
6+
{
7+
const CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
8+
if (code != CURLE_OK) {
9+
throw curl_easy_exception(code, __FUNCTION__);
10+
}
11+
}
12+
13+
curl_global::curl_global(const long flag)
14+
{
15+
const CURLcode code = curl_global_init(flag);
16+
if (code != CURLE_OK) {
17+
throw curl_easy_exception(code, __FUNCTION__);
18+
}
19+
}
20+
21+
curl_global::~curl_global()
22+
{
23+
curl_global_cleanup();
24+
}

0 commit comments

Comments
 (0)