diff --git a/src/lib/utils/httpclient.cpp b/src/lib/utils/httpclient.cpp index 02a9c838..442076d3 100755 --- a/src/lib/utils/httpclient.cpp +++ b/src/lib/utils/httpclient.cpp @@ -208,7 +208,13 @@ SSLSocket* SSLSocket::connect(const string& host, const uint16_t& port, bool htt return nullptr; } +bool HttpClient::s_initialized = false; + void HttpClient::initialize() { + if (s_initialized) { + return; + } + s_initialized = true; SSL_library_init(); SSL_load_error_strings(); signal(SIGPIPE, SIG_IGN); // needed to avoid SIGPIPE when writing to a closed pipe diff --git a/src/lib/utils/httpclient.h b/src/lib/utils/httpclient.h index 9897fd14..f9fc3cb9 100755 --- a/src/lib/utils/httpclient.h +++ b/src/lib/utils/httpclient.h @@ -120,7 +120,9 @@ class HttpClient { /** * Constructor. */ - HttpClient() : m_socket(nullptr), m_port(0), m_timeout(0), m_bufferSize(0), m_buffer(nullptr) {} + HttpClient() : m_socket(nullptr), m_port(0), m_timeout(0), m_bufferSize(0), m_buffer(nullptr) { + initialize(); + } /** * Destructor. @@ -218,6 +220,11 @@ class HttpClient { size_t readUntil(const string& delim, const size_t length, string* result); private: +#ifdef HAVE_SSL + /** true once @a initialize() was called. */ + static bool s_initialized; +#endif + /** the currently connected socket. */ SocketClass* m_socket;