mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- some libcurl usage bugfixes for multi-thread use
This commit is contained in:
parent
385fb0b3f0
commit
4649f761f6
@ -111,6 +111,8 @@ protected:
|
||||
|
||||
static std::map<DebugType,SystemFlagsType> *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();
|
||||
|
@ -40,15 +40,16 @@ namespace Shared{ namespace Util{
|
||||
|
||||
// Init statics
|
||||
std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType> *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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user