Improve curl/ares init behavior by duping handles instead of calling easy_init
parent
df08808640
commit
2dcbbf04c9
5408
autobuild.xml
5408
autobuild.xml
File diff suppressed because it is too large
Load Diff
|
|
@ -339,7 +339,6 @@ void HttpOpRequest::setupCommon(HttpRequest::policy_t policy_id,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Sets all libcurl options and data for a request.
|
||||
//
|
||||
// Used both for initial requests and to 'reload' for
|
||||
|
|
@ -381,13 +380,7 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service)
|
|||
// Get policy options
|
||||
HttpPolicyGlobal & policy(service->getPolicy().getGlobalOptions());
|
||||
|
||||
mCurlHandle = curl_easy_init();
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_NOPROGRESS, 1);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_URL, mReqURL.c_str());
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_PRIVATE, this);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_ENCODING, "");
|
||||
mCurlHandle = LLCurlHandleHandler::getInstance()->CreateCurlHandle();
|
||||
|
||||
if (HTTP_ENABLE_LINKSYS_WRT54G_V5_DNS_FIX)
|
||||
{
|
||||
|
|
@ -399,23 +392,14 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service)
|
|||
// seconds and no RSTs.
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_DNS_CACHE_TIMEOUT, 15);
|
||||
}
|
||||
else
|
||||
{
|
||||
// *TODO: Revisit this old DNS timeout setting - may no longer be valid
|
||||
// I don't think this is valid anymore, the Multi shared DNS
|
||||
// cache is working well. For the case of naked easy handles,
|
||||
// consider using a shared DNS object.
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0);
|
||||
}
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_AUTOREFERER, 1);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_MAXREDIRS, HTTP_REDIRECTS_DEFAULT);
|
||||
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_WRITEFUNCTION, writeCallback);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_WRITEDATA, this);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_READFUNCTION, readCallback);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_READFUNCTION, readCallback);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_READDATA, this);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_SSL_VERIFYPEER, 1);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_WRITEDATA, this);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_URL, mReqURL.c_str());
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_PRIVATE, this);
|
||||
curl_easy_setopt(mCurlHandle, CURLOPT_MAXREDIRS, HTTP_REDIRECTS_DEFAULT);
|
||||
|
||||
const std::string * opt_value(NULL);
|
||||
long opt_long(0L);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
|
||||
#include "linden_common.h" // Modifies curl/curl.h interfaces
|
||||
#include "llsingleton.h"
|
||||
|
||||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
|
|
@ -60,12 +61,13 @@ class HttpOptions;
|
|||
/// the information needed to make a working request which can
|
||||
/// then be enqueued to a request queue.
|
||||
///
|
||||
|
||||
class HttpOpRequest : public HttpOperation
|
||||
{
|
||||
public:
|
||||
HttpOpRequest();
|
||||
|
||||
friend class CurlHandleHandler;
|
||||
|
||||
protected:
|
||||
virtual ~HttpOpRequest(); // Use release()
|
||||
|
||||
|
|
|
|||
|
|
@ -1813,10 +1813,10 @@ CURL* LLCurl::newEasyHandle()
|
|||
}
|
||||
sTotalHandles++;
|
||||
|
||||
CURL* ret = curl_easy_init() ;
|
||||
CURL* ret = LLCurlHandleHandler::getInstance()->CreateCurlHandle();
|
||||
if(!ret)
|
||||
{
|
||||
llwarns << "curl_easy_init failed." << llendl ;
|
||||
llwarns << "failed to create curl handle." << llendl ;
|
||||
}
|
||||
|
||||
return ret ;
|
||||
|
|
@ -1846,3 +1846,24 @@ void LLCurlFF::check_multi_code(CURLMcode code)
|
|||
{
|
||||
check_curl_multi_code(code);
|
||||
}
|
||||
|
||||
CURL* LLCurlHandleHandler::the_one_true_curl_handle;
|
||||
|
||||
LLCurlHandleHandler::LLCurlHandleHandler()
|
||||
{
|
||||
the_one_true_curl_handle = curl_easy_init();
|
||||
curl_easy_setopt(the_one_true_curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
curl_easy_setopt(the_one_true_curl_handle, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(the_one_true_curl_handle, CURLOPT_NOPROGRESS, 1);
|
||||
curl_easy_setopt(the_one_true_curl_handle, CURLOPT_ENCODING, "");
|
||||
curl_easy_setopt(the_one_true_curl_handle, CURLOPT_AUTOREFERER, 1);
|
||||
curl_easy_setopt(the_one_true_curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(the_one_true_curl_handle, CURLOPT_SSL_VERIFYPEER, 1);
|
||||
curl_easy_setopt(the_one_true_curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_easy_setopt(the_one_true_curl_handle, CURLOPT_DNS_CACHE_TIMEOUT, 0);
|
||||
}
|
||||
|
||||
CURL* LLCurlHandleHandler::CreateCurlHandle()
|
||||
{
|
||||
return curl_easy_duphandle(the_one_true_curl_handle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
#include "llqueuedthread.h"
|
||||
#include "llframetimer.h"
|
||||
#include "llpointer.h"
|
||||
|
||||
#include "llsingleton.h"
|
||||
|
||||
class LLMutex;
|
||||
class LLCurlThread;
|
||||
|
|
@ -53,6 +53,14 @@ class LLCurlThread;
|
|||
// For whatever reason, this is not typedef'd in curl.h
|
||||
typedef size_t (*curl_header_callback)(void *ptr, size_t size, size_t nmemb, void *stream);
|
||||
|
||||
class LLCurlHandleHandler : public LLSingleton<LLCurlHandleHandler>
|
||||
{
|
||||
public:
|
||||
static CURL* the_one_true_curl_handle;
|
||||
LLCurlHandleHandler();
|
||||
static CURL* CreateCurlHandle();
|
||||
};
|
||||
|
||||
class LLCurl
|
||||
{
|
||||
LOG_CLASS(LLCurl);
|
||||
|
|
|
|||
Loading…
Reference in New Issue