Skip to content

Commit b86c618

Browse files
committedMay 30, 2022
Fixed multithread issue in CTX. Closes jgaa#128
1 parent 0e09292 commit b86c618

15 files changed

+339
-159
lines changed
 

Diff for: ‎CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if (DEFINED ENV{RESTC_CPP_VERSION})
55
endif()
66

77
if (NOT DEFINED RESTC_CPP_VERSION)
8-
set(RESTC_CPP_VERSION 0.92.0)
8+
set(RESTC_CPP_VERSION 0.93.0)
99
endif()
1010

1111
if(NOT DEFINED RESTC_BOOST_VERSION)
@@ -56,9 +56,9 @@ if (NOT RESTC_CPP_LOG_WITH_INTERNAL_LOG AND NOT RESTC_CPP_LOG_WITH_LOGFAULT AND
5656
set(RESTC_CPP_LOG_WITH_INTERNAL_LOG ON)
5757
endif()
5858

59-
set(RESTC_CPP_LOG_LEVEL_STR "info" CACHE STRING "Limit logs to: none, error, warn, info, debug, trace")
59+
set(RESTC_CPP_LOG_LEVEL_STR "trace" CACHE STRING "Limit logs to: none, error, warn, info, debug, trace")
6060

61-
option(RESTC_CPP_LOG_JSON_SERIALIZATION "Enable trace logging for json serialization debugging")
61+
option(RESTC_CPP_LOG_JSON_SERIALIZATION "Enable trace logging for json serialization debugging" OFF)
6262

6363
option(RESTC_CPP_WITH_ZLIB "Use zlib" ON)
6464

Diff for: ‎include/restc-cpp/ConnectionPool.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConnectionPool
2121
const Connection::Type connectionType,
2222
bool new_connection_please = false) = 0;
2323

24-
virtual std::future<std::size_t> GetIdleConnections() const = 0;
24+
virtual size_t GetIdleConnections() const = 0;
2525
static std::shared_ptr<ConnectionPool> Create(RestClient& owner);
2626

2727
/*! Close the connection-pool

Diff for: ‎include/restc-cpp/Socket.h

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <boost/system/error_code.hpp>
1212

1313
#include "restc-cpp/typename.h"
14+
#include "restc-cpp/logging.h"
15+
1416
#include "error.h"
1517

1618
namespace restc_cpp {
@@ -68,6 +70,10 @@ class ExceptionWrapper {
6870
try {
6971
return fn();
7072
} catch (const boost::system::system_error& ex) {
73+
74+
RESTC_CPP_LOG_TRACE_("ExceptionWrapper: " << ex.what()
75+
<< ", value=" << ex.code());
76+
7177
if (ex.code().value() == boost::system::errc::operation_canceled) {
7278
if (reason_ == Socket::Reason::TIME_OUT) {
7379
throw RequestTimeOutException();

Diff for: ‎include/restc-cpp/internals/helpers.h

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
#else
88
# define LOCK_
99
#endif
10+
11+
#define LOCK_ALWAYS_ std::lock_guard<std::mutex> lock_{mutex_}

Diff for: ‎include/restc-cpp/logging.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class Logger {
107107

108108
}
109109

110-
#define RESTC_CPP_TEST_LOGGING_SETUP(level) RestcCppTestStartLogger(level)
110+
//#define RESTC_CPP_TEST_LOGGING_SETUP(level) RestcCppTestStartLogger(level)
111+
#define RESTC_CPP_TEST_LOGGING_SETUP(level) RestcCppTestStartLogger("trace")
111112

112113
inline void RestcCppTestStartLogger(const std::string& level = "info") {
113114
auto llevel = restc_cpp::LogLevel::INFO;

Diff for: ‎include/restc-cpp/restc-cpp.h

+8
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ class Request {
174174
general_callback_t beforeWriteFn;
175175
general_callback_t afterWriteFn;
176176
std::string bindToLocalAddress; // host:port
177+
#ifdef RESTC_CPP_THREADED_CTX
178+
size_t threads = 4; // Threads created for the Client.
179+
#else
180+
size_t threads = 1;
181+
#endif
177182
};
178183

179184
virtual const Properties& GetProperties() const = 0;
@@ -419,6 +424,8 @@ class RestClient {
419424
*/
420425
virtual void CloseWhenReady(bool wait = true) = 0;
421426

427+
virtual bool IsClosed() const noexcept = 0;
428+
422429
/*! Factory */
423430
static std::unique_ptr<RestClient> Create();
424431

@@ -449,6 +456,7 @@ class RestClient {
449456
static std::unique_ptr<RestClient>
450457
Create(boost::asio::io_service& ioservice);
451458

459+
452460
protected:
453461
virtual std::unique_ptr<DoneHandler> GetDoneHandler() = 0;
454462
};

0 commit comments

Comments
 (0)
Please sign in to comment.