Run HTTPGetResponder in any thread.
This fixes a bug where unref() was called when a state machine was aborted before it reached bs_initialized. Debug code was added to detect errors related to that. In order to run HTTPGetResponder in any thread, I needed direct access to LLHTTPClient::request, so I had to move that to the header file, and therefore had to move ERequestAction from LLURLRequest to LLHTTPClient to avoid include problems. With this, textures are fetched with no latency: call to LLHTTPClient::request runs all the way till the state machine is idle (AICurlEasyRequestStateMachine_waitAdded). There is small delay till the curl thread wakes up, which then processes the request and opens the url etc. When the transaction is finished, it calls AIStateMachine::advance_state(AICurlEasyRequestStateMachine_removed_after_finished) which subsequently doesn't return until the state machine is completely finished (bs_killed). The LLURLRequest isn't deleted yet at that point because the AITimer of the LLURLRequest runs in the main thread: it is aborted, but only the next time the main thread state engines run that is deleted and the timer keeps an LLPointer to it's parent, the LLURLRequest, so only then the LLURLRequest object is destructed. This however has nothing to do with the texture-bandwidth loop.
This commit is contained in:
@@ -52,8 +52,6 @@
|
||||
#include "stdtypes.h" // U16, S32, U32, F64
|
||||
#include "llatomic.h" // LLAtomicU32
|
||||
#include "aithreadsafe.h"
|
||||
#include "llhttpstatuscodes.h"
|
||||
#include "llhttpclient.h"
|
||||
|
||||
// Debug Settings.
|
||||
extern bool gNoVerifySSLCert;
|
||||
|
||||
@@ -36,9 +36,11 @@
|
||||
#include "llrefcount.h"
|
||||
#include "aicurlperhost.h"
|
||||
#include "aihttptimeout.h"
|
||||
#include "llhttpclient.h"
|
||||
|
||||
class AIHTTPHeaders;
|
||||
class AICurlEasyRequestStateMachine;
|
||||
class AITransferInfo;
|
||||
|
||||
namespace AICurlPrivate {
|
||||
|
||||
|
||||
@@ -195,18 +195,20 @@ public:
|
||||
LLAssetType::EType mAssetType;
|
||||
};
|
||||
|
||||
static void request(
|
||||
const std::string& url,
|
||||
//static
|
||||
void LLHTTPClient::request(
|
||||
std::string const& url,
|
||||
LLURLRequest::ERequestAction method,
|
||||
Injector* body_injector,
|
||||
LLHTTPClient::ResponderPtr responder,
|
||||
AIHTTPHeaders& headers/*,*/
|
||||
DEBUG_CURLIO_PARAM(EDebugCurl debug),
|
||||
EKeepAlive keepalive = keep_alive,
|
||||
bool is_auth = false,
|
||||
bool no_compression = false,
|
||||
AIStateMachine* parent = NULL,
|
||||
AIStateMachine::state_type new_parent_state = 0)
|
||||
EKeepAlive keepalive,
|
||||
bool is_auth,
|
||||
bool no_compression,
|
||||
AIStateMachine* parent,
|
||||
AIStateMachine::state_type new_parent_state,
|
||||
AIEngine* default_engine)
|
||||
{
|
||||
llassert(responder);
|
||||
|
||||
@@ -231,7 +233,7 @@ static void request(
|
||||
return ;
|
||||
}
|
||||
|
||||
req->run(parent, new_parent_state, parent != NULL);
|
||||
req->run(parent, new_parent_state, parent != NULL, true, default_engine);
|
||||
}
|
||||
|
||||
void LLHTTPClient::getByteRange(std::string const& url, S32 offset, S32 bytes, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug))
|
||||
@@ -240,22 +242,22 @@ void LLHTTPClient::getByteRange(std::string const& url, S32 offset, S32 bytes, R
|
||||
{
|
||||
headers.addHeader("Range", llformat("bytes=%d-%d", offset, offset + bytes - 1));
|
||||
}
|
||||
request(url, LLURLRequest::HTTP_GET, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
request(url, HTTP_GET, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
}
|
||||
|
||||
void LLHTTPClient::head(std::string const& url, ResponderHeadersOnly* responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug))
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_HEAD, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
request(url, HTTP_HEAD, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
}
|
||||
|
||||
void LLHTTPClient::get(std::string const& url, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug))
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_GET, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
request(url, HTTP_GET, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
}
|
||||
|
||||
void LLHTTPClient::getHeaderOnly(std::string const& url, ResponderHeadersOnly* responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug))
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_HEAD, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
request(url, HTTP_HEAD, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
}
|
||||
|
||||
void LLHTTPClient::get(std::string const& url, LLSD const& query, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug))
|
||||
@@ -686,17 +688,17 @@ U32 LLHTTPClient::blockingGetRaw(const std::string& url, std::string& body/*,*/
|
||||
|
||||
void LLHTTPClient::put(std::string const& url, LLSD const& body, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug))
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_PUT, new LLSDInjector(body), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
request(url, HTTP_PUT, new LLSDInjector(body), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
}
|
||||
|
||||
void LLHTTPClient::post(std::string const& url, LLSD const& body, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug), EKeepAlive keepalive, AIStateMachine* parent, AIStateMachine::state_type new_parent_state)
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_POST, new LLSDInjector(body), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive, false, false, parent, new_parent_state);
|
||||
request(url, HTTP_POST, new LLSDInjector(body), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive, false, false, parent, new_parent_state);
|
||||
}
|
||||
|
||||
void LLHTTPClient::postXMLRPC(std::string const& url, XMLRPC_REQUEST xmlrpc_request, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug), EKeepAlive keepalive)
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_POST, new XMLRPCInjector(xmlrpc_request), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive, true, false); // Does use compression.
|
||||
request(url, HTTP_POST, new XMLRPCInjector(xmlrpc_request), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive, true, false); // Does use compression.
|
||||
}
|
||||
|
||||
void LLHTTPClient::postXMLRPC(std::string const& url, char const* method, XMLRPC_VALUE value, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug), EKeepAlive keepalive)
|
||||
@@ -707,33 +709,33 @@ void LLHTTPClient::postXMLRPC(std::string const& url, char const* method, XMLRPC
|
||||
XMLRPC_RequestSetData(xmlrpc_request, value);
|
||||
// XMLRPCInjector takes ownership of xmlrpc_request and will free it when done.
|
||||
// LLURLRequest takes ownership of the XMLRPCInjector object and will free it when done.
|
||||
request(url, LLURLRequest::HTTP_POST, new XMLRPCInjector(xmlrpc_request), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive, true, true); // Does not use compression.
|
||||
request(url, HTTP_POST, new XMLRPCInjector(xmlrpc_request), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive, true, true); // Does not use compression.
|
||||
}
|
||||
|
||||
void LLHTTPClient::postRaw(std::string const& url, char const* data, S32 size, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug), EKeepAlive keepalive)
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_POST, new RawInjector(data, size), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive);
|
||||
request(url, HTTP_POST, new RawInjector(data, size), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive);
|
||||
}
|
||||
|
||||
void LLHTTPClient::postFile(std::string const& url, std::string const& filename, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug), EKeepAlive keepalive)
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_POST, new FileInjector(filename), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive);
|
||||
request(url, HTTP_POST, new FileInjector(filename), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive);
|
||||
}
|
||||
|
||||
void LLHTTPClient::postFile(std::string const& url, LLUUID const& uuid, LLAssetType::EType asset_type, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug), EKeepAlive keepalive)
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_POST, new VFileInjector(uuid, asset_type), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive);
|
||||
request(url, HTTP_POST, new VFileInjector(uuid, asset_type), responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug), keepalive);
|
||||
}
|
||||
|
||||
// static
|
||||
void LLHTTPClient::del(std::string const& url, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug))
|
||||
{
|
||||
request(url, LLURLRequest::HTTP_DELETE, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
request(url, HTTP_DELETE, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
}
|
||||
|
||||
// static
|
||||
void LLHTTPClient::move(std::string const& url, std::string const& destination, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug))
|
||||
{
|
||||
headers.addHeader("Destination", destination);
|
||||
request(url, LLURLRequest::HTTP_MOVE, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
request(url, HTTP_MOVE, NULL, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug));
|
||||
}
|
||||
|
||||
@@ -46,10 +46,13 @@ class AIHTTPTimeoutPolicy;
|
||||
class LLBufferArray;
|
||||
class LLChannelDescriptors;
|
||||
class AIStateMachine;
|
||||
class Injector;
|
||||
class AIEngine;
|
||||
|
||||
extern AIHTTPTimeoutPolicy responderIgnore_timeout;
|
||||
typedef struct _xmlrpc_request* XMLRPC_REQUEST;
|
||||
typedef struct _xmlrpc_value* XMLRPC_VALUE;
|
||||
extern AIEngine gMainThreadEngine;
|
||||
|
||||
// Output parameter of AICurlPrivate::CurlEasyRequest::getResult.
|
||||
// Used in XMLRPCResponder.
|
||||
@@ -84,6 +87,20 @@ enum EDebugCurl {
|
||||
|
||||
class LLHTTPClient {
|
||||
public:
|
||||
/**
|
||||
* @brief This enumeration is for specifying the type of request.
|
||||
*/
|
||||
enum ERequestAction
|
||||
{
|
||||
INVALID,
|
||||
HTTP_HEAD,
|
||||
HTTP_GET,
|
||||
HTTP_PUT,
|
||||
HTTP_POST,
|
||||
HTTP_DELETE,
|
||||
HTTP_MOVE, // Caller will need to set 'Destination' header
|
||||
REQUEST_ACTION_COUNT
|
||||
};
|
||||
|
||||
/** @name Responder base classes */
|
||||
//@{
|
||||
@@ -393,6 +410,21 @@ public:
|
||||
|
||||
//@}
|
||||
|
||||
/** General API to request a transfer. */
|
||||
static void request(
|
||||
std::string const& url,
|
||||
ERequestAction method,
|
||||
Injector* body_injector,
|
||||
ResponderPtr responder,
|
||||
AIHTTPHeaders& headers/*,*/
|
||||
DEBUG_CURLIO_PARAM(EDebugCurl debug),
|
||||
EKeepAlive keepalive = keep_alive,
|
||||
bool is_auth = false,
|
||||
bool no_compression = false,
|
||||
AIStateMachine* parent = NULL,
|
||||
/*AIStateMachine::state_type*/ U32 new_parent_state = 0,
|
||||
AIEngine* default_engine = &gMainThreadEngine);
|
||||
|
||||
/** @name non-blocking API */
|
||||
//@{
|
||||
static void head(std::string const& url, ResponderHeadersOnly* responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug = debug_off));
|
||||
|
||||
@@ -61,7 +61,7 @@ const std::string CONTEXT_TRANSFERED_BYTES("transfered_bytes");
|
||||
// static
|
||||
std::string LLURLRequest::actionAsVerb(LLURLRequest::ERequestAction action)
|
||||
{
|
||||
static int const array_size = HTTP_MOVE + 1; // INVALID == 0
|
||||
static int const array_size = LLHTTPClient::REQUEST_ACTION_COUNT; // INVALID == 0
|
||||
static char const* const VERBS[array_size] =
|
||||
{
|
||||
"(invalid)",
|
||||
@@ -72,7 +72,7 @@ std::string LLURLRequest::actionAsVerb(LLURLRequest::ERequestAction action)
|
||||
"DELETE",
|
||||
"MOVE"
|
||||
};
|
||||
return VERBS[action >= array_size ? INVALID : action];
|
||||
return VERBS[action >= array_size ? LLHTTPClient::INVALID : action];
|
||||
}
|
||||
|
||||
// This might throw AICurlNoEasyHandle.
|
||||
@@ -94,13 +94,13 @@ void LLURLRequest::initialize_impl(void)
|
||||
useProxy(false);
|
||||
}
|
||||
|
||||
if (mAction == HTTP_PUT || mAction == HTTP_POST)
|
||||
if (mAction == LLHTTPClient::HTTP_PUT || mAction == LLHTTPClient::HTTP_POST)
|
||||
{
|
||||
// If the Content-Type header was passed in we defer to the caller's wisdom,
|
||||
// but if they did not specify a Content-Type, then ask the injector.
|
||||
mHeaders.addHeader("Content-Type", mBody->contentType(), AIHTTPHeaders::keep_existing_header);
|
||||
}
|
||||
else if (mAction != HTTP_HEAD)
|
||||
else if (mAction != LLHTTPClient::HTTP_HEAD)
|
||||
{
|
||||
// Check to see if we have already set Accept or not. If no one
|
||||
// set it, set it to application/llsd+xml since that's what we
|
||||
@@ -108,7 +108,7 @@ void LLURLRequest::initialize_impl(void)
|
||||
mHeaders.addHeader("Accept", "application/llsd+xml", AIHTTPHeaders::keep_existing_header);
|
||||
}
|
||||
|
||||
if (mAction == HTTP_POST && gMessageSystem)
|
||||
if (mAction == LLHTTPClient::HTTP_POST && gMessageSystem)
|
||||
{
|
||||
mHeaders.addHeader("X-SecondLife-UDP-Listen-Port", llformat("%d", gMessageSystem->mPort));
|
||||
}
|
||||
@@ -200,12 +200,12 @@ bool LLURLRequest::configure(AICurlEasyRequest_wat const& curlEasyRequest_w)
|
||||
{
|
||||
switch(mAction)
|
||||
{
|
||||
case HTTP_HEAD:
|
||||
case LLHTTPClient::HTTP_HEAD:
|
||||
curlEasyRequest_w->setopt(CURLOPT_NOBODY, 1);
|
||||
rv = true;
|
||||
break;
|
||||
|
||||
case HTTP_GET:
|
||||
case LLHTTPClient::HTTP_GET:
|
||||
curlEasyRequest_w->setopt(CURLOPT_HTTPGET, 1);
|
||||
|
||||
// Set Accept-Encoding to allow response compression
|
||||
@@ -213,7 +213,7 @@ bool LLURLRequest::configure(AICurlEasyRequest_wat const& curlEasyRequest_w)
|
||||
rv = true;
|
||||
break;
|
||||
|
||||
case HTTP_PUT:
|
||||
case LLHTTPClient::HTTP_PUT:
|
||||
{
|
||||
// Disable the expect http 1.1 extension. POST and PUT default
|
||||
// to using this, causing the broken server to get confused.
|
||||
@@ -223,7 +223,7 @@ bool LLURLRequest::configure(AICurlEasyRequest_wat const& curlEasyRequest_w)
|
||||
rv = true;
|
||||
break;
|
||||
}
|
||||
case HTTP_POST:
|
||||
case LLHTTPClient::HTTP_POST:
|
||||
{
|
||||
// Set the handle for an http post
|
||||
curlEasyRequest_w->setPost(mBodySize, mKeepAlive);
|
||||
@@ -233,13 +233,13 @@ bool LLURLRequest::configure(AICurlEasyRequest_wat const& curlEasyRequest_w)
|
||||
rv = true;
|
||||
break;
|
||||
}
|
||||
case HTTP_DELETE:
|
||||
case LLHTTPClient::HTTP_DELETE:
|
||||
// Set the handle for an http post
|
||||
curlEasyRequest_w->setoptString(CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
rv = true;
|
||||
break;
|
||||
|
||||
case HTTP_MOVE:
|
||||
case LLHTTPClient::HTTP_MOVE:
|
||||
// Set the handle for an http post
|
||||
curlEasyRequest_w->setoptString(CURLOPT_CUSTOMREQUEST, "MOVE");
|
||||
rv = true;
|
||||
|
||||
@@ -51,20 +51,7 @@ class Injector
|
||||
|
||||
class LLURLRequest : public AICurlEasyRequestStateMachine {
|
||||
public:
|
||||
/**
|
||||
* @brief This enumeration is for specifying the type of request.
|
||||
*/
|
||||
enum ERequestAction
|
||||
{
|
||||
INVALID,
|
||||
HTTP_HEAD,
|
||||
HTTP_GET,
|
||||
HTTP_PUT,
|
||||
HTTP_POST,
|
||||
HTTP_DELETE,
|
||||
HTTP_MOVE, // Caller will need to set 'Destination' header
|
||||
REQUEST_ACTION_COUNT
|
||||
};
|
||||
typedef LLHTTPClient::ERequestAction ERequestAction;
|
||||
|
||||
/**
|
||||
* @brief Turn the request action into an http verb.
|
||||
|
||||
Reference in New Issue
Block a user