Replace TimeOut with Timeout everywhere.
This commit is contained in:
@@ -850,7 +850,7 @@ class AICurlThread : public LLThread
|
|||||||
curl_socket_t mWakeUpFd_in;
|
curl_socket_t mWakeUpFd_in;
|
||||||
curl_socket_t mWakeUpFd;
|
curl_socket_t mWakeUpFd;
|
||||||
|
|
||||||
int mZeroTimeOut;
|
int mZeroTimeout;
|
||||||
|
|
||||||
volatile bool mRunning;
|
volatile bool mRunning;
|
||||||
};
|
};
|
||||||
@@ -862,7 +862,7 @@ AICurlThread* AICurlThread::sInstance = NULL;
|
|||||||
AICurlThread::AICurlThread(void) : LLThread("AICurlThread"),
|
AICurlThread::AICurlThread(void) : LLThread("AICurlThread"),
|
||||||
mWakeUpFd_in(CURL_SOCKET_BAD),
|
mWakeUpFd_in(CURL_SOCKET_BAD),
|
||||||
mWakeUpFd(CURL_SOCKET_BAD),
|
mWakeUpFd(CURL_SOCKET_BAD),
|
||||||
mZeroTimeOut(0), mRunning(true), mWakeUpFlag(false)
|
mZeroTimeout(0), mRunning(true), mWakeUpFlag(false)
|
||||||
{
|
{
|
||||||
create_wakeup_fds();
|
create_wakeup_fds();
|
||||||
sInstance = this;
|
sInstance = this;
|
||||||
@@ -1304,27 +1304,27 @@ void AICurlThread::run(void)
|
|||||||
// We're now entering select(), during which the main thread will write to the pipe/socket
|
// We're now entering select(), during which the main thread will write to the pipe/socket
|
||||||
// to wake us up, because it can't get the lock.
|
// to wake us up, because it can't get the lock.
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
long timeout_ms = multi_handle_w->getTimeOut();
|
long timeout_ms = multi_handle_w->getTimeout();
|
||||||
// If no timeout is set, sleep 1 second.
|
// If no timeout is set, sleep 1 second.
|
||||||
if (LL_UNLIKELY(timeout_ms < 0))
|
if (LL_UNLIKELY(timeout_ms < 0))
|
||||||
timeout_ms = 1000;
|
timeout_ms = 1000;
|
||||||
if (LL_UNLIKELY(timeout_ms == 0))
|
if (LL_UNLIKELY(timeout_ms == 0))
|
||||||
{
|
{
|
||||||
if (mZeroTimeOut >= 10000)
|
if (mZeroTimeout >= 10000)
|
||||||
{
|
{
|
||||||
if (mZeroTimeOut == 10000)
|
if (mZeroTimeout == 10000)
|
||||||
llwarns << "Detected more than 10000 zero-timeout calls of select() by curl thread (more than 101 seconds)!" << llendl;
|
llwarns << "Detected more than 10000 zero-timeout calls of select() by curl thread (more than 101 seconds)!" << llendl;
|
||||||
}
|
}
|
||||||
else if (mZeroTimeOut >= 1000)
|
else if (mZeroTimeout >= 1000)
|
||||||
timeout_ms = 10;
|
timeout_ms = 10;
|
||||||
else if (mZeroTimeOut >= 100)
|
else if (mZeroTimeout >= 100)
|
||||||
timeout_ms = 1;
|
timeout_ms = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (LL_UNLIKELY(mZeroTimeOut >= 10000))
|
if (LL_UNLIKELY(mZeroTimeout >= 10000))
|
||||||
llinfos << "Timeout of select() call by curl thread reset (to " << timeout_ms << " ms)." << llendl;
|
llinfos << "Timeout of select() call by curl thread reset (to " << timeout_ms << " ms)." << llendl;
|
||||||
mZeroTimeOut = 0;
|
mZeroTimeout = 0;
|
||||||
}
|
}
|
||||||
timeout.tv_sec = timeout_ms / 1000;
|
timeout.tv_sec = timeout_ms / 1000;
|
||||||
timeout.tv_usec = (timeout_ms % 1000) * 1000;
|
timeout.tv_usec = (timeout_ms % 1000) * 1000;
|
||||||
@@ -1497,7 +1497,7 @@ int MultiHandle::timer_callback(CURLM* multi, long timeout_ms, void* userp)
|
|||||||
{
|
{
|
||||||
MultiHandle& self = *static_cast<MultiHandle*>(userp);
|
MultiHandle& self = *static_cast<MultiHandle*>(userp);
|
||||||
llassert(multi == self.mMultiHandle);
|
llassert(multi == self.mMultiHandle);
|
||||||
self.mTimeOut = timeout_ms;
|
self.mTimeout = timeout_ms;
|
||||||
Dout(dc::curl, "MultiHandle::timer_callback(): timeout set to " << timeout_ms << " ms.");
|
Dout(dc::curl, "MultiHandle::timer_callback(): timeout set to " << timeout_ms << " ms.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class MultiHandle : public CurlMultiHandle
|
|||||||
bool mHandleAddedOrRemoved; // Set when an easy handle was added or removed, reset in check_run_count().
|
bool mHandleAddedOrRemoved; // Set when an easy handle was added or removed, reset in check_run_count().
|
||||||
int mPrevRunningHandles; // The last value of mRunningHandles that check_run_count() was called with.
|
int mPrevRunningHandles; // The last value of mRunningHandles that check_run_count() was called with.
|
||||||
int mRunningHandles; // The last value returned by curl_multi_socket_action.
|
int mRunningHandles; // The last value returned by curl_multi_socket_action.
|
||||||
long mTimeOut; // The last time out in ms as set by the callback CURLMOPT_TIMERFUNCTION.
|
long mTimeout; // The last timeout in ms as set by the callback CURLMOPT_TIMERFUNCTION.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Store result and trigger events for easy request.
|
// Store result and trigger events for easy request.
|
||||||
@@ -96,7 +96,7 @@ class MultiHandle : public CurlMultiHandle
|
|||||||
int getRunningHandles(void) const { return mRunningHandles; }
|
int getRunningHandles(void) const { return mRunningHandles; }
|
||||||
|
|
||||||
// Returns how long to wait for socket action before calling socket_action(CURL_SOCKET_TIMEOUT, 0), in ms.
|
// Returns how long to wait for socket action before calling socket_action(CURL_SOCKET_TIMEOUT, 0), in ms.
|
||||||
int getTimeOut(void) const { return mTimeOut; }
|
int getTimeout(void) const { return mTimeout; }
|
||||||
|
|
||||||
// This is called before sleeping, after calling (one or more times) socket_action.
|
// This is called before sleeping, after calling (one or more times) socket_action.
|
||||||
void check_run_count(void);
|
void check_run_count(void);
|
||||||
|
|||||||
@@ -1,153 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file llcurl.cpp
|
|
||||||
* @author Zero / Donovan
|
|
||||||
* @date 2006-10-15
|
|
||||||
* @brief Implementation of wrapper around libcurl.
|
|
||||||
*
|
|
||||||
* $LicenseInfo:firstyear=2006&license=viewerlgpl$
|
|
||||||
* Second Life Viewer Source Code
|
|
||||||
* Copyright (C) 2010, Linden Research, Inc.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation;
|
|
||||||
* version 2.1 of the License only.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
|
|
||||||
* $/LicenseInfo$
|
|
||||||
*/
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
|
||||||
The trick to getting curl to do keep-alives is to reuse the
|
|
||||||
same easy handle for the requests. It appears that curl
|
|
||||||
keeps a pool of connections alive for each easy handle, but
|
|
||||||
doesn't share them between easy handles. Therefore it is
|
|
||||||
important to keep a pool of easy handles and reuse them,
|
|
||||||
rather than create and destroy them with each request. This
|
|
||||||
code does this.
|
|
||||||
|
|
||||||
Furthermore, it would behoove us to keep track of which
|
|
||||||
hosts an easy handle was used for and pick an easy handle
|
|
||||||
that matches the next request. This code does not current
|
|
||||||
do this.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static const U32 EASY_HANDLE_POOL_SIZE = 5;
|
|
||||||
static const S32 MULTI_PERFORM_CALL_REPEAT = 5;
|
|
||||||
static const S32 MAX_ACTIVE_REQUEST_COUNT = 100;
|
|
||||||
|
|
||||||
//static
|
|
||||||
F32 LLCurl::sCurlRequestTimeOut = 120.f; //seconds
|
|
||||||
S32 LLCurl::sMaxHandles = 256; //max number of handles, (multi handles and easy handles combined).
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
AIThreadSafeSimpleDC<LLCurl::Easy::Handles> LLCurl::Easy::sHandles;
|
|
||||||
|
|
||||||
//static
|
|
||||||
CURL* LLCurl::Easy::allocEasyHandle()
|
|
||||||
{
|
|
||||||
llassert(*AIAccess<LLCurlThread*>(LLCurl::getCurlThread())) ;
|
|
||||||
|
|
||||||
CURL* ret = NULL;
|
|
||||||
|
|
||||||
//*** Multi-threaded.
|
|
||||||
AIAccess<Handles> handles_w(sHandles);
|
|
||||||
|
|
||||||
if (handles_w->free.empty())
|
|
||||||
{
|
|
||||||
ret = LLCurl::newEasyHandle();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = *(handles_w->free.begin());
|
|
||||||
handles_w->free.erase(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret)
|
|
||||||
{
|
|
||||||
handles_w->active.insert(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
//static
|
|
||||||
void LLCurl::Easy::releaseEasyHandle(CURL* handle)
|
|
||||||
{
|
|
||||||
DoutEntering(dc::curl, "LLCurl::Easy::releaseEasyHandle(" << (void*)handle << ")");
|
|
||||||
BACKTRACE;
|
|
||||||
|
|
||||||
static const S32 MAX_NUM_FREE_HANDLES = 32 ;
|
|
||||||
|
|
||||||
if (!handle)
|
|
||||||
{
|
|
||||||
return ; //handle allocation failed.
|
|
||||||
//llerrs << "handle cannot be NULL!" << llendl;
|
|
||||||
}
|
|
||||||
|
|
||||||
//*** Multi-Threaded (logout only?)
|
|
||||||
AIAccess<Handles> handles_w(sHandles);
|
|
||||||
|
|
||||||
if (handles_w->active.find(handle) != handles_w->active.end())
|
|
||||||
{
|
|
||||||
handles_w->active.erase(handle);
|
|
||||||
|
|
||||||
if (handles_w->free.size() < MAX_NUM_FREE_HANDLES)
|
|
||||||
{
|
|
||||||
curl_easy_reset(handle);
|
|
||||||
handles_w->free.insert(handle);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LLCurl::deleteEasyHandle(handle) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
llerrs << "Invalid handle." << llendl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LLCurl::Easy::~Easy()
|
|
||||||
{
|
|
||||||
AISTAccess<LLCurl::ResponderPtr> responder_w(mResponder);
|
|
||||||
if (*responder_w && LLCurl::getNotQuitting()) //aborted
|
|
||||||
{
|
|
||||||
std::string reason("Request timeout, aborted.") ;
|
|
||||||
(*responder_w)->completedRaw(408, //HTTP_REQUEST_TIME_OUT, timeout, abort
|
|
||||||
reason, mChannels, mOutput);
|
|
||||||
}
|
|
||||||
*responder_w = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
LLCurl::Easy* LLCurlRequest::allocEasy()
|
|
||||||
{
|
|
||||||
if (!mActiveMulti ||
|
|
||||||
mActiveRequestCount >= MAX_ACTIVE_REQUEST_COUNT ||
|
|
||||||
mActiveMulti->mErrorCount > 0)
|
|
||||||
{
|
|
||||||
addMulti();
|
|
||||||
}
|
|
||||||
if(!mActiveMulti)
|
|
||||||
{
|
|
||||||
return NULL ;
|
|
||||||
}
|
|
||||||
|
|
||||||
//llassert_always(mActiveMulti);
|
|
||||||
++mActiveRequestCount;
|
|
||||||
LLCurl::Easy* easy = mActiveMulti->allocEasy();
|
|
||||||
return easy;
|
|
||||||
}
|
|
||||||
@@ -326,11 +326,11 @@ void LLXMLRPCTransaction::Impl::curlEasyRequestCallback(bool success)
|
|||||||
if (LLApp::isRunning())
|
if (LLApp::isRunning())
|
||||||
{
|
{
|
||||||
std::ostringstream msg;
|
std::ostringstream msg;
|
||||||
F32 timeout_value = gSavedSettings.getF32("CurlRequestTimeOut");
|
F32 timeout_value = gSavedSettings.getF32("CurlRequestTimeout");
|
||||||
msg << "Connection to " << mURI << " timed out (" << timeout_value << " s)!";
|
msg << "Connection to " << mURI << " timed out (" << timeout_value << " s)!";
|
||||||
if (timeout_value < 40)
|
if (timeout_value < 40)
|
||||||
{
|
{
|
||||||
msg << "\nTry increasing CurlRequestTimeOut in Debug Settings.";
|
msg << "\nTry increasing CurlRequestTimeout in Debug Settings.";
|
||||||
}
|
}
|
||||||
setStatus(LLXMLRPCTransaction::StatusOtherError, msg.str());
|
setStatus(LLXMLRPCTransaction::StatusOtherError, msg.str());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user