Skip to content

Commit f3c5499

Browse files
committed
Fixed examples
Added clear_traceback method which clears the error stack in a thread safe way.
1 parent 162b98a commit f3c5499

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ int main(int argc, const char **argv) {
7070
curlcpp_traceback errors = error.get_traceback();
7171
// Otherwise we could print the stack like this:
7272
error.print_traceback();
73-
// Note that the printing the stack will erase it
7473
}
7574
return 0;
7675
}
@@ -108,7 +107,6 @@ int main(int argc, const char **argv) {
108107
curlcpp_traceback errors = error.get_traceback();
109108
// Otherwise we could print the stack like this:
110109
error.print_traceback();
111-
// Note that the printing the stack will erase it
112110
}
113111
114112
// Retrieve information about curl current session.
@@ -162,7 +160,6 @@ int main(int argc, const char * argv[]) {
162160
curlcpp_traceback errors = error.get_traceback();
163161
// Otherwise we could print the stack like this:
164162
error.print_traceback();
165-
// Note that the printing the stack will erase it
166163
}
167164
return 0;
168165
}
@@ -210,7 +207,6 @@ int main(int argc, const char * argv[]) {
210207
curlcpp_traceback errors = error.get_traceback();
211208
// Otherwise we could print the stack like this:
212209
error.print_traceback();
213-
// Note that the printing the stack will erase it
214210
}
215211
myfile.close();
216212
return 0;
@@ -256,7 +252,6 @@ int main() {
256252
curlcpp_traceback errors = error.get_traceback();
257253
// Otherwise we could print the stack like this:
258254
error.print_traceback();
259-
// Note that the printing the stack will erase it
260255
}
261256
// Let's print the stream content.
262257
cout<<str.str()<<endl;
@@ -305,7 +300,6 @@ int main(int argc, const char * argv[]) {
305300
curlcpp_traceback errors = error.get_traceback();
306301
// Otherwise we could print the stack like this:
307302
error.print_traceback();
308-
// Note that the printing the stack will erase it
309303
}
310304

311305
// Creation of a sender. You should wait here using select to check if socket is ready to send.

include/curl_exception.h

+11
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ namespace curl {
6969
* Simple method which prints the entire error stack.
7070
*/
7171
void print_traceback() const;
72+
/**
73+
* Simple method which clears the entire error stack.
74+
*/
75+
void clear_traceback() const;
7276
private:
7377
/**
7478
* The error container must be static or will be cleared
@@ -88,6 +92,13 @@ namespace curl {
8892
std::cout<<"ERROR: "<<value.first<<" ::::: FUNCTION: "<<value.second<<std::endl;
8993
});
9094
}
95+
96+
// Implementation of clear method.
97+
inline void curl_exception::clear_traceback() const {
98+
curl_exception::tracebackLocker.lock();
99+
curl_exception::traceback.clear();
100+
curl_exception::tracebackLocker.unlock();
101+
}
91102

92103
// Implementation of get_traceback.
93104
inline curlcpp_traceback curl_exception::get_traceback() const {

src/curl_exception.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
using curl::curl_exception;
99
using curl::curlcpp_traceback;
1010

11-
// Need to define the traceback here to separate declaration from definition, or we'll get a linker error.
11+
// Need to define the traceback here to separate declaration from definition, or we'll get a linker error...
1212
curlcpp_traceback curl::curl_exception::traceback;
13-
13+
// .. same for the traceback mutexe.
1414
std::mutex curl::curl_exception::tracebackLocker;
1515

1616
// Constructor implementation. Every call will push into the calls stack the function name and the error occurred.
1717
curl_exception::curl_exception(const std::string &error, const std::string &fun_name) {
1818
curl_exception::tracebackLocker.lock();
19-
2019
curl_exception::traceback.insert(curl_exception::traceback.begin(),curlcpp_traceback_object(error,fun_name));
21-
2220
curl_exception::tracebackLocker.unlock();
2321
}
2422

test/easy.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ using curl::curl_easy;
44
using curl::curl_easy_exception;
55

66
/*
7-
* This example shows how to make a simple request with
8-
* curl.
7+
* This example shows how to make a simple request with curl.
98
*/
109

1110
int main() {
@@ -22,7 +21,6 @@ int main() {
2221
auto errors = error.what();
2322
// Otherwise we could print the stack like this:
2423
error.print_traceback();
25-
// Note that the printing the stack will erase it
2624
}
2725
return 0;
2826
}

test/easy_info.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ int main(int argc, const char **argv) {
2727
curlcpp_traceback errors = error.get_traceback();
2828
// Otherwise we could print the stack like this:
2929
error.print_traceback();
30-
// Note that the printing the stack will erase it
3130
}
3231
// Retrieve information about curl current session.
3332
auto x = easy.get_info<char>(CURLINFO_CONTENT_TYPE);

0 commit comments

Comments
 (0)