Changes to HTTPManager and it's clean-up sequence. Main thread now "joins" the network thread and thus waits for all the requests to be done. (Remember me to start a discussion on the memory leak checker!)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13671 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-09-12 18:23:56 +00:00
parent e71d99aa2d
commit 2c1d02095a
6 changed files with 20 additions and 15 deletions

View File

@ -1191,6 +1191,7 @@ void initRest()
// to network_http (since the thread might use network_http, otherwise
// a race condition can be introduced resulting in a crash).
INetworkHttp::get()->startNetworkThread();
Online::HTTPManager::get()->startNetworkThread();
music_manager = new MusicManager();
sfx_manager = new SFXManager();
// The order here can be important, e.g. KartPropertiesManager needs
@ -1297,6 +1298,7 @@ void cleanSuperTuxKart()
StateManager::deallocate();
GUIEngine::EventHandler::deallocate();
Online::HTTPManager::deallocate();
} // cleanSuperTuxKart
//=============================================================================

View File

@ -229,7 +229,7 @@ namespace Online{
{
if(!success)
{
Log::warn("CurrentUser::signOut", "%s", _("There were some connection issues while signing out. Report a bug if this caused issues."));
Log::warn("CurrentUser::signOut", "%s", "There were some connection issues while signing out. Report a bug if this caused issues.");
}
m_token = "";
ProfileManager::get()->clearPersistent();
@ -623,7 +623,7 @@ namespace Online{
{
if(isRegisteredUser())
{
XMLRequest * request = new XMLRequest(true, HTTPManager::MAX_PRIORITY);
HTTPRequest * request = new HTTPRequest(true, HTTPManager::MAX_PRIORITY);
request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
request->setParameter("action", std::string("client-quit"));
request->setParameter("token", getToken());

View File

@ -57,16 +57,17 @@ namespace Online{
if (http_singleton == NULL)
{
http_singleton = new HTTPManager();
http_singleton->startNetworkThread();
CurrentUser::get()->requestSavedSession();
}
return http_singleton;
} // get
void HTTPManager::deallocate()
{
delete http_singleton;
http_singleton = NULL;
if (http_singleton != NULL)
{
delete http_singleton;
http_singleton = NULL;
}
} // deallocate
bool HTTPManager::isRunning()
@ -84,6 +85,11 @@ namespace Online{
// ============================================================================
HTTPManager::~HTTPManager(){
m_thread_id.lock();
pthread_join(*m_thread_id.getData(), NULL);
delete m_thread_id.getData();
m_thread_id.unlock();
pthread_cond_destroy(&m_cond_request);
curl_global_cleanup();
}
@ -116,10 +122,10 @@ namespace Online{
Log::error("HTTP Manager", "Could not create thread, error=%d.\n", errno);
}
pthread_attr_destroy(&attr);
CurrentUser::get()->requestSavedSession();
} // startNetworkThread
// ---------------------------------------------------------------------------
/** This function inserts a high priority request to quit into the request
* queue of the network thead, and also aborts any ongoing download.
@ -188,7 +194,7 @@ namespace Online{
{
HTTPManager *me = (HTTPManager*) obj;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
//pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
me->m_current_request = NULL;
me->m_request_queue.lock();
@ -221,7 +227,6 @@ namespace Online{
delete request;
}
me->m_request_queue.unlock();
HTTPManager::deallocate();
pthread_exit(NULL);
return 0;
} // mainLoop

View File

@ -76,8 +76,6 @@ namespace Online{
void handleResultQueue();
static void *mainLoop(void *obj);
void startNetworkThread();
static void deallocate();
HTTPManager(); //const std::string &url
~HTTPManager();
@ -87,6 +85,7 @@ namespace Online{
// singleton
static HTTPManager* get();
static void deallocate();
static bool isRunning();
//Execute
@ -96,6 +95,7 @@ namespace Online{
void synchronousRequest(Online::Request *request);
void addRequest(Online::Request *request);
void cancelAllDownloads();
void startNetworkThread();
void stopNetworkThread();
bool getAbort(){ return m_abort.getAtomic(); };

View File

@ -103,6 +103,7 @@ namespace Online{
curl_easy_setopt(m_curl_session, CURLOPT_CAINFO, (file_manager->getDataDir() + "web.tuxfamily.org.pem").c_str());
curl_easy_setopt(m_curl_session, CURLOPT_SSL_VERIFYPEER, 0L);
//curl_easy_setopt(m_curl_session, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(m_curl_session, CURLOPT_WRITEDATA, &m_string_buffer);
}
void HTTPRequest::operation()
@ -222,7 +223,6 @@ namespace Online{
void XMLRequest::prepareOperation()
{
HTTPRequest::prepareOperation();
curl_easy_setopt(m_curl_session, CURLOPT_WRITEDATA, &m_string_buffer);
}

View File

@ -150,6 +150,7 @@ namespace Online{
Parameters * m_parameters;
CURL * m_curl_session;
CURLcode m_curl_code;
std::string m_string_buffer;
virtual void prepareOperation() OVERRIDE;
virtual void operation() OVERRIDE;
@ -201,9 +202,6 @@ namespace Online{
class XMLRequest : public HTTPRequest
{
private:
std::string m_string_buffer;
protected :
XMLNode * m_result;
irr::core::stringw m_info;