summaryrefslogtreecommitdiff
path: root/indra/llmessage
diff options
context:
space:
mode:
authorRider Linden <none@none>2015-04-08 10:17:34 -0700
committerRider Linden <none@none>2015-04-08 10:17:34 -0700
commit1c91c8a106a78f2087a3fb4312e428a0128283b4 (patch)
tree1f80ff372a3a9c2670049f76cde4d6782661dfe9 /indra/llmessage
parentfe34b3ef725b83af0deeffcf8bf6ef9769224e8d (diff)
Adding weak pointer support.
Event polling as a coroutine. (incomplete) Groundwork for canceling HttpCoroutineAdapter yields.
Diffstat (limited to 'indra/llmessage')
-rw-r--r--indra/llmessage/llcorehttputil.cpp81
-rw-r--r--indra/llmessage/llcorehttputil.h30
2 files changed, 59 insertions, 52 deletions
diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp
index 882fef66bc..d560ec8462 100644
--- a/indra/llmessage/llcorehttputil.cpp
+++ b/indra/llmessage/llcorehttputil.cpp
@@ -317,15 +317,18 @@ HttpCoroutineAdapter::HttpCoroutineAdapter(const std::string &name,
LLCore::HttpRequest::policy_t policyId, LLCore::HttpRequest::priority_t priority) :
mAdapterName(name),
mPolicyId(policyId),
- mPriority(priority)
+ mPriority(priority),
+ mYieldingHandle(LLCORE_HTTP_HANDLE_INVALID),
+ mWeakRequest()
{
}
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,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
@@ -353,28 +356,17 @@ LLSD HttpCoroutineAdapter::postAndYield(LLCoros::self & self, LLCore::HttpReques
if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
{
- 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;
+ return HttpCoroutineAdapter::buildImmediateErrorResult(request, url, httpHandler);
}
+ mYieldingHandle = hhandle;
LLSD results = waitForEventOn(self, replyPump);
+ mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
//LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL;
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,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
@@ -402,28 +394,17 @@ LLSD HttpCoroutineAdapter::putAndYield(LLCoros::self & self, LLCore::HttpRequest
if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
{
- 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;
+ return HttpCoroutineAdapter::buildImmediateErrorResult(request, url, httpHandler);
}
+ mYieldingHandle = hhandle;
LLSD results = waitForEventOn(self, replyPump);
+ mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
//LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL;
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,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
@@ -450,26 +431,34 @@ LLSD HttpCoroutineAdapter::getAndYield(LLCoros::self & self, LLCore::HttpRequest
if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
{
- 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;
+ return HttpCoroutineAdapter::buildImmediateErrorResult(request, url, httpHandler);
}
+ mYieldingHandle = hhandle;
LLSD results = waitForEventOn(self, replyPump);
+ mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
//LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL;
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
diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h
index 10f46dd477..33cc389c49 100644
--- a/indra/llmessage/llcorehttputil.h
+++ b/indra/llmessage/llcorehttputil.h
@@ -210,36 +210,54 @@ private:
class HttpCoroutineAdapter
{
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,
LLCore::HttpRequest::priority_t priority = 0L);
~HttpCoroutineAdapter();
/// Execute a Post transaction on the supplied URL and yield execution of
- /// the coroutine until a result is available.
- LLSD postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t & request,
+ /// the coroutine until a result is available.
+ /// 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,
- LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(),
- LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t());
+ LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false),
+ 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
/// 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,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t());
/// Execute a Get transaction on the supplied URL and yield execution of
/// 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,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t());
+ ///
+ void cancelYieldingOperation();
+
private:
+ static LLSD buildImmediateErrorResult(const LLCore::HttpRequest::ptr_t &request,
+ const std::string &url, LLCoreHttpUtil::HttpCoroHandler::ptr_t &httpHandler);
std::string mAdapterName;
LLCore::HttpRequest::priority_t mPriority;
LLCore::HttpRequest::policy_t mPolicyId;
+
+ LLCore::HttpHandle mYieldingHandle;
+ LLCore::HttpRequest::wptr_t mWeakRequest;
+
};
} // end namespace LLCoreHttpUtil