Skip to content

Commit b88ab3b

Browse files
committed
implement RestClient::init() and RestClient::disable()
1 parent a8cb9c5 commit b88ab3b

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

include/restclient-cpp/restclient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ typedef struct {
4141
HeaderFields headers;
4242
} Response;
4343

44-
// init function
45-
void init();
44+
// init and disable functions
45+
int init();
4646
void disable();
4747

4848
/**

source/restclient.cc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,32 @@
1212
*/
1313

1414
#include "restclient-cpp/restclient.h"
15-
#include "restclient-cpp/version.h"
1615

16+
#include <curl/curl.h>
17+
18+
#include "restclient-cpp/version.h"
1719
#include "restclient-cpp/connection.h"
1820

21+
/**
22+
* @brief global init function. Call this before you start any threads.
23+
*/
24+
int RestClient::init() {
25+
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
26+
if (res == CURLE_OK) {
27+
return 0;
28+
} else {
29+
return 1;
30+
}
31+
}
32+
33+
/**
34+
* @brief global disable function. Call this before you terminate your
35+
* program.
36+
*/
37+
void RestClient::disable() {
38+
curl_global_cleanup();
39+
}
40+
1941
/**
2042
* @brief HTTP GET method
2143
*

test/test_restclient.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ class RestClientTest : public ::testing::Test
1717

1818
virtual void SetUp()
1919
{
20+
RestClient::init();
2021
}
2122

2223
virtual void TearDown()
2324
{
25+
RestClient::disable();
2426
}
2527

2628
};

0 commit comments

Comments
 (0)