diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index b7bb8066..fe1cfae4 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -111,6 +111,8 @@ protected: static std::map *debugLogFileList; static bool haveSpecialOutputCommandLineOption; + static bool curl_global_init_called; + public: static CURL *curl_handle; @@ -128,7 +130,7 @@ public: static std::string escapeURL(std::string URL, CURL *handle=NULL); static CURL *initHTTP(); - static void cleanupHTTP(CURL **handle); + static void cleanupHTTP(CURL **handle,bool globalCleanup=false); static bool getThreadedLoggerRunning(); static std::size_t getLogEntryBufferCount(); diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 76794c49..928c6b3b 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -40,15 +40,16 @@ namespace Shared{ namespace Util{ // Init statics std::map *SystemFlags::debugLogFileList = NULL; -int SystemFlags::lockFile = -1; -int SystemFlags::lockFileCountIndex = -1; -string SystemFlags::lockfilename = ""; -bool SystemFlags::haveSpecialOutputCommandLineOption = false; -CURL *SystemFlags::curl_handle = NULL; -int SystemFlags::DEFAULT_HTTP_TIMEOUT = 10; -bool SystemFlags::VERBOSE_MODE_ENABLED = false; -bool SystemFlags::ENABLE_THREADED_LOGGING = false; -static LogFileThread *threadLogger = NULL; +int SystemFlags::lockFile = -1; +int SystemFlags::lockFileCountIndex = -1; +string SystemFlags::lockfilename = ""; +bool SystemFlags::haveSpecialOutputCommandLineOption = false; +CURL *SystemFlags::curl_handle = NULL; +bool SystemFlags::curl_global_init_called = false; +int SystemFlags::DEFAULT_HTTP_TIMEOUT = 10; +bool SystemFlags::VERBOSE_MODE_ENABLED = false; +bool SystemFlags::ENABLE_THREADED_LOGGING = false; +static LogFileThread *threadLogger = NULL; // static void *myrealloc(void *ptr, size_t size) @@ -145,8 +146,6 @@ std::string SystemFlags::getHTTP(std::string URL,CURL *handle,int timeOut) { } curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, timeOut); - curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1); - /* get contents from the URL */ CURLcode result = curl_easy_perform(handle); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] return code [%d] [%s]\n",__FILE__,__FUNCTION__,__LINE__,result,errbuf); @@ -165,8 +164,12 @@ std::string SystemFlags::getHTTP(std::string URL,CURL *handle,int timeOut) { } CURL *SystemFlags::initHTTP() { - curl_global_init(CURL_GLOBAL_ALL); + if(SystemFlags::curl_global_init_called == false) { + SystemFlags::curl_global_init_called = true; + curl_global_init(CURL_GLOBAL_ALL); + } CURL *handle = curl_easy_init(); + curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1); return handle; } @@ -224,11 +227,17 @@ SystemFlags::SystemFlags() { } -void SystemFlags::cleanupHTTP(CURL **handle) { +void SystemFlags::cleanupHTTP(CURL **handle, bool globalCleanup) { if(handle != NULL && *handle != NULL) { curl_easy_cleanup(*handle); *handle = NULL; - curl_global_cleanup(); + + if(globalCleanup == true) { + if(SystemFlags::curl_global_init_called == true) { + SystemFlags::curl_global_init_called = false; + curl_global_cleanup(); + } + } } } @@ -236,7 +245,7 @@ SystemFlags::~SystemFlags() { SystemFlags::Close(); if(curl_handle != NULL) { - SystemFlags::cleanupHTTP(&curl_handle); + SystemFlags::cleanupHTTP(&curl_handle, true); curl_handle = NULL; } }