auto-initialize

This commit is contained in:
John
2022-02-12 08:05:59 +01:00
parent 2f92ea5477
commit f1a5d87aab
2 changed files with 14 additions and 1 deletions
+6
View File
@@ -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
+8 -1
View File
@@ -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;