Skip to content
Snippets Groups Projects
Commit 1c91c8a1 authored by Rider Linden's avatar Rider Linden
Browse files

Adding weak pointer support.

Event polling as a coroutine. (incomplete)
Groundwork for canceling HttpCoroutineAdapter yields.
parent fe34b3ef
No related branches found
No related tags found
No related merge requests found
...@@ -190,6 +190,7 @@ ...@@ -190,6 +190,7 @@
#include "linden_common.h" // Modifies curl/curl.h interfaces #include "linden_common.h" // Modifies curl/curl.h interfaces
#include "boost/intrusive_ptr.hpp" #include "boost/intrusive_ptr.hpp"
#include "boost/shared_ptr.hpp" #include "boost/shared_ptr.hpp"
#include "boost/weak_ptr.hpp"
#include "boost/function.hpp" #include "boost/function.hpp"
#include <string> #include <string>
......
...@@ -98,6 +98,7 @@ class HttpRequest ...@@ -98,6 +98,7 @@ class HttpRequest
typedef unsigned int priority_t; typedef unsigned int priority_t;
typedef boost::shared_ptr<HttpRequest> ptr_t; typedef boost::shared_ptr<HttpRequest> ptr_t;
typedef boost::weak_ptr<HttpRequest> wptr_t;
public: public:
/// @name PolicyMethods /// @name PolicyMethods
/// @{ /// @{
......
...@@ -317,15 +317,18 @@ HttpCoroutineAdapter::HttpCoroutineAdapter(const std::string &name, ...@@ -317,15 +317,18 @@ HttpCoroutineAdapter::HttpCoroutineAdapter(const std::string &name,
LLCore::HttpRequest::policy_t policyId, LLCore::HttpRequest::priority_t priority) : LLCore::HttpRequest::policy_t policyId, LLCore::HttpRequest::priority_t priority) :
mAdapterName(name), mAdapterName(name),
mPolicyId(policyId), mPolicyId(policyId),
mPriority(priority) mPriority(priority),
mYieldingHandle(LLCORE_HTTP_HANDLE_INVALID),
mWeakRequest()
{ {
} }
HttpCoroutineAdapter::~HttpCoroutineAdapter() HttpCoroutineAdapter::~HttpCoroutineAdapter()
{ {
} }
LLSD HttpCoroutineAdapter::postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t &request, LLSD HttpCoroutineAdapter::postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, const LLSD & body, const std::string & url, const LLSD & body,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers) LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{ {
...@@ -353,28 +356,17 @@ LLSD HttpCoroutineAdapter::postAndYield(LLCoros::self & self, LLCore::HttpReques ...@@ -353,28 +356,17 @@ LLSD HttpCoroutineAdapter::postAndYield(LLCoros::self & self, LLCore::HttpReques
if (hhandle == LLCORE_HTTP_HANDLE_INVALID) if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
{ {
LLCore::HttpStatus status = request->getStatus(); return HttpCoroutineAdapter::buildImmediateErrorResult(request, url, httpHandler);
LL_WARNS() << "Error posting to " << url << " Status=" << status.getStatus() <<
" message = " << status.getMessage() << LL_ENDL;
// Mimic the status results returned from an http error that we had
// to wait on
LLSD httpresults = LLSD::emptyMap();
httpHandler->writeStatusCodes(status, url, httpresults);
LLSD errorres = LLSD::emptyMap();
errorres["http_result"] = httpresults;
return errorres;
} }
mYieldingHandle = hhandle;
LLSD results = waitForEventOn(self, replyPump); LLSD results = waitForEventOn(self, replyPump);
mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
//LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL; //LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL;
return results; return results;
} }
LLSD HttpCoroutineAdapter::putAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t & request, LLSD HttpCoroutineAdapter::putAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, const LLSD & body, const std::string & url, const LLSD & body,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers) LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{ {
...@@ -402,28 +394,17 @@ LLSD HttpCoroutineAdapter::putAndYield(LLCoros::self & self, LLCore::HttpRequest ...@@ -402,28 +394,17 @@ LLSD HttpCoroutineAdapter::putAndYield(LLCoros::self & self, LLCore::HttpRequest
if (hhandle == LLCORE_HTTP_HANDLE_INVALID) if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
{ {
LLCore::HttpStatus status = request->getStatus(); return HttpCoroutineAdapter::buildImmediateErrorResult(request, url, httpHandler);
LL_WARNS() << "Error posting to " << url << " Status=" << status.getStatus() <<
" message = " << status.getMessage() << LL_ENDL;
// Mimic the status results returned from an http error that we had
// to wait on
LLSD httpresults = LLSD::emptyMap();
httpHandler->writeStatusCodes(status, url, httpresults);
LLSD errorres = LLSD::emptyMap();
errorres["http_result"] = httpresults;
return errorres;
} }
mYieldingHandle = hhandle;
LLSD results = waitForEventOn(self, replyPump); LLSD results = waitForEventOn(self, replyPump);
mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
//LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL; //LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL;
return results; return results;
} }
LLSD HttpCoroutineAdapter::getAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t & request, LLSD HttpCoroutineAdapter::getAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, const std::string & url,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers) LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{ {
...@@ -450,26 +431,34 @@ LLSD HttpCoroutineAdapter::getAndYield(LLCoros::self & self, LLCore::HttpRequest ...@@ -450,26 +431,34 @@ LLSD HttpCoroutineAdapter::getAndYield(LLCoros::self & self, LLCore::HttpRequest
if (hhandle == LLCORE_HTTP_HANDLE_INVALID) if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
{ {
LLCore::HttpStatus status = request->getStatus(); return HttpCoroutineAdapter::buildImmediateErrorResult(request, url, httpHandler);
LL_WARNS() << "Error posting to " << url << " Status=" << status.getStatus() <<
" message = " << status.getMessage() << LL_ENDL;
// Mimic the status results returned from an http error that we had
// to wait on
LLSD httpresults = LLSD::emptyMap();
httpHandler->writeStatusCodes(status, url, httpresults);
LLSD errorres = LLSD::emptyMap();
errorres["http_result"] = httpresults;
return errorres;
} }
mYieldingHandle = hhandle;
LLSD results = waitForEventOn(self, replyPump); LLSD results = waitForEventOn(self, replyPump);
mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
//LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL; //LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL;
return results; return results;
} }
LLSD HttpCoroutineAdapter::buildImmediateErrorResult(const LLCore::HttpRequest::ptr_t &request,
const std::string &url, LLCoreHttpUtil::HttpCoroHandler::ptr_t &httpHandler)
{
LLCore::HttpStatus status = request->getStatus();
LL_WARNS() << "Error posting to " << url << " Status=" << status.getStatus() <<
" message = " << status.getMessage() << LL_ENDL;
// Mimic the status results returned from an http error that we had
// to wait on
LLSD httpresults = LLSD::emptyMap();
httpHandler->writeStatusCodes(status, url, httpresults);
LLSD errorres = LLSD::emptyMap();
errorres["http_result"] = httpresults;
return errorres;
}
} // end namespace LLCoreHttpUtil } // end namespace LLCoreHttpUtil
...@@ -210,36 +210,54 @@ class HttpRequestPumper ...@@ -210,36 +210,54 @@ class HttpRequestPumper
class HttpCoroutineAdapter class HttpCoroutineAdapter
{ {
public: public:
typedef boost::shared_ptr<HttpCoroutineAdapter> ptr_t;
typedef boost::weak_ptr<HttpCoroutineAdapter> wptr_t;
HttpCoroutineAdapter(const std::string &name, LLCore::HttpRequest::policy_t policyId, HttpCoroutineAdapter(const std::string &name, LLCore::HttpRequest::policy_t policyId,
LLCore::HttpRequest::priority_t priority = 0L); LLCore::HttpRequest::priority_t priority = 0L);
~HttpCoroutineAdapter(); ~HttpCoroutineAdapter();
/// Execute a Post transaction on the supplied URL and yield execution of /// Execute a Post transaction on the supplied URL and yield execution of
/// the coroutine until a result is available. /// the coroutine until a result is available.
LLSD postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t & request, /// Note: the request's smart pointer is passed by value so that it will
/// not be deallocated during the yield.
LLSD postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, const LLSD & body, const std::string & url, const LLSD & body,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(), LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t()); LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false));
/// Execute a Put transaction on the supplied URL and yield execution of /// Execute a Put transaction on the supplied URL and yield execution of
/// the coroutine until a result is available. /// the coroutine until a result is available.
LLSD putAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t & request, /// Note: the request's smart pointer is passed by value so that it will
/// not be deallocated during the yield.
LLSD putAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, const LLSD & body, const std::string & url, const LLSD & body,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(), LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t()); LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t());
/// Execute a Get transaction on the supplied URL and yield execution of /// Execute a Get transaction on the supplied URL and yield execution of
/// the coroutine until a result is available. /// the coroutine until a result is available.
LLSD getAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t & request, /// Note: the request's smart pointer is passed by value so that it will
/// not be deallocated during the yield.
LLSD getAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
const std::string & url, const std::string & url,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(), LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t()); LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t());
///
void cancelYieldingOperation();
private: private:
static LLSD buildImmediateErrorResult(const LLCore::HttpRequest::ptr_t &request,
const std::string &url, LLCoreHttpUtil::HttpCoroHandler::ptr_t &httpHandler);
std::string mAdapterName; std::string mAdapterName;
LLCore::HttpRequest::priority_t mPriority; LLCore::HttpRequest::priority_t mPriority;
LLCore::HttpRequest::policy_t mPolicyId; LLCore::HttpRequest::policy_t mPolicyId;
LLCore::HttpHandle mYieldingHandle;
LLCore::HttpRequest::wptr_t mWeakRequest;
}; };
} // end namespace LLCoreHttpUtil } // end namespace LLCoreHttpUtil
......
This diff is collapsed.
...@@ -28,9 +28,20 @@ ...@@ -28,9 +28,20 @@
#define LL_LLEVENTPOLL_H #define LL_LLEVENTPOLL_H
#include "llhttpclient.h" #include "llhttpclient.h"
#include "boost/move/unique_ptr.hpp"
namespace boost
{
using ::boost::movelib::unique_ptr; // move unique_ptr into the boost namespace.
}
class LLHost; class LLHost;
namespace
{
class LLEventPollImpl;
}
class LLEventPoll class LLEventPoll
///< implements the viewer side of server-to-viewer pushed events. ///< implements the viewer side of server-to-viewer pushed events.
...@@ -40,11 +51,15 @@ class LLEventPoll ...@@ -40,11 +51,15 @@ class LLEventPoll
///< Start polling the URL. ///< Start polling the URL.
virtual ~LLEventPoll(); virtual ~LLEventPoll();
///< will stop polling, cancelling any poll in progress. ///< will stop polling, canceling any poll in progress.
private: private:
#if 1
boost::unique_ptr<LLEventPollImpl> mImpl;
#else
LLHTTPClient::ResponderPtr mImpl; LLHTTPClient::ResponderPtr mImpl;
#endif
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment