Files
SingularityViewer/indra/llmessage/llurlrequest.h
Aleric Inglewood b9b5f13624 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.
2013-03-07 01:52:21 +01:00

115 lines
3.5 KiB
C++

/**
* @file llurlrequest.h
* @author Phoenix
* @date 2005-04-21
* @brief Declaration of url based requests on pipes.
*
* $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
* Copyright (C) 2012, Aleric Inglewood.
*
* 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$
*/
#ifndef LL_LLURLREQUEST_H
#define LL_LLURLREQUEST_H
/**
* This file holds the declaration of useful classes for dealing with
* url based client requests.
*/
#include <string>
#include "aicurleasyrequeststatemachine.h"
#include "aihttpheaders.h"
class Injector
{
public:
typedef LLHTTPClient::ResponderBase::buffer_ptr_t buffer_ptr_t;
virtual char const* contentType(void) const = 0;
virtual U32 get_body(LLChannelDescriptors const& channels, buffer_ptr_t& buffer) = 0;
// To avoid compiler warning.
virtual ~Injector() { }
};
class LLURLRequest : public AICurlEasyRequestStateMachine {
public:
typedef LLHTTPClient::ERequestAction ERequestAction;
/**
* @brief Turn the request action into an http verb.
*/
static std::string actionAsVerb(ERequestAction action);
/**
* @brief Constructor.
*
* @param action One of the ERequestAction enumerations.
* @param url The url of the request. It should already be encoded.
*/
LLURLRequest(ERequestAction action, std::string const& url, Injector* body, LLHTTPClient::ResponderPtr responder, AIHTTPHeaders& headers, bool keepalive, bool is_auth, bool no_compression);
protected:
// Call abort(), not delete.
/*virtual*/ ~LLURLRequest() { }
public:
/**
* @ brief Turn off (or on) the CURLOPT_PROXY header.
*/
void useProxy(bool use_proxy);
/**
* @brief Add a header to the http post.
*
* The header must be correctly formatted for HTTP requests. This
* provides a raw interface if you know what kind of request you
* will be making during construction of this instance. All
* required headers will be automatically constructed, so this is
* usually useful for encoding parameters.
*/
void addHeader(char const* header);
private:
/**
* @brief Handle action specific url request configuration.
*
* @return Returns true if this is configured.
*/
bool configure(AICurlEasyRequest_wat const& curlEasyRequest_w);
private:
ERequestAction mAction;
std::string mURL;
bool mKeepAlive; // Set to false only when explicitely requested.
bool mIsAuth; // Set for authentication messages (login, buy land, buy currency).
bool mNoCompression; // Set to disable using gzip.
Injector* mBody; // Non-zero iff the action is HTTP_POST and HTTP_PUT.
U32 mBodySize;
LLHTTPClient::ResponderPtr mResponder;
AIHTTPHeaders mHeaders;
protected:
// Handle initializing the object.
/*virtual*/ void initialize_impl(void);
};
#endif // LL_LLURLREQUEST_H