diff options
Diffstat (limited to 'indra/llmessage/llcurl.cpp')
-rw-r--r-- | indra/llmessage/llcurl.cpp | 85 |
1 files changed, 56 insertions, 29 deletions
diff --git a/indra/llmessage/llcurl.cpp b/indra/llmessage/llcurl.cpp index b4ac984d57..8ffa8e4271 100644 --- a/indra/llmessage/llcurl.cpp +++ b/indra/llmessage/llcurl.cpp @@ -133,12 +133,12 @@ std::string LLCurl::getVersionString() ////////////////////////////////////////////////////////////////////////////// LLCurl::Responder::Responder() - : mReferenceCount(0) { } LLCurl::Responder::~Responder() { + LL_CHECK_MEMORY } // virtual @@ -202,23 +202,6 @@ void LLCurl::Responder::completedHeader(U32 status, const std::string& reason, c } -namespace boost -{ - void intrusive_ptr_add_ref(LLCurl::Responder* p) - { - ++p->mReferenceCount; - } - - void intrusive_ptr_release(LLCurl::Responder* p) - { - if (p && 0 == --p->mReferenceCount) - { - delete p; - } - } -}; - - ////////////////////////////////////////////////////////////////////////////// std::set<CURL*> LLCurl::Easy::sFreeHandles; @@ -267,15 +250,18 @@ void LLCurl::Easy::releaseEasyHandle(CURL* handle) LLMutexLock lock(sHandleMutexp) ; if (sActiveHandles.find(handle) != sActiveHandles.end()) { + LL_CHECK_MEMORY sActiveHandles.erase(handle); - + LL_CHECK_MEMORY if(sFreeHandles.size() < MAX_NUM_FREE_HANDLES) { - sFreeHandles.insert(handle); - } - else - { + sFreeHandles.insert(handle); + LL_CHECK_MEMORY + } + else + { LLCurl::deleteEasyHandle(handle) ; + LL_CHECK_MEMORY } } else @@ -308,6 +294,8 @@ LLCurl::Easy* LLCurl::Easy::getEasy() // multi handles cache if they are added to one. CURLcode result = curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0); check_curl_code(result); + result = curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + check_curl_code(result); ++gCurlEasyCount; return easy; @@ -318,13 +306,15 @@ LLCurl::Easy::~Easy() releaseEasyHandle(mCurlEasyHandle); --gCurlEasyCount; curl_slist_free_all(mHeaders); + LL_CHECK_MEMORY for_each(mStrings.begin(), mStrings.end(), DeletePointerArray()); - + LL_CHECK_MEMORY if (mResponder && LLCurl::sNotQuitting) //aborted { std::string reason("Request timeout, aborted.") ; mResponder->completedRaw(408, //HTTP_REQUEST_TIME_OUT, timeout, abort reason, mChannels, mOutput); + LL_CHECK_MEMORY } mResponder = NULL; } @@ -494,7 +484,8 @@ void LLCurl::Easy::prepRequest(const std::string& url, //setopt(CURLOPT_VERBOSE, 1); // useful for debugging setopt(CURLOPT_NOSIGNAL, 1); - + setopt(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + // Set the CURL options for either Socks or HTTP proxy LLProxy::getInstance()->applyProxySettings(this); @@ -599,35 +590,50 @@ void LLCurl::Multi::cleanup(bool deleted) llassert_always(deleted || !mValid) ; LLMutexLock lock(mDeletionMutexp); - + + // Clean up active for(easy_active_list_t::iterator iter = mEasyActiveList.begin(); iter != mEasyActiveList.end(); ++iter) { Easy* easy = *iter; + LL_CHECK_MEMORY check_curl_multi_code(curl_multi_remove_handle(mCurlMultiHandle, easy->getCurlHandle())); - + LL_CHECK_MEMORY if(deleted) { easy->mResponder = NULL ; //avoid triggering mResponder. + LL_CHECK_MEMORY } delete easy; + LL_CHECK_MEMORY } mEasyActiveList.clear(); mEasyActiveMap.clear(); - // Clean up freed + LL_CHECK_MEMORY + + // Clean up freed for_each(mEasyFreeList.begin(), mEasyFreeList.end(), DeletePointer()); mEasyFreeList.clear(); - + + LL_CHECK_MEMORY + check_curl_multi_code(LLCurl::deleteMultiHandle(mCurlMultiHandle)); mCurlMultiHandle = NULL ; + + LL_CHECK_MEMORY delete mMutexp ; mMutexp = NULL ; + + LL_CHECK_MEMORY + delete mEasyMutexp ; mEasyMutexp = NULL ; + LL_CHECK_MEMORY + mQueued = 0 ; mState = STATE_COMPLETED; @@ -1104,6 +1110,7 @@ bool LLCurlRequest::getByteRange(const std::string& url, S32 offset, S32 length, LLCurl::ResponderPtr responder) { + llassert(LLCurl::sNotQuitting); LLCurl::Easy* easy = allocEasy(); if (!easy) { @@ -1131,6 +1138,7 @@ bool LLCurlRequest::post(const std::string& url, const LLSD& data, LLCurl::ResponderPtr responder, S32 time_out) { + llassert(LLCurl::sNotQuitting); LLCurl::Easy* easy = allocEasy(); if (!easy) { @@ -1158,6 +1166,7 @@ bool LLCurlRequest::post(const std::string& url, const std::string& data, LLCurl::ResponderPtr responder, S32 time_out) { + llassert(LLCurl::sNotQuitting); LLCurl::Easy* easy = allocEasy(); if (!easy) { @@ -1714,29 +1723,42 @@ void LLCurl::cleanupClass() break ; } } + LL_CHECK_MEMORY sCurlThread->shutdown() ; + LL_CHECK_MEMORY delete sCurlThread ; sCurlThread = NULL ; + LL_CHECK_MEMORY #if SAFE_SSL CRYPTO_set_locking_callback(NULL); for_each(sSSLMutex.begin(), sSSLMutex.end(), DeletePointer()); #endif + + LL_CHECK_MEMORY for (std::set<CURL*>::iterator iter = Easy::sFreeHandles.begin(); iter != Easy::sFreeHandles.end(); ++iter) { CURL* curl = *iter; LLCurl::deleteEasyHandle(curl); } + + LL_CHECK_MEMORY Easy::sFreeHandles.clear(); + LL_CHECK_MEMORY + delete Easy::sHandleMutexp ; Easy::sHandleMutexp = NULL ; + LL_CHECK_MEMORY + delete sHandleMutexp ; sHandleMutexp = NULL ; + LL_CHECK_MEMORY + // removed as per https://jira.secondlife.com/browse/SH-3115 //llassert(Easy::sActiveHandles.empty()); } @@ -1744,6 +1766,8 @@ void LLCurl::cleanupClass() //static CURLM* LLCurl::newMultiHandle() { + llassert(sNotQuitting); + LLMutexLock lock(sHandleMutexp) ; if(sTotalHandles + 1 > sMaxHandles) @@ -1777,6 +1801,7 @@ CURLMcode LLCurl::deleteMultiHandle(CURLM* handle) //static CURL* LLCurl::newEasyHandle() { + llassert(sNotQuitting); LLMutexLock lock(sHandleMutexp) ; if(sTotalHandles + 1 > sMaxHandles) @@ -1801,7 +1826,9 @@ void LLCurl::deleteEasyHandle(CURL* handle) if(handle) { LLMutexLock lock(sHandleMutexp) ; + LL_CHECK_MEMORY curl_easy_cleanup(handle) ; + LL_CHECK_MEMORY sTotalHandles-- ; } } |