summaryrefslogtreecommitdiff
path: root/indra/llmessage
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage')
-rw-r--r--indra/llmessage/llcorehttputil.cpp104
-rw-r--r--indra/llmessage/llcorehttputil.h37
2 files changed, 85 insertions, 56 deletions
diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp
index d560ec8462..dd9cb2032a 100644
--- a/indra/llmessage/llcorehttputil.cpp
+++ b/indra/llmessage/llcorehttputil.cpp
@@ -199,6 +199,12 @@ void HttpCoroHandler::onCompleted(LLCore::HttpHandle handle, LLCore::HttpRespons
LLCore::HttpStatus status = response->getStatus();
+ if (status == LLCore::HttpStatus(LLCore::HttpStatus::LLCORE, LLCore::HE_HANDLE_NOT_FOUND))
+ { // A response came in for a canceled request and we have not processed the
+ // cancel yet. Patience!
+ return;
+ }
+
if (!status)
{
result = LLSD::emptyMap();
@@ -290,6 +296,14 @@ void HttpCoroHandler::writeStatusCodes(LLCore::HttpStatus status, const std::str
}
+LLCore::HttpStatus HttpCoroHandler::getStatusFromLLSD(const LLSD &httpResults)
+{
+ LLCore::HttpStatus::type_enum_t type = static_cast<LLCore::HttpStatus::type_enum_t>(httpResults["type"].asInteger());
+ short code = static_cast<short>(httpResults["status"].asInteger());
+
+ return LLCore::HttpStatus(type, code);
+}
+
//========================================================================
HttpRequestPumper::HttpRequestPumper(const LLCore::HttpRequest::ptr_t &request) :
mHttpRequest(request)
@@ -308,7 +322,10 @@ HttpRequestPumper::~HttpRequestPumper()
bool HttpRequestPumper::pollRequest(const LLSD&)
{
- mHttpRequest->update(0L);
+ if (mHttpRequest->getStatus() != HttpStatus(HttpStatus::LLCORE, HE_OP_CANCELED))
+ {
+ mHttpRequest->update(0L);
+ }
return false;
}
@@ -319,29 +336,20 @@ HttpCoroutineAdapter::HttpCoroutineAdapter(const std::string &name,
mPolicyId(policyId),
mPriority(priority),
mYieldingHandle(LLCORE_HTTP_HANDLE_INVALID),
- mWeakRequest()
+ mWeakRequest(),
+ mWeakHandler()
{
}
HttpCoroutineAdapter::~HttpCoroutineAdapter()
{
-
+ cancelYieldingOperation();
}
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)
{
- if (!options)
- {
- options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false);
- }
-
- if (!headers)
- {
- headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false);
- }
-
LLEventStream replyPump(mAdapterName, true);
LLCoreHttpUtil::HttpCoroHandler::ptr_t httpHandler =
LLCoreHttpUtil::HttpCoroHandler::ptr_t(new LLCoreHttpUtil::HttpCoroHandler(replyPump));
@@ -356,12 +364,13 @@ LLSD HttpCoroutineAdapter::postAndYield(LLCoros::self & self, LLCore::HttpReques
if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
{
- return HttpCoroutineAdapter::buildImmediateErrorResult(request, url, httpHandler);
+ return HttpCoroutineAdapter::buildImmediateErrorResult(request, url);
}
- mYieldingHandle = hhandle;
+ saveState(hhandle, request, httpHandler);
LLSD results = waitForEventOn(self, replyPump);
- mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
+ cleanState();
+
//LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL;
return results;
}
@@ -370,16 +379,6 @@ LLSD HttpCoroutineAdapter::putAndYield(LLCoros::self & self, LLCore::HttpRequest
const std::string & url, const LLSD & body,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
- if (!options)
- {
- options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false);
- }
-
- if (!headers)
- {
- headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false);
- }
-
LLEventStream replyPump(mAdapterName, true);
LLCoreHttpUtil::HttpCoroHandler::ptr_t httpHandler =
LLCoreHttpUtil::HttpCoroHandler::ptr_t(new LLCoreHttpUtil::HttpCoroHandler(replyPump));
@@ -394,12 +393,12 @@ LLSD HttpCoroutineAdapter::putAndYield(LLCoros::self & self, LLCore::HttpRequest
if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
{
- return HttpCoroutineAdapter::buildImmediateErrorResult(request, url, httpHandler);
+ return HttpCoroutineAdapter::buildImmediateErrorResult(request, url);
}
- mYieldingHandle = hhandle;
+ saveState(hhandle, request, httpHandler);
LLSD results = waitForEventOn(self, replyPump);
- mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
+ cleanState();
//LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL;
return results;
}
@@ -408,16 +407,6 @@ LLSD HttpCoroutineAdapter::getAndYield(LLCoros::self & self, LLCore::HttpRequest
const std::string & url,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
- if (!options)
- {
- options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false);
- }
-
- if (!headers)
- {
- headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false);
- }
-
LLEventStream replyPump(mAdapterName + "Reply", true);
LLCoreHttpUtil::HttpCoroHandler::ptr_t httpHandler =
LLCoreHttpUtil::HttpCoroHandler::ptr_t(new LLCoreHttpUtil::HttpCoroHandler(replyPump));
@@ -431,18 +420,45 @@ LLSD HttpCoroutineAdapter::getAndYield(LLCoros::self & self, LLCore::HttpRequest
if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
{
- return HttpCoroutineAdapter::buildImmediateErrorResult(request, url, httpHandler);
+ return HttpCoroutineAdapter::buildImmediateErrorResult(request, url);
}
- mYieldingHandle = hhandle;
+ saveState(hhandle, request, httpHandler);
LLSD results = waitForEventOn(self, replyPump);
- mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
+ cleanState();
//LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL;
return results;
}
+void HttpCoroutineAdapter::cancelYieldingOperation()
+{
+ LLCore::HttpRequest::ptr_t request = mWeakRequest.lock();
+ HttpCoroHandler::ptr_t handler = mWeakHandler.lock();
+ if ((request) && (handler) && (mYieldingHandle != LLCORE_HTTP_HANDLE_INVALID))
+ {
+ cleanState();
+ LL_INFOS() << "Canceling yielding request!" << LL_ENDL;
+ request->requestCancel(mYieldingHandle, handler.get());
+ }
+}
+
+void HttpCoroutineAdapter::saveState(LLCore::HttpHandle yieldingHandle,
+ LLCore::HttpRequest::ptr_t &request, HttpCoroHandler::ptr_t &handler)
+{
+ mWeakRequest = request;
+ mWeakHandler = handler;
+ mYieldingHandle = yieldingHandle;
+}
+
+void HttpCoroutineAdapter::cleanState()
+{
+ mWeakRequest.reset();
+ mWeakHandler.reset();
+ mYieldingHandle = LLCORE_HTTP_HANDLE_INVALID;
+}
+
LLSD HttpCoroutineAdapter::buildImmediateErrorResult(const LLCore::HttpRequest::ptr_t &request,
- const std::string &url, LLCoreHttpUtil::HttpCoroHandler::ptr_t &httpHandler)
+ const std::string &url)
{
LLCore::HttpStatus status = request->getStatus();
LL_WARNS() << "Error posting to " << url << " Status=" << status.getStatus() <<
@@ -452,7 +468,7 @@ LLSD HttpCoroutineAdapter::buildImmediateErrorResult(const LLCore::HttpRequest::
// to wait on
LLSD httpresults = LLSD::emptyMap();
- httpHandler->writeStatusCodes(status, url, httpresults);
+ HttpCoroHandler::writeStatusCodes(status, url, httpresults);
LLSD errorres = LLSD::emptyMap();
errorres["http_result"] = httpresults;
diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h
index 33cc389c49..471710f61b 100644
--- a/indra/llmessage/llcorehttputil.h
+++ b/indra/llmessage/llcorehttputil.h
@@ -170,13 +170,16 @@ LLCore::HttpHandle requestPutWithLLSD(LLCore::HttpRequest::ptr_t & request,
class HttpCoroHandler : public LLCore::HttpHandler
{
public:
+ typedef boost::shared_ptr<HttpCoroHandler> ptr_t;
+ typedef boost::weak_ptr<HttpCoroHandler> wptr_t;
+
HttpCoroHandler(LLEventStream &reply);
virtual void onCompleted(LLCore::HttpHandle handle, LLCore::HttpResponse * response);
- typedef boost::shared_ptr<HttpCoroHandler> ptr_t;
+ static void writeStatusCodes(LLCore::HttpStatus status, const std::string &url, LLSD &result);
+ static LLCore::HttpStatus getStatusFromLLSD(const LLSD &httpResults);
- void writeStatusCodes(LLCore::HttpStatus status, const std::string &url, LLSD &result);
private:
void buildStatusEntry(LLCore::HttpResponse *response, LLCore::HttpStatus status, LLSD &result);
@@ -219,7 +222,8 @@ public:
/// Execute a Post transaction on the supplied URL and yield execution of
/// the coroutine until a result is available.
- /// Note: the request's smart pointer is passed by value so that it will
+ ///
+ /// @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,
@@ -228,28 +232,34 @@ public:
/// Execute a Put transaction on the supplied URL and yield execution of
/// the coroutine until a result is available.
- /// Note: the request's smart pointer is passed by value so that it will
+ ///
+ /// @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());
+ 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 Get transaction on the supplied URL and yield execution of
/// the coroutine until a result is available.
- /// Note: the request's smart pointer is passed by value so that it will
+ ///
+ /// @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());
+ 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));
///
void cancelYieldingOperation();
private:
- static LLSD buildImmediateErrorResult(const LLCore::HttpRequest::ptr_t &request,
- const std::string &url, LLCoreHttpUtil::HttpCoroHandler::ptr_t &httpHandler);
+ static LLSD buildImmediateErrorResult(const LLCore::HttpRequest::ptr_t &request, const std::string &url);
+
+ void saveState(LLCore::HttpHandle yieldingHandle, LLCore::HttpRequest::ptr_t &request,
+ HttpCoroHandler::ptr_t &handler);
+ void cleanState();
+
std::string mAdapterName;
LLCore::HttpRequest::priority_t mPriority;
@@ -257,9 +267,12 @@ private:
LLCore::HttpHandle mYieldingHandle;
LLCore::HttpRequest::wptr_t mWeakRequest;
-
+ HttpCoroHandler::wptr_t mWeakHandler;
};
+//-------------------------------------------------------------------------
+LLCore::HttpStatus getStatusFromLLSD(const LLSD &httpResults);
+
} // end namespace LLCoreHttpUtil
#endif // LL_LLCOREHTTPUTIL_H