auto-initialize
This commit is contained in:
@@ -208,7 +208,13 @@ SSLSocket* SSLSocket::connect(const string& host, const uint16_t& port, bool htt
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HttpClient::s_initialized = false;
|
||||||
|
|
||||||
void HttpClient::initialize() {
|
void HttpClient::initialize() {
|
||||||
|
if (s_initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s_initialized = true;
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
SSL_load_error_strings();
|
SSL_load_error_strings();
|
||||||
signal(SIGPIPE, SIG_IGN); // needed to avoid SIGPIPE when writing to a closed pipe
|
signal(SIGPIPE, SIG_IGN); // needed to avoid SIGPIPE when writing to a closed pipe
|
||||||
|
|||||||
@@ -120,7 +120,9 @@ class HttpClient {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* 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.
|
* Destructor.
|
||||||
@@ -218,6 +220,11 @@ class HttpClient {
|
|||||||
size_t readUntil(const string& delim, const size_t length, string* result);
|
size_t readUntil(const string& delim, const size_t length, string* result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef HAVE_SSL
|
||||||
|
/** true once @a initialize() was called. */
|
||||||
|
static bool s_initialized;
|
||||||
|
#endif
|
||||||
|
|
||||||
/** the currently connected socket. */
|
/** the currently connected socket. */
|
||||||
SocketClass* m_socket;
|
SocketClass* m_socket;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user