summaryrefslogtreecommitdiff
path: root/indra/llcorehttp/_httpoperation.cpp
diff options
context:
space:
mode:
authorRider Linden <rider@lindenlab.com>2015-10-16 11:40:48 -0700
committerRider Linden <rider@lindenlab.com>2015-10-16 11:40:48 -0700
commit8d334ca1bf51dc1a0020f53cdd7a3927bdb7740c (patch)
treeb5624a2a6f94c5e6e1c748fc1c4ae3e77ceda5d2 /indra/llcorehttp/_httpoperation.cpp
parent302e5780694a6f271807d0804db0c6fc6923026f (diff)
MAINT-5271: Converted internal pointers to internal operation to managed shared pointers. Removed direct cast and dereference of handles.
Diffstat (limited to 'indra/llcorehttp/_httpoperation.cpp')
-rwxr-xr-xindra/llcorehttp/_httpoperation.cpp100
1 files changed, 81 insertions, 19 deletions
diff --git a/indra/llcorehttp/_httpoperation.cpp b/indra/llcorehttp/_httpoperation.cpp
index dc03b059a4..333f20d281 100755
--- a/indra/llcorehttp/_httpoperation.cpp
+++ b/indra/llcorehttp/_httpoperation.cpp
@@ -53,15 +53,18 @@ namespace LLCore
// ==================================
// HttpOperation
// ==================================
-
-
-HttpOperation::HttpOperation()
- : LLCoreInt::RefCounted(true),
- mReplyQueue(),
- mUserHandler(),
- mReqPolicy(HttpRequest::DEFAULT_POLICY_ID),
- mReqPriority(0U),
- mTracing(HTTP_TRACE_OFF)
+/*static*/
+HttpOperation::handleMap_t HttpOperation::mHandleMap;
+LLCoreInt::HttpMutex HttpOperation::mOpMutex;
+
+HttpOperation::HttpOperation():
+ boost::enable_shared_from_this<HttpOperation>(),
+ mReplyQueue(),
+ mUserHandler(),
+ mReqPolicy(HttpRequest::DEFAULT_POLICY_ID),
+ mReqPriority(0U),
+ mTracing(HTTP_TRACE_OFF),
+ mMyHandle(LLCORE_HTTP_HANDLE_INVALID)
{
mMetricCreated = totalTime();
}
@@ -69,7 +72,9 @@ HttpOperation::HttpOperation()
HttpOperation::~HttpOperation()
{
- setReplyPath(HttpReplyQueue::ptr_t(), HttpHandler::ptr_t());
+ destroyHandle();
+ mReplyQueue.reset();
+ mUserHandler.reset();
}
@@ -119,7 +124,7 @@ void HttpOperation::visitNotifier(HttpRequest *)
HttpResponse * response = new HttpResponse();
response->setStatus(mStatus);
- mUserHandler->onCompleted(static_cast<HttpHandle>(this), response);
+ mUserHandler->onCompleted(getHandle(), response);
response->release();
}
@@ -133,20 +138,80 @@ HttpStatus HttpOperation::cancel()
return status;
}
+// Handle methods
+HttpHandle HttpOperation::getHandle()
+{
+ if (mMyHandle == LLCORE_HTTP_HANDLE_INVALID)
+ return createHandle();
+
+ return mMyHandle;
+}
+
+HttpHandle HttpOperation::createHandle()
+{
+ HttpHandle handle = static_cast<HttpHandle>(this);
+
+ {
+ LLCoreInt::HttpScopedLock lock(mOpMutex);
+
+ mHandleMap[handle] = shared_from_this();
+ mMyHandle = handle;
+ }
+
+ return mMyHandle;
+}
+
+void HttpOperation::destroyHandle()
+{
+ if (mMyHandle == LLCORE_HTTP_HANDLE_INVALID)
+ return;
+ {
+ LLCoreInt::HttpScopedLock lock(mOpMutex);
+
+ handleMap_t::iterator it = mHandleMap.find(mMyHandle);
+ if (it != mHandleMap.end())
+ mHandleMap.erase(it);
+ }
+}
+
+/*static*/
+HttpOperation::ptr_t HttpOperation::findByHandle(HttpHandle handle)
+{
+ wptr_t weak;
+
+ {
+ LLCoreInt::HttpScopedLock lock(mOpMutex);
+
+ handleMap_t::iterator it = mHandleMap.find(handle);
+ if (it == mHandleMap.end())
+ {
+ LL_WARNS("LLCore::HTTP") << "Could not find operation for handle " << handle << LL_ENDL;
+ return ptr_t();
+ }
+
+ weak = (*it).second;
+ }
+
+ if (!weak.expired())
+ return weak.lock();
+
+ return ptr_t();
+}
+
void HttpOperation::addAsReply()
{
if (mTracing > HTTP_TRACE_OFF)
{
LL_INFOS(LOG_CORE) << "TRACE, ToReplyQueue, Handle: "
- << static_cast<HttpHandle>(this)
+ << getHandle()
<< LL_ENDL;
}
if (mReplyQueue)
{
- addRef();
- mReplyQueue->addOp(this);
+ HttpOperation::ptr_t op = shared_from_this();
+ mReplyQueue->addOp(op);
}
}
@@ -229,11 +294,8 @@ void HttpOpSpin::stageFromRequest(HttpService * service)
else
{
ms_sleep(1); // backoff interlock plumbing a bit
- this->addRef();
- if (! service->getRequestQueue().addOp(this))
- {
- this->release();
- }
+ HttpOperation::ptr_t opptr = shared_from_this();
+ service->getRequestQueue().addOp(opptr);
}
}