From 6f4d36634e980bb989b9a8b762c3c622804c43dd Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Mon, 16 Mar 2015 17:14:34 -0700 Subject: Removal of RPCXML dep on LLCurl switching to LLCore::Html --- indra/llcorehttp/_httpservice.cpp | 80 ++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 10 deletions(-) (limited to 'indra/llcorehttp/_httpservice.cpp') diff --git a/indra/llcorehttp/_httpservice.cpp b/indra/llcorehttp/_httpservice.cpp index c673e1be1d..7b8aac35a8 100755 --- a/indra/llcorehttp/_httpservice.cpp +++ b/indra/llcorehttp/_httpservice.cpp @@ -53,15 +53,16 @@ namespace LLCore const HttpService::OptionDescriptor HttpService::sOptionDesc[] = { // isLong isDynamic isGlobal isClass - { true, true, true, true }, // PO_CONNECTION_LIMIT - { true, true, false, true }, // PO_PER_HOST_CONNECTION_LIMIT - { false, false, true, false }, // PO_CA_PATH - { false, false, true, false }, // PO_CA_FILE - { false, true, true, false }, // PO_HTTP_PROXY - { true, true, true, false }, // PO_LLPROXY - { true, true, true, false }, // PO_TRACE - { true, true, false, true }, // PO_ENABLE_PIPELINING - { true, true, false, true } // PO_THROTTLE_RATE + { true, true, true, true, false }, // PO_CONNECTION_LIMIT + { true, true, false, true, false }, // PO_PER_HOST_CONNECTION_LIMIT + { false, false, true, false, false }, // PO_CA_PATH + { false, false, true, false, false }, // PO_CA_FILE + { false, true, true, false, false }, // PO_HTTP_PROXY + { true, true, true, false, false }, // PO_LLPROXY + { true, true, true, false, false }, // PO_TRACE + { true, true, false, true, false }, // PO_ENABLE_PIPELINING + { true, true, false, true, false }, // PO_THROTTLE_RATE + { false, false, true, false, true } // PO_SSL_VERIFY_CALLBACK }; HttpService * HttpService::sInstance(NULL); volatile HttpService::EState HttpService::sState(NOT_INITIALIZED); @@ -413,6 +414,34 @@ HttpStatus HttpService::getPolicyOption(HttpRequest::EPolicyOption opt, HttpRequ return status; } +HttpStatus HttpService::getPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t pclass, + HttpRequest::policyCallback * ret_value) +{ + HttpStatus status(HttpStatus::LLCORE, LLCore::HE_INVALID_ARG); + + if (opt < HttpRequest::PO_CONNECTION_LIMIT // option must be in range + || opt >= HttpRequest::PO_LAST // ditto + || (sOptionDesc[opt].mIsLong) // datatype is string + || (pclass != HttpRequest::GLOBAL_POLICY_ID && pclass > mLastPolicy) // pclass in valid range + || (pclass == HttpRequest::GLOBAL_POLICY_ID && !sOptionDesc[opt].mIsGlobal) // global setting permitted + || (pclass != HttpRequest::GLOBAL_POLICY_ID && !sOptionDesc[opt].mIsClass)) // class setting permitted + // can always get, no dynamic check + { + return status; + } + + // Only global has callback values + if (pclass == HttpRequest::GLOBAL_POLICY_ID) + { + HttpPolicyGlobal & opts(mPolicy->getGlobalOptions()); + + status = opts.get(opt, ret_value); + } + + return status; +} + + HttpStatus HttpService::setPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t pclass, long value, long * ret_value) @@ -489,6 +518,37 @@ HttpStatus HttpService::setPolicyOption(HttpRequest::EPolicyOption opt, HttpRequ return status; } - + +HttpStatus HttpService::setPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t pclass, + HttpRequest::policyCallback value, HttpRequest::policyCallback * ret_value) +{ + HttpStatus status(HttpStatus::LLCORE, LLCore::HE_INVALID_ARG); + + if (opt < HttpRequest::PO_CONNECTION_LIMIT // option must be in range + || opt >= HttpRequest::PO_LAST // ditto + || (sOptionDesc[opt].mIsLong) // datatype is string + || (pclass != HttpRequest::GLOBAL_POLICY_ID && pclass > mLastPolicy) // pclass in valid range + || (pclass == HttpRequest::GLOBAL_POLICY_ID && !sOptionDesc[opt].mIsGlobal) // global setting permitted + || (pclass != HttpRequest::GLOBAL_POLICY_ID && !sOptionDesc[opt].mIsClass) // class setting permitted + || (RUNNING == sState && !sOptionDesc[opt].mIsDynamic)) // dynamic setting permitted + { + return status; + } + + // Callbacks values are always global (at this time). + if (pclass == HttpRequest::GLOBAL_POLICY_ID) + { + HttpPolicyGlobal & opts(mPolicy->getGlobalOptions()); + + status = opts.set(opt, value); + if (status && ret_value) + { + status = opts.get(opt, ret_value); + } + } + + return status; +} + } // end namespace LLCore -- cgit v1.3 From 735364038767694ea29d9b6a168410e6482cc9c2 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 27 Mar 2015 17:00:02 -0700 Subject: first set of chnages from code review from Nat --- indra/llcorehttp/_httpoprequest.cpp | 10 +- indra/llcorehttp/_httpoprequest.h | 5 +- indra/llcorehttp/_httppolicyglobal.cpp | 4 +- indra/llcorehttp/_httppolicyglobal.h | 6 +- indra/llcorehttp/_httpservice.cpp | 4 +- indra/llcorehttp/_httpservice.h | 6 +- indra/llcorehttp/httpcommon.h | 75 +++++++------- indra/llcorehttp/httpoptions.cpp | 8 +- indra/llcorehttp/httpoptions.h | 90 ++++++++++------- indra/llcorehttp/httprequest.cpp | 10 +- indra/llcorehttp/httprequest.h | 4 +- indra/llmessage/llhttpsdhandler.cpp | 2 +- indra/llmessage/llhttpsdhandler.h | 4 +- indra/newview/llagent.cpp | 11 ++- indra/newview/llagent.h | 4 +- indra/newview/llagentlanguage.cpp | 2 +- indra/newview/llappcorehttp.cpp | 2 +- indra/newview/llappearancemgr.cpp | 6 +- indra/newview/llavatarrenderinfoaccountant.cpp | 131 ++++++++++++++++++++++++- indra/newview/llavatarrenderinfoaccountant.h | 10 +- indra/newview/llmaterialmgr.cpp | 4 +- 21 files changed, 271 insertions(+), 127 deletions(-) (limited to 'indra/llcorehttp/_httpservice.cpp') diff --git a/indra/llcorehttp/_httpoprequest.cpp b/indra/llcorehttp/_httpoprequest.cpp index 48e22468cd..5768fe5a90 100755 --- a/indra/llcorehttp/_httpoprequest.cpp +++ b/indra/llcorehttp/_httpoprequest.cpp @@ -115,9 +115,8 @@ namespace LLCore { -HttpOpRequest::HttpOpRequest(HttpRequest const * const request) +HttpOpRequest::HttpOpRequest() : HttpOperation(), - mRequest(request), mProcFlags(0U), mReqMethod(HOR_GET), mReqBody(NULL), @@ -490,13 +489,13 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) long follow_redirect(1L); long sslPeerV(0L); long sslHostV(0L); - long dnsCacheTimeout(15L); + long dnsCacheTimeout(-1L); if (mReqOptions) { follow_redirect = mReqOptions->getFollowRedirects() ? 1L : 0L; - sslPeerV = mReqOptions->getSSLVerifyHost() ? 0L : 1L; - sslHostV = mReqOptions->getSSLVerifyHost(); + sslPeerV = mReqOptions->getSSLVerifyPeer() ? 1L : 0L; + sslHostV = mReqOptions->getSSLVerifyHost() ? 2L : 0L; dnsCacheTimeout = mReqOptions->getDNSCacheTimeout(); } code = curl_easy_setopt(mCurlHandle, CURLOPT_FOLLOWLOCATION, follow_redirect); @@ -516,7 +515,6 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) code = curl_easy_setopt(mCurlHandle, CURLOPT_DNS_CACHE_TIMEOUT, dnsCacheTimeout); check_curl_easy_code(code, CURLOPT_DNS_CACHE_TIMEOUT); - if (gpolicy.mUseLLProxy) { // Use the viewer-based thread-safe API which has a diff --git a/indra/llcorehttp/_httpoprequest.h b/indra/llcorehttp/_httpoprequest.h index 7a4b7c189e..e71d1d1edf 100755 --- a/indra/llcorehttp/_httpoprequest.h +++ b/indra/llcorehttp/_httpoprequest.h @@ -66,7 +66,7 @@ class HttpOptions; class HttpOpRequest : public HttpOperation { public: - HttpOpRequest(HttpRequest const * const request); + HttpOpRequest(); protected: virtual ~HttpOpRequest(); // Use release() @@ -165,11 +165,10 @@ protected: static const unsigned int PF_SAVE_HEADERS = 0x00000002U; static const unsigned int PF_USE_RETRY_AFTER = 0x00000004U; - HttpRequest::policyCallback mCallbackSSLVerify; + HttpRequest::policyCallback_t mCallbackSSLVerify; public: // Request data - HttpRequest const * const mRequest; EMethod mReqMethod; std::string mReqURL; BufferArray * mReqBody; diff --git a/indra/llcorehttp/_httppolicyglobal.cpp b/indra/llcorehttp/_httppolicyglobal.cpp index c4ef38a815..3d0df96ade 100755 --- a/indra/llcorehttp/_httppolicyglobal.cpp +++ b/indra/llcorehttp/_httppolicyglobal.cpp @@ -106,7 +106,7 @@ HttpStatus HttpPolicyGlobal::set(HttpRequest::EPolicyOption opt, const std::stri return HttpStatus(); } -HttpStatus HttpPolicyGlobal::set(HttpRequest::EPolicyOption opt, HttpRequest::policyCallback value) +HttpStatus HttpPolicyGlobal::set(HttpRequest::EPolicyOption opt, HttpRequest::policyCallback_t value) { switch (opt) { @@ -169,7 +169,7 @@ HttpStatus HttpPolicyGlobal::get(HttpRequest::EPolicyOption opt, std::string * v } -HttpStatus HttpPolicyGlobal::get(HttpRequest::EPolicyOption opt, HttpRequest::policyCallback * value) const +HttpStatus HttpPolicyGlobal::get(HttpRequest::EPolicyOption opt, HttpRequest::policyCallback_t * value) const { switch (opt) { diff --git a/indra/llcorehttp/_httppolicyglobal.h b/indra/llcorehttp/_httppolicyglobal.h index 1696238814..e02da4386a 100755 --- a/indra/llcorehttp/_httppolicyglobal.h +++ b/indra/llcorehttp/_httppolicyglobal.h @@ -60,10 +60,10 @@ private: public: HttpStatus set(HttpRequest::EPolicyOption opt, long value); HttpStatus set(HttpRequest::EPolicyOption opt, const std::string & value); - HttpStatus set(HttpRequest::EPolicyOption opt, HttpRequest::policyCallback value); + HttpStatus set(HttpRequest::EPolicyOption opt, HttpRequest::policyCallback_t value); HttpStatus get(HttpRequest::EPolicyOption opt, long * value) const; HttpStatus get(HttpRequest::EPolicyOption opt, std::string * value) const; - HttpStatus get(HttpRequest::EPolicyOption opt, HttpRequest::policyCallback * value) const; + HttpStatus get(HttpRequest::EPolicyOption opt, HttpRequest::policyCallback_t * value) const; public: long mConnectionLimit; @@ -72,7 +72,7 @@ public: std::string mHttpProxy; long mTrace; long mUseLLProxy; - HttpRequest::policyCallback mSslCtxCallback; + HttpRequest::policyCallback_t mSslCtxCallback; }; // end class HttpPolicyGlobal } // end namespace LLCore diff --git a/indra/llcorehttp/_httpservice.cpp b/indra/llcorehttp/_httpservice.cpp index 7b8aac35a8..252db78c89 100755 --- a/indra/llcorehttp/_httpservice.cpp +++ b/indra/llcorehttp/_httpservice.cpp @@ -415,7 +415,7 @@ HttpStatus HttpService::getPolicyOption(HttpRequest::EPolicyOption opt, HttpRequ } HttpStatus HttpService::getPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t pclass, - HttpRequest::policyCallback * ret_value) + HttpRequest::policyCallback_t * ret_value) { HttpStatus status(HttpStatus::LLCORE, LLCore::HE_INVALID_ARG); @@ -520,7 +520,7 @@ HttpStatus HttpService::setPolicyOption(HttpRequest::EPolicyOption opt, HttpRequ } HttpStatus HttpService::setPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t pclass, - HttpRequest::policyCallback value, HttpRequest::policyCallback * ret_value) + HttpRequest::policyCallback_t value, HttpRequest::policyCallback_t * ret_value) { HttpStatus status(HttpStatus::LLCORE, LLCore::HE_INVALID_ARG); diff --git a/indra/llcorehttp/_httpservice.h b/indra/llcorehttp/_httpservice.h index 699a8eaa4f..ac518a5de7 100755 --- a/indra/llcorehttp/_httpservice.h +++ b/indra/llcorehttp/_httpservice.h @@ -209,15 +209,15 @@ protected: HttpStatus getPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t, std::string * ret_value); HttpStatus getPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t, - HttpRequest::policyCallback * ret_value); + HttpRequest::policyCallback_t * ret_value); HttpStatus setPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t, long value, long * ret_value); HttpStatus setPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t, const std::string & value, std::string * ret_value); HttpStatus setPolicyOption(HttpRequest::EPolicyOption opt, HttpRequest::policy_t, - HttpRequest::policyCallback value, - HttpRequest::policyCallback * ret_value); + HttpRequest::policyCallback_t value, + HttpRequest::policyCallback_t * ret_value); protected: static const OptionDescriptor sOptionDesc[HttpRequest::PO_LAST]; diff --git a/indra/llcorehttp/httpcommon.h b/indra/llcorehttp/httpcommon.h index 64075f5f20..ada5c1bbe7 100755 --- a/indra/llcorehttp/httpcommon.h +++ b/indra/llcorehttp/httpcommon.h @@ -190,6 +190,7 @@ #include "linden_common.h" // Modifies curl/curl.h interfaces #include "boost/intrusive_ptr.hpp" #include "boost/shared_ptr.hpp" +#include "boost/function.hpp" #include namespace LLCore @@ -294,50 +295,50 @@ struct HttpStatus typedef unsigned short type_enum_t; HttpStatus() - { - mDetails = new Details(LLCORE, HE_SUCCESS); - } + { + mDetails = boost::shared_ptr
(new Details(LLCORE, HE_SUCCESS)); + } HttpStatus(type_enum_t type, short status) - { - mDetails = new Details(type, status); - } + { + mDetails = boost::shared_ptr
(new Details(type, status)); + } HttpStatus(int http_status) - { - mDetails = new Details(http_status, - (http_status >= 200 && http_status <= 299) ? HE_SUCCESS : HE_REPLY_ERROR); - llassert(http_status >= 100 && http_status <= 999); - } + { + mDetails = boost::shared_ptr
(new Details(http_status, + (http_status >= 200 && http_status <= 299) ? HE_SUCCESS : HE_REPLY_ERROR)); + llassert(http_status >= 100 && http_status <= 999); + } HttpStatus(int http_status, const std::string &message) - { - mDetails = new Details(http_status, - (http_status >= 200 && http_status <= 299) ? HE_SUCCESS : HE_REPLY_ERROR); - llassert(http_status >= 100 && http_status <= 999); - mDetails->mMessage = message; - } + { + mDetails = boost::shared_ptr
(new Details(http_status, + (http_status >= 200 && http_status <= 299) ? HE_SUCCESS : HE_REPLY_ERROR)); + llassert(http_status >= 100 && http_status <= 999); + mDetails->mMessage = message; + } HttpStatus(const HttpStatus & rhs) - { - mDetails = new Details(*rhs.mDetails); - } + { + mDetails = rhs.mDetails; + } ~HttpStatus() - { - delete mDetails; - } + { + } HttpStatus & operator=(const HttpStatus & rhs) - { - // Don't care if lhs & rhs are the same object - mDetails->mType = rhs.mDetails->mType; - mDetails->mStatus = rhs.mDetails->mStatus; - mDetails->mMessage = rhs.mDetails->mMessage; - mDetails->mErrorData = rhs.mDetails->mErrorData; - - return *this; - } + { + mDetails = rhs.mDetails; + return *this; + } + + HttpStatus & clone(const HttpStatus &rhs) + { + mDetails = boost::shared_ptr
(new Details(*rhs.mDetails)); + return *this; + } static const type_enum_t EXT_CURL_EASY = 0; ///< mStatus is an error from a curl_easy_*() call static const type_enum_t EXT_CURL_MULTI = 1; ///< mStatus is an error from a curl_multi_*() call @@ -365,8 +366,7 @@ struct HttpStatus /// which will do the wrong thing in conditional expressions. bool operator==(const HttpStatus & rhs) const { - return (mDetails->mType == rhs.mDetails->mType) && - (mDetails->mStatus == rhs.mDetails->mStatus); + return (*mDetails == *rhs.mDetails); } bool operator!=(const HttpStatus & rhs) const @@ -474,6 +474,10 @@ private: mErrorData(rhs.mErrorData) {} + bool operator == (const Details &rhs) const + { + return (mType == rhs.mType) && (mStatus == rhs.mStatus); + } type_enum_t mType; short mStatus; @@ -481,8 +485,7 @@ private: void * mErrorData; }; - //boost::unique_ptr
mDetails; - Details * mDetails; + boost::shared_ptr
mDetails; }; // end struct HttpStatus diff --git a/indra/llcorehttp/httpoptions.cpp b/indra/llcorehttp/httpoptions.cpp index 28c2c25e92..a4d08a80df 100755 --- a/indra/llcorehttp/httpoptions.cpp +++ b/indra/llcorehttp/httpoptions.cpp @@ -42,8 +42,8 @@ HttpOptions::HttpOptions() : RefCounted(true), mUseRetryAfter(HTTP_USE_RETRY_AFTER_DEFAULT), mFollowRedirects(false), mVerifyPeer(false), - mVerifyHost(0), - mDNSCacheTimeout(15) + mVerifyHost(false), + mDNSCacheTimeout(-1L) {} @@ -95,9 +95,9 @@ void HttpOptions::setSSLVerifyPeer(bool verify) mVerifyPeer = verify; } -void HttpOptions::setSSLVerifyHost(unsigned int type) +void HttpOptions::setSSLVerifyHost(bool verify) { - mVerifyHost = llclamp(type, 0, 2); + mVerifyHost = verify; } void HttpOptions::setDNSCacheTimeout(int timeout) diff --git a/indra/llcorehttp/httpoptions.h b/indra/llcorehttp/httpoptions.h index 3b9ad9598b..765d2431bb 100755 --- a/indra/llcorehttp/httpoptions.h +++ b/indra/llcorehttp/httpoptions.h @@ -69,72 +69,86 @@ protected: void operator=(const HttpOptions &); // Not defined public: + // Default: false void setWantHeaders(bool wanted); bool getWantHeaders() const - { - return mWantHeaders; - } + { + return mWantHeaders; + } // Default: 0 void setTrace(int long); int getTrace() const - { - return mTracing; - } + { + return mTracing; + } // Default: 30 void setTimeout(unsigned int timeout); unsigned int getTimeout() const - { - return mTimeout; - } + { + return mTimeout; + } // Default: 0 void setTransferTimeout(unsigned int timeout); unsigned int getTransferTimeout() const - { - return mTransferTimeout; - } + { + return mTransferTimeout; + } + /// Sets the number of retries on an LLCore::HTTPRequest before the + /// request fails. // Default: 8 void setRetries(unsigned int retries); unsigned int getRetries() const - { - return mRetries; - } + { + return mRetries; + } // Default: true void setUseRetryAfter(bool use_retry); bool getUseRetryAfter() const - { - return mUseRetryAfter; - } + { + return mUseRetryAfter; + } - // Default: false + /// Instructs the LLCore::HTTPRequest to follow redirects + /// Default: false void setFollowRedirects(bool follow_redirect); bool getFollowRedirects() const - { - return mFollowRedirects; - } - - void setSSLVerifyPeer(bool verify); + { + return mFollowRedirects; + } + + /// Instructs the LLCore::HTTPRequest to verify that the exchanged security + /// certificate is authentic. + /// Default: false + void setSSLVerifyPeer(bool verify); bool getSSLVerifyPeer() const - { - return mVerifyPeer; - } - - void setSSLVerifyHost(unsigned int type); - unsigned int getSSLVerifyHost() const - { - return mVerifyHost; - } - + { + return mVerifyPeer; + } + + /// Instructs the LLCore::HTTPRequest to verify that the name in the + /// security certificate matches the name of the host contacted. + /// Default: false + void setSSLVerifyHost(bool verify); + bool getSSLVerifyHost() const + { + return mVerifyHost; + } + + /// Sets the time for DNS name caching in seconds. Setting this value + /// to 0 will disable name caching. Setting this value to -1 causes the + /// name cache to never time out. + /// Default: -1 void setDNSCacheTimeout(int timeout); int getDNSCacheTimeout() const - { - return mDNSCacheTimeout; - } + { + return mDNSCacheTimeout; + } protected: bool mWantHeaders; @@ -145,7 +159,7 @@ protected: bool mUseRetryAfter; bool mFollowRedirects; bool mVerifyPeer; - unsigned int mVerifyHost; + bool mVerifyHost; int mDNSCacheTimeout; }; // end class HttpOptions diff --git a/indra/llcorehttp/httprequest.cpp b/indra/llcorehttp/httprequest.cpp index 5f1ed3d43b..df8502b947 100755 --- a/indra/llcorehttp/httprequest.cpp +++ b/indra/llcorehttp/httprequest.cpp @@ -117,7 +117,7 @@ HttpStatus HttpRequest::setStaticPolicyOption(EPolicyOption opt, policy_t pclass return HttpService::instanceOf()->setPolicyOption(opt, pclass, value, ret_value); } -HttpStatus HttpRequest::setStaticPolicyOption(EPolicyOption opt, policy_t pclass, policyCallback value, policyCallback * ret_value) +HttpStatus HttpRequest::setStaticPolicyOption(EPolicyOption opt, policy_t pclass, policyCallback_t value, policyCallback_t * ret_value) { if (HttpService::RUNNING == HttpService::instanceOf()->getState()) { @@ -204,7 +204,7 @@ HttpHandle HttpRequest::requestGet(policy_t policy_id, HttpStatus status; HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(this); + HttpOpRequest * op = new HttpOpRequest(); if (! (status = op->setupGet(policy_id, priority, url, options, headers))) { op->release(); @@ -238,7 +238,7 @@ HttpHandle HttpRequest::requestGetByteRange(policy_t policy_id, HttpStatus status; HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(this); + HttpOpRequest * op = new HttpOpRequest(); if (! (status = op->setupGetByteRange(policy_id, priority, url, offset, len, options, headers))) { op->release(); @@ -271,7 +271,7 @@ HttpHandle HttpRequest::requestPost(policy_t policy_id, HttpStatus status; HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(this); + HttpOpRequest * op = new HttpOpRequest(); if (! (status = op->setupPost(policy_id, priority, url, body, options, headers))) { op->release(); @@ -304,7 +304,7 @@ HttpHandle HttpRequest::requestPut(policy_t policy_id, HttpStatus status; HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(this); + HttpOpRequest * op = new HttpOpRequest(); if (! (status = op->setupPut(policy_id, priority, url, body, options, headers))) { op->release(); diff --git a/indra/llcorehttp/httprequest.h b/indra/llcorehttp/httprequest.h index 4cacb3a20b..f7ce82d412 100755 --- a/indra/llcorehttp/httprequest.h +++ b/indra/llcorehttp/httprequest.h @@ -237,7 +237,7 @@ public: /// Prototype for policy based callbacks. The callback methods will be executed /// on the worker thread so no modifications should be made to the HttpHandler object. - typedef HttpStatus(*policyCallback)(const std::string &, HttpHandler const * const, void *); + typedef boost::function policyCallback_t; /// Set a policy option for a global or class parameter at /// startup time (prior to thread start). @@ -255,7 +255,7 @@ public: static HttpStatus setStaticPolicyOption(EPolicyOption opt, policy_t pclass, const std::string & value, std::string * ret_value); static HttpStatus setStaticPolicyOption(EPolicyOption opt, policy_t pclass, - policyCallback value, policyCallback * ret_value);; + policyCallback_t value, policyCallback_t * ret_value);; /// Set a parameter on a class-based policy option. Calls /// made after the start of the servicing thread are diff --git a/indra/llmessage/llhttpsdhandler.cpp b/indra/llmessage/llhttpsdhandler.cpp index 0d385d6497..72ecfe77e2 100644 --- a/indra/llmessage/llhttpsdhandler.cpp +++ b/indra/llmessage/llhttpsdhandler.cpp @@ -89,7 +89,7 @@ LLHttpSDGenericHandler::LLHttpSDGenericHandler(const LLURI &uri, const std::stri { } -void LLHttpSDGenericHandler::onSuccess(LLCore::HttpResponse * response, LLSD &content) +void LLHttpSDGenericHandler::onSuccess(LLCore::HttpResponse * response, const LLSD &content) { LL_DEBUGS() << mCaps << " Success." << LL_ENDL; } diff --git a/indra/llmessage/llhttpsdhandler.h b/indra/llmessage/llhttpsdhandler.h index b3eb7d6145..a2598c9709 100644 --- a/indra/llmessage/llhttpsdhandler.h +++ b/indra/llmessage/llhttpsdhandler.h @@ -49,7 +49,7 @@ public: } protected: - virtual void onSuccess(LLCore::HttpResponse * response, LLSD &content) = 0; + virtual void onSuccess(LLCore::HttpResponse * response, const LLSD &content) = 0; virtual void onFailure(LLCore::HttpResponse * response, LLCore::HttpStatus status) = 0; private: @@ -65,7 +65,7 @@ public: LLHttpSDGenericHandler(const LLURI &uri, const std::string &action); protected: - virtual void onSuccess(LLCore::HttpResponse * response, LLSD &content); + virtual void onSuccess(LLCore::HttpResponse * response, const LLSD &content); virtual void onFailure(LLCore::HttpResponse * response, LLCore::HttpStatus status); private: diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 81387fb927..667d530e39 100755 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -2559,7 +2559,7 @@ public: { } protected: - virtual void onSuccess(LLCore::HttpResponse * response, LLSD &content); + virtual void onSuccess(LLCore::HttpResponse * response, const LLSD &content); virtual void onFailure(LLCore::HttpResponse * response, LLCore::HttpStatus status); private: @@ -2572,7 +2572,7 @@ private: }; //------------------------------------------------------------------------- -void LLMaturityHttpHandler::onSuccess(LLCore::HttpResponse * response, LLSD &content) +void LLMaturityHttpHandler::onSuccess(LLCore::HttpResponse * response, const LLSD &content) { U8 actualMaturity = parseMaturityFromServerResponse(content); @@ -2774,7 +2774,7 @@ void LLAgent::sendMaturityPreferenceToServer(U8 pPreferredMaturity) LL_INFOS() << "Sending viewer preferred maturity to '" << LLViewerRegion::accessToString(pPreferredMaturity) << "' via capability to: " << url << LL_ENDL; - LLCore::HttpHandle handle = requestPostCapibility("UpdateAgentInformation", url, postData, handler); + LLCore::HttpHandle handle = requestPostCapability("UpdateAgentInformation", url, postData, handler); if (handle == LLCORE_HTTP_HANDLE_INVALID) { @@ -2784,7 +2784,7 @@ void LLAgent::sendMaturityPreferenceToServer(U8 pPreferredMaturity) } } -LLCore::HttpHandle LLAgent::requestPostCapibility(const std::string &cap, const std::string &url, LLSD &postData, LLHttpSDHandler *usrhndlr) +LLCore::HttpHandle LLAgent::requestPostCapability(const std::string &cap, const std::string &url, LLSD &postData, LLHttpSDHandler *usrhndlr) { LLHttpSDHandler * handler = (usrhndlr) ? usrhndlr : new LLHttpSDGenericHandler(url, cap); LLCore::HttpHandle handle = LLCoreHttpUtil::requestPostWithLLSD(mHttpRequest, @@ -2793,6 +2793,9 @@ LLCore::HttpHandle LLAgent::requestPostCapibility(const std::string &cap, const if (handle == LLCORE_HTTP_HANDLE_INVALID) { + // If no handler was passed in we delete the handler default handler allocated + // at the start of this function. + // *TODO: Change this metaphore to use boost::shared_ptr<> for handlers. Requires change in LLCore::HTTP if (!usrhndlr) delete handler; LLCore::HttpStatus status = mHttpRequest->getStatus(); diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h index 6b636a2dc0..26120b52f6 100755 --- a/indra/newview/llagent.h +++ b/indra/newview/llagent.h @@ -925,8 +925,8 @@ public: public: /// Utilities for allowing the the agent sub managers to post and get via /// HTTP using the agent's policy settings and headers. - LLCore::HttpHandle requestPostCapibility(const std::string &cap, const std::string &url, LLSD &postData, LLHttpSDHandler *usrhndlr = NULL); - //LLCore::HttpHandle httpGetCapibility(const std::string &cap, const LLURI &uri, LLHttpSDHandler *usrhndlr = NULL); + LLCore::HttpHandle requestPostCapability(const std::string &cap, const std::string &url, LLSD &postData, LLHttpSDHandler *usrhndlr = NULL); + //LLCore::HttpHandle httpGetCapability(const std::string &cap, const LLURI &uri, LLHttpSDHandler *usrhndlr = NULL); /** Utility ** ** diff --git a/indra/newview/llagentlanguage.cpp b/indra/newview/llagentlanguage.cpp index 81fce9b257..f2ac323578 100755 --- a/indra/newview/llagentlanguage.cpp +++ b/indra/newview/llagentlanguage.cpp @@ -71,7 +71,7 @@ bool LLAgentLanguage::update() body["language_is_public"] = gSavedSettings.getBOOL("LanguageIsPublic"); //LLHTTPClient::post(url, body, new LLHTTPClient::Responder); - LLCore::HttpHandle handle = gAgent.requestPostCapibility("UpdateAgentLanguage", url, body); + LLCore::HttpHandle handle = gAgent.requestPostCapability("UpdateAgentLanguage", url, body); if (handle == LLCORE_HTTP_HANDLE_INVALID) { LL_WARNS() << "Unable to change language." << LL_ENDL; diff --git a/indra/newview/llappcorehttp.cpp b/indra/newview/llappcorehttp.cpp index cd9166f7b7..51cca273d8 100755 --- a/indra/newview/llappcorehttp.cpp +++ b/indra/newview/llappcorehttp.cpp @@ -494,7 +494,7 @@ LLCore::HttpStatus LLAppCoreHttp::sslVerify(const std::string &url, validation_params[CERT_HOSTNAME] = uri.hostName(); - // *TODO*: In the case of an exception while validating the cert, we need a way + // *TODO: In the case of an exception while validating the cert, we need a way // to pass the offending(?) cert back out. *Rider* try diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp index be71c430f4..709d9881e1 100755 --- a/indra/newview/llappearancemgr.cpp +++ b/indra/newview/llappearancemgr.cpp @@ -1260,7 +1260,7 @@ public: virtual void onCompleted(LLCore::HttpHandle handle, LLCore::HttpResponse * response); protected: - virtual void onSuccess(LLCore::HttpResponse * response, LLSD &content); + virtual void onSuccess(LLCore::HttpResponse * response, const LLSD &content); virtual void onFailure(LLCore::HttpResponse * response, LLCore::HttpStatus status); private: @@ -1278,7 +1278,7 @@ void LLAppearanceMgrHttpHandler::onCompleted(LLCore::HttpHandle handle, LLCore:: LLHttpSDHandler::onCompleted(handle, response); } -void LLAppearanceMgrHttpHandler::onSuccess(LLCore::HttpResponse * response, LLSD &content) +void LLAppearanceMgrHttpHandler::onSuccess(LLCore::HttpResponse * response, const LLSD &content) { if (!content.isMap()) { @@ -3443,7 +3443,7 @@ void LLAppearanceMgr::requestServerAppearanceUpdate() gAgentAvatarp->mLastUpdateRequestCOFVersion = cof_version; - LLCore::HttpHandle handle = gAgent.requestPostCapibility("UpdateAvatarAppearance", url, postData, handler); + LLCore::HttpHandle handle = gAgent.requestPostCapability("UpdateAvatarAppearance", url, postData, handler); if (handle == LLCORE_HTTP_HANDLE_INVALID) { diff --git a/indra/newview/llavatarrenderinfoaccountant.cpp b/indra/newview/llavatarrenderinfoaccountant.cpp index 38e153137c..aeaa832bc7 100644 --- a/indra/newview/llavatarrenderinfoaccountant.cpp +++ b/indra/newview/llavatarrenderinfoaccountant.cpp @@ -43,7 +43,9 @@ #include "llviewerregion.h" #include "llvoavatar.h" #include "llworld.h" - +#include "llhttpsdhandler.h" +#include "httpheaders.h" +#include "httpoptions.h" static const std::string KEY_AGENTS = "agents"; // map static const std::string KEY_WEIGHT = "weight"; // integer @@ -55,8 +57,113 @@ static const std::string KEY_ERROR = "error"; // Send data updates about once per minute, only need per-frame resolution LLFrameTimer LLAvatarRenderInfoAccountant::sRenderInfoReportTimer; +//LLCore::HttpRequest::ptr_t LLAvatarRenderInfoAccountant::sHttpRequest; + +#if 0 +//========================================================================= +class LLAvatarRenderInfoHandler : public LLHttpSDHandler +{ +public: + LLAvatarRenderInfoHandler(const LLURI &uri, U64 regionHandle); + +protected: + virtual void onSuccess(LLCore::HttpResponse * response, LLSD &content); + virtual void onFailure(LLCore::HttpResponse * response, LLCore::HttpStatus status); + +private: + U64 mRegionHandle; +}; + +LLAvatarRenderInfoHandler::LLAvatarRenderInfoHandler(const LLURI &uri, U64 regionHandle) : + LLHttpSDHandler(uri), + mRegionHandle(regionHandle) +{ +} + +void LLAvatarRenderInfoHandler::onSuccess(LLCore::HttpResponse * response, LLSD &content) +{ + LLViewerRegion * regionp = LLWorld::getInstance()->getRegionFromHandle(mRegionHandle); + if (regionp) + { + if (LLAvatarRenderInfoAccountant::logRenderInfo()) + { + LL_INFOS() << "LRI: Result for avatar weights request for region " << regionp->getName() << ":" << LL_ENDL; + } + + if (content.isMap()) + { + if (content.has(KEY_AGENTS)) + { + const LLSD & agents = content[KEY_AGENTS]; + if (agents.isMap()) + { + LLSD::map_const_iterator report_iter = agents.beginMap(); + while (report_iter != agents.endMap()) + { + LLUUID target_agent_id = LLUUID(report_iter->first); + const LLSD & agent_info_map = report_iter->second; + LLViewerObject* avatarp = gObjectList.findObject(target_agent_id); + if (avatarp && + avatarp->isAvatar() && + agent_info_map.isMap()) + { // Extract the data for this avatar + + if (LLAvatarRenderInfoAccountant::logRenderInfo()) + { + LL_INFOS() << "LRI: Agent " << target_agent_id + << ": " << agent_info_map << LL_ENDL; + } + + if (agent_info_map.has(KEY_WEIGHT)) + { + ((LLVOAvatar *)avatarp)->setReportedVisualComplexity(agent_info_map[KEY_WEIGHT].asInteger()); + } + } + report_iter++; + } + } + } // has "agents" + else if (content.has(KEY_ERROR)) + { + const LLSD & error = content[KEY_ERROR]; + LL_WARNS() << "Avatar render info GET error: " + << error[KEY_IDENTIFIER] + << ": " << error[KEY_MESSAGE] + << " from region " << regionp->getName() + << LL_ENDL; + } + } + } + else + { + LL_INFOS() << "Avatar render weight info received but region not found for " + << mRegionHandle << LL_ENDL; + } +} +void LLAvatarRenderInfoHandler::onFailure(LLCore::HttpResponse * response, LLCore::HttpStatus status) +{ + LLViewerRegion * regionp = LLWorld::getInstance()->getRegionFromHandle(mRegionHandle); + if (regionp) + { + LL_WARNS() << "HTTP error result for avatar weight GET: " << status.toULong() + << ", " << status.toString() + << " returned by region " << regionp->getName() + << LL_ENDL; + } + else + { + LL_WARNS() << "Avatar render weight GET error received but region not found for " + << mRegionHandle + << ", error " << status.toULong() + << ", " << status.toString() + << LL_ENDL; + } +} + +//------------------------------------------------------------------------- +#else // HTTP responder class for GET request for avatar render weight information class LLAvatarRenderInfoGetResponder : public LLHTTPClient::Responder { @@ -142,7 +249,7 @@ public: } else { - LL_INFOS() << "Avatar render weight info recieved but region not found for " + LL_INFOS() << "Avatar render weight info received but region not found for " << mRegionHandle << LL_ENDL; } } @@ -150,7 +257,7 @@ public: private: U64 mRegionHandle; }; - +#endif // HTTP responder class for POST request for avatar render weight information class LLAvatarRenderInfoPostResponder : public LLHTTPClient::Responder @@ -172,7 +279,7 @@ public: } else { - LL_WARNS() << "Avatar render weight POST error recieved but region not found for " + LL_WARNS() << "Avatar render weight POST error received but region not found for " << mRegionHandle << ", error " << statusNum << ", " << reason @@ -215,7 +322,6 @@ private: U64 mRegionHandle; }; - // static // Send request for one region, no timer checks void LLAvatarRenderInfoAccountant::sendRenderInfoToRegion(LLViewerRegion * regionp) @@ -292,7 +398,19 @@ void LLAvatarRenderInfoAccountant::getRenderInfoFromRegion(LLViewerRegion * regi } // First send a request to get the latest data +#if 0 + if (!LLAvatarRenderInfoAccountant::sHttpRequest) + sHttpRequest = LLCore::HttpRequest::ptr_t(new LLCore::HttpRequest()); + LLAppCoreHttp & app_core_http(LLAppViewer::instance()->getAppCoreHttp()); + + LLCore::HttpHeaders::ptr_t httpHeaders = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false); + LLCore::HttpOptions::ptr_t httpOptions = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false); + LLCore::HttpRequest::policy_t httpPolicy = app_core_http.getPolicy(LLAppCoreHttp::AP_AGENT); + + LLCore::HttpHandle handle = sHttpRequest-> +#else LLHTTPClient::get(url, new LLAvatarRenderInfoGetResponder(regionp->getHandle())); +#endif } } @@ -301,6 +419,9 @@ void LLAvatarRenderInfoAccountant::getRenderInfoFromRegion(LLViewerRegion * regi // Called every frame - send render weight requests to every region void LLAvatarRenderInfoAccountant::idle() { +// if (!LLAvatarRenderInfoAccountant::sHttpRequest) +// sHttpRequest = LLCore::HttpRequest::ptr_t(new LLCore::HttpRequest()); + if (sRenderInfoReportTimer.hasExpired()) { const F32 SECS_BETWEEN_REGION_SCANS = 5.f; // Scan the region list every 5 seconds diff --git a/indra/newview/llavatarrenderinfoaccountant.h b/indra/newview/llavatarrenderinfoaccountant.h index d68f2dccfb..13054f5e2f 100644 --- a/indra/newview/llavatarrenderinfoaccountant.h +++ b/indra/newview/llavatarrenderinfoaccountant.h @@ -29,6 +29,8 @@ #if ! defined(LL_llavatarrenderinfoaccountant_H) #define LL_llavatarrenderinfoaccountant_H +#include "httpcommon.h" + class LLViewerRegion; // Class to gather avatar rendering information @@ -36,8 +38,6 @@ class LLViewerRegion; class LLAvatarRenderInfoAccountant { public: - LLAvatarRenderInfoAccountant() {}; - ~LLAvatarRenderInfoAccountant() {}; static void sendRenderInfoToRegion(LLViewerRegion * regionp); static void getRenderInfoFromRegion(LLViewerRegion * regionp); @@ -49,8 +49,14 @@ public: static bool logRenderInfo(); private: + LLAvatarRenderInfoAccountant() {}; + ~LLAvatarRenderInfoAccountant() {}; + // Send data updates about once per minute, only need per-frame resolution static LLFrameTimer sRenderInfoReportTimer; + +// static LLCore::HttpRequest::ptr_t sHttpRequest; + }; #endif /* ! defined(LL_llavatarrenderinfoaccountant_H) */ diff --git a/indra/newview/llmaterialmgr.cpp b/indra/newview/llmaterialmgr.cpp index 065d763596..78fbe9af0a 100755 --- a/indra/newview/llmaterialmgr.cpp +++ b/indra/newview/llmaterialmgr.cpp @@ -75,7 +75,7 @@ public: virtual ~LLMaterialHttpHandler(); protected: - virtual void onSuccess(LLCore::HttpResponse * response, LLSD &content); + virtual void onSuccess(LLCore::HttpResponse * response, const LLSD &content); virtual void onFailure(LLCore::HttpResponse * response, LLCore::HttpStatus status); private: @@ -95,7 +95,7 @@ LLMaterialHttpHandler::~LLMaterialHttpHandler() { } -void LLMaterialHttpHandler::onSuccess(LLCore::HttpResponse * response, LLSD &content) +void LLMaterialHttpHandler::onSuccess(LLCore::HttpResponse * response, const LLSD &content) { LL_DEBUGS("Materials") << LL_ENDL; mCallback(true, content); -- cgit v1.3 From 8d334ca1bf51dc1a0020f53cdd7a3927bdb7740c Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 16 Oct 2015 11:40:48 -0700 Subject: MAINT-5271: Converted internal pointers to internal operation to managed shared pointers. Removed direct cast and dereference of handles. --- indra/llcorehttp/_httplibcurl.cpp | 35 ++--- indra/llcorehttp/_httplibcurl.h | 8 +- indra/llcorehttp/_httpopcancel.h | 5 - indra/llcorehttp/_httpoperation.cpp | 100 ++++++++++--- indra/llcorehttp/_httpoperation.h | 42 ++++-- indra/llcorehttp/_httpoprequest.cpp | 43 +++--- indra/llcorehttp/_httpoprequest.h | 3 +- indra/llcorehttp/_httpopsetget.h | 3 +- indra/llcorehttp/_httpopsetpriority.h | 1 - indra/llcorehttp/_httppolicy.cpp | 49 +++---- indra/llcorehttp/_httppolicy.h | 8 +- indra/llcorehttp/_httpreadyqueue.h | 6 +- indra/llcorehttp/_httpreplyqueue.cpp | 18 +-- indra/llcorehttp/_httpreplyqueue.h | 8 +- indra/llcorehttp/_httprequestqueue.cpp | 15 +- indra/llcorehttp/_httprequestqueue.h | 8 +- indra/llcorehttp/_httpretryqueue.h | 6 +- indra/llcorehttp/_httpservice.cpp | 19 ++- indra/llcorehttp/httpcommon.h | 1 + indra/llcorehttp/httprequest.cpp | 175 ++++++++--------------- indra/llcorehttp/httprequest.h | 1 - indra/llcorehttp/tests/test_httpoperation.hpp | 13 +- indra/llcorehttp/tests/test_httprequestqueue.hpp | 32 +++-- indra/newview/llmaterialmgr.cpp | 45 +----- 24 files changed, 311 insertions(+), 333 deletions(-) (limited to 'indra/llcorehttp/_httpservice.cpp') diff --git a/indra/llcorehttp/_httplibcurl.cpp b/indra/llcorehttp/_httplibcurl.cpp index 17e997688f..4ebe14e740 100755 --- a/indra/llcorehttp/_httplibcurl.cpp +++ b/indra/llcorehttp/_httplibcurl.cpp @@ -71,11 +71,10 @@ void HttpLibcurl::shutdown() { while (! mActiveOps.empty()) { - HttpOpRequest * op(* mActiveOps.begin()); + HttpOpRequest::ptr_t op(* mActiveOps.begin()); mActiveOps.erase(mActiveOps.begin()); cancelRequest(op); - op->release(); } if (mMultiHandles) @@ -204,7 +203,7 @@ HttpService::ELoopSpeed HttpLibcurl::processTransport() // Caller has provided us with a ref count on op. -void HttpLibcurl::addOp(HttpOpRequest * op) +void HttpLibcurl::addOp(const HttpOpRequest::ptr_t &op) { llassert_always(op->mReqPolicy < mPolicyCount); llassert_always(mMultiHandles[op->mReqPolicy] != NULL); @@ -235,21 +234,21 @@ void HttpLibcurl::addOp(HttpOpRequest * op) HttpPolicy & policy(mService->getPolicy()); LL_INFOS(LOG_CORE) << "TRACE, ToActiveQueue, Handle: " - << static_cast(op) - << ", Actives: " << mActiveOps.size() - << ", Readies: " << policy.getReadyCount(op->mReqPolicy) - << LL_ENDL; + << op->getHandle() + << ", Actives: " << mActiveOps.size() + << ", Readies: " << policy.getReadyCount(op->mReqPolicy) + << LL_ENDL; } } // Implements the transport part of any cancel operation. // See if the handle is an active operation and if so, -// use the more complicated transport-based cancelation +// use the more complicated transport-based cancellation // method to kill the request. bool HttpLibcurl::cancel(HttpHandle handle) { - HttpOpRequest * op(static_cast(handle)); + HttpOpRequest::ptr_t op = HttpOpRequest::fromHandle(handle); active_set_t::iterator it(mActiveOps.find(op)); if (mActiveOps.end() == it) { @@ -262,7 +261,6 @@ bool HttpLibcurl::cancel(HttpHandle handle) // Drop references mActiveOps.erase(it); --mActiveHandles[op->mReqPolicy]; - op->release(); return true; } @@ -273,7 +271,7 @@ bool HttpLibcurl::cancel(HttpHandle handle) // remove the op from the active list and release the op *after* // calling this method. It must be called first to deliver the // op to the reply queue with refcount intact. -void HttpLibcurl::cancelRequest(HttpOpRequest * op) +void HttpLibcurl::cancelRequest(const HttpOpRequest::ptr_t &op) { // Deactivate request op->mCurlActive = false; @@ -287,7 +285,7 @@ void HttpLibcurl::cancelRequest(HttpOpRequest * op) if (op->mTracing > HTTP_TRACE_OFF) { LL_INFOS(LOG_CORE) << "TRACE, RequestCanceled, Handle: " - << static_cast(op) + << op->getHandle() << ", Status: " << op->mStatus.toTerseString() << LL_ENDL; } @@ -301,8 +299,11 @@ void HttpLibcurl::cancelRequest(HttpOpRequest * op) // Keep them synchronized as necessary. bool HttpLibcurl::completeRequest(CURLM * multi_handle, CURL * handle, CURLcode status) { - HttpOpRequest * op(NULL); - curl_easy_getinfo(handle, CURLINFO_PRIVATE, &op); + HttpHandle ophandle(NULL); + + curl_easy_getinfo(handle, CURLINFO_PRIVATE, &ophandle); + HttpOpRequest::ptr_t op(HttpOpRequest::fromHandle(ophandle)); + if (handle != op->mCurlHandle || ! op->mCurlActive) { @@ -364,9 +365,9 @@ bool HttpLibcurl::completeRequest(CURLM * multi_handle, CURL * handle, CURLcode if (op->mTracing > HTTP_TRACE_OFF) { LL_INFOS(LOG_CORE) << "TRACE, RequestComplete, Handle: " - << static_cast(op) - << ", Status: " << op->mStatus.toTerseString() - << LL_ENDL; + << op->getHandle() + << ", Status: " << op->mStatus.toTerseString() + << LL_ENDL; } // Dispatch to next stage diff --git a/indra/llcorehttp/_httplibcurl.h b/indra/llcorehttp/_httplibcurl.h index ffc24c63a8..a71eae59c0 100755 --- a/indra/llcorehttp/_httplibcurl.h +++ b/indra/llcorehttp/_httplibcurl.h @@ -65,6 +65,8 @@ private: void operator=(const HttpLibcurl &); // Not defined public: + typedef boost::shared_ptr opReqPtr_t; + /// Give cycles to libcurl to run active requests. Completed /// operations (successful or failed) will be retried or handed /// over to the reply queue as final responses. @@ -80,7 +82,7 @@ public: /// request. (No additional references will be added.) /// /// Threading: called by worker thread. - void addOp(HttpOpRequest * op); + void addOp(const opReqPtr_t & op); /// One-time call to set the number of policy classes to be /// serviced and to create the resources for each. Value @@ -148,10 +150,10 @@ protected: /// Invoked to cancel an active request, mainly during shutdown /// and destroy. - void cancelRequest(HttpOpRequest * op); + void cancelRequest(const opReqPtr_t &op); protected: - typedef std::set active_set_t; + typedef std::set active_set_t; /// Simple request handle cache for libcurl. /// diff --git a/indra/llcorehttp/_httpopcancel.h b/indra/llcorehttp/_httpopcancel.h index 336dfdc573..86944eb159 100755 --- a/indra/llcorehttp/_httpopcancel.h +++ b/indra/llcorehttp/_httpopcancel.h @@ -56,13 +56,8 @@ public: /// be canceled. HttpOpCancel(HttpHandle handle); -protected: virtual ~HttpOpCancel(); // Use release() -private: - HttpOpCancel(const HttpOpCancel &); // Not defined - void operator=(const HttpOpCancel &); // Not defined - public: virtual void stageFromRequest(HttpService *); 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(), + 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(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(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(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); } } diff --git a/indra/llcorehttp/_httpoperation.h b/indra/llcorehttp/_httpoperation.h index f677e7aed8..417bdc7c50 100755 --- a/indra/llcorehttp/_httpoperation.h +++ b/indra/llcorehttp/_httpoperation.h @@ -30,8 +30,7 @@ #include "httpcommon.h" #include "httprequest.h" -#include "_refcounted.h" - +#include "_mutex.h" namespace LLCore { @@ -69,21 +68,20 @@ class HttpService; /// via queue-like interfaces that are thread compatible /// and those interfaces establish the access rules. -class HttpOperation : public LLCoreInt::RefCounted +class HttpOperation : private boost::noncopyable, + public boost::enable_shared_from_this { public: + typedef boost::shared_ptr ptr_t; + typedef boost::weak_ptr wptr_t; typedef boost::shared_ptr HttpReplyQueuePtr_t; /// Threading: called by consumer thread. HttpOperation(); -protected: /// Threading: called by any thread. virtual ~HttpOperation(); // Use release() -private: - HttpOperation(const HttpOperation &); // Not defined - void operator=(const HttpOperation &); // Not defined public: /// Register a reply queue and a handler for completion notifications. @@ -154,6 +152,18 @@ public: /// Threading: called by worker thread. /// virtual HttpStatus cancel(); + + /// Retrieves a unique handle for this operation. + HttpHandle getHandle(); + + template< class OPT > + static boost::shared_ptr< OPT > fromHandle(HttpHandle handle) + { + ptr_t ptr = findByHandle(handle); + if (!ptr) + return boost::shared_ptr< OPT >(); + return boost::dynamic_pointer_cast(ptr); + } protected: /// Delivers request to reply queue on completion. After this @@ -179,6 +189,21 @@ public: // Tracing, debug and metrics HttpTime mMetricCreated; int mTracing; + +private: + typedef std::map handleMap_t; + + HttpHandle createHandle(); + void destroyHandle(); + HttpHandle mMyHandle; + + static handleMap_t mHandleMap; + static LLCoreInt::HttpMutex mOpMutex; + +protected: + static ptr_t findByHandle(HttpHandle handle); + + }; // end class HttpOperation @@ -197,7 +222,6 @@ class HttpOpStop : public HttpOperation public: HttpOpStop(); -protected: virtual ~HttpOpStop(); private: @@ -220,7 +244,6 @@ class HttpOpNull : public HttpOperation public: HttpOpNull(); -protected: virtual ~HttpOpNull(); private: @@ -243,7 +266,6 @@ public: // 1 does a soft spin continuously requeuing itself HttpOpSpin(int mode); -protected: virtual ~HttpOpSpin(); private: diff --git a/indra/llcorehttp/_httpoprequest.cpp b/indra/llcorehttp/_httpoprequest.cpp index 86110f5b46..557f6207b5 100755 --- a/indra/llcorehttp/_httpoprequest.cpp +++ b/indra/llcorehttp/_httpoprequest.cpp @@ -187,15 +187,15 @@ HttpOpRequest::~HttpOpRequest() void HttpOpRequest::stageFromRequest(HttpService * service) { - addRef(); - service->getPolicy().addOp(this); // transfers refcount + HttpOpRequest::ptr_t self(boost::dynamic_pointer_cast(shared_from_this())); + service->getPolicy().addOp(self); // transfers refcount } void HttpOpRequest::stageFromReady(HttpService * service) { - addRef(); - service->getTransport().addOp(this); // transfers refcount + HttpOpRequest::ptr_t self(boost::dynamic_pointer_cast(shared_from_this())); + service->getTransport().addOp(self); // transfers refcount } @@ -261,12 +261,19 @@ void HttpOpRequest::visitNotifier(HttpRequest * request) response->setTransferStats(stats); - mUserHandler->onCompleted(static_cast(this), response); + mUserHandler->onCompleted(this->getHandle(), response); response->release(); } } +// /*static*/ +// HttpOpRequest::ptr_t HttpOpRequest::fromHandle(HttpHandle handle) +// { +// +// return boost::dynamic_pointer_cast((static_cast(handle))->shared_from_this()); +// } + HttpStatus HttpOpRequest::cancel() { @@ -488,7 +495,7 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) check_curl_easy_code(code, CURLOPT_NOPROGRESS); code = curl_easy_setopt(mCurlHandle, CURLOPT_URL, mReqURL.c_str()); check_curl_easy_code(code, CURLOPT_URL); - code = curl_easy_setopt(mCurlHandle, CURLOPT_PRIVATE, this); + code = curl_easy_setopt(mCurlHandle, CURLOPT_PRIVATE, getHandle()); check_curl_easy_code(code, CURLOPT_PRIVATE); code = curl_easy_setopt(mCurlHandle, CURLOPT_ENCODING, ""); check_curl_easy_code(code, CURLOPT_ENCODING); @@ -499,15 +506,15 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) check_curl_easy_code(code, CURLOPT_MAXREDIRS); code = curl_easy_setopt(mCurlHandle, CURLOPT_WRITEFUNCTION, writeCallback); check_curl_easy_code(code, CURLOPT_WRITEFUNCTION); - code = curl_easy_setopt(mCurlHandle, CURLOPT_WRITEDATA, this); + code = curl_easy_setopt(mCurlHandle, CURLOPT_WRITEDATA, getHandle()); check_curl_easy_code(code, CURLOPT_WRITEDATA); code = curl_easy_setopt(mCurlHandle, CURLOPT_READFUNCTION, readCallback); check_curl_easy_code(code, CURLOPT_READFUNCTION); - code = curl_easy_setopt(mCurlHandle, CURLOPT_READDATA, this); + code = curl_easy_setopt(mCurlHandle, CURLOPT_READDATA, getHandle()); check_curl_easy_code(code, CURLOPT_READDATA); code = curl_easy_setopt(mCurlHandle, CURLOPT_SEEKFUNCTION, seekCallback); check_curl_easy_code(code, CURLOPT_SEEKFUNCTION); - code = curl_easy_setopt(mCurlHandle, CURLOPT_SEEKDATA, this); + code = curl_easy_setopt(mCurlHandle, CURLOPT_SEEKDATA, getHandle()); check_curl_easy_code(code, CURLOPT_SEEKDATA); code = curl_easy_setopt(mCurlHandle, CURLOPT_COOKIEFILE, ""); @@ -517,7 +524,7 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) { code = curl_easy_setopt(mCurlHandle, CURLOPT_SSL_CTX_FUNCTION, curlSslCtxCallback); check_curl_easy_code(code, CURLOPT_SSL_CTX_FUNCTION); - code = curl_easy_setopt(mCurlHandle, CURLOPT_SSL_CTX_DATA, this); + code = curl_easy_setopt(mCurlHandle, CURLOPT_SSL_CTX_DATA, getHandle()); check_curl_easy_code(code, CURLOPT_SSL_CTX_DATA); mCallbackSSLVerify = gpolicy.mSslCtxCallback; } @@ -776,7 +783,7 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) size_t HttpOpRequest::writeCallback(void * data, size_t size, size_t nmemb, void * userdata) { - HttpOpRequest * op(static_cast(userdata)); + HttpOpRequest::ptr_t op(HttpOpRequest::fromHandle(userdata)); if (! op->mReplyBody) { @@ -790,7 +797,7 @@ size_t HttpOpRequest::writeCallback(void * data, size_t size, size_t nmemb, void size_t HttpOpRequest::readCallback(void * data, size_t size, size_t nmemb, void * userdata) { - HttpOpRequest * op(static_cast(userdata)); + HttpOpRequest::ptr_t op(HttpOpRequest::fromHandle(userdata)); if (! op->mReqBody) { @@ -819,7 +826,7 @@ size_t HttpOpRequest::readCallback(void * data, size_t size, size_t nmemb, void int HttpOpRequest::seekCallback(void *userdata, curl_off_t offset, int origin) { - HttpOpRequest * op(static_cast(userdata)); + HttpOpRequest::ptr_t op(HttpOpRequest::fromHandle(userdata)); if (!op->mReqBody) { @@ -855,7 +862,7 @@ size_t HttpOpRequest::headerCallback(void * data, size_t size, size_t nmemb, voi static const char con_ran_line[] = "content-range"; static const char con_retry_line[] = "retry-after"; - HttpOpRequest * op(static_cast(userdata)); + HttpOpRequest::ptr_t op(HttpOpRequest::fromHandle(userdata)); const size_t hdr_size(size * nmemb); const char * hdr_data(static_cast(data)); // Not null terminated @@ -999,7 +1006,7 @@ size_t HttpOpRequest::headerCallback(void * data, size_t size, size_t nmemb, voi CURLcode HttpOpRequest::curlSslCtxCallback(CURL *curl, void *sslctx, void *userdata) { - HttpOpRequest * op(static_cast(userdata)); + HttpOpRequest::ptr_t op(HttpOpRequest::fromHandle(userdata)); if (op->mCallbackSSLVerify) { @@ -1016,7 +1023,7 @@ CURLcode HttpOpRequest::curlSslCtxCallback(CURL *curl, void *sslctx, void *userd int HttpOpRequest::sslCertVerifyCallback(X509_STORE_CTX *ctx, void *param) { - HttpOpRequest * op(static_cast(param)); + HttpOpRequest::ptr_t op(HttpOpRequest::fromHandle(param)); if (op->mCallbackSSLVerify) { @@ -1028,7 +1035,7 @@ int HttpOpRequest::sslCertVerifyCallback(X509_STORE_CTX *ctx, void *param) int HttpOpRequest::debugCallback(CURL * handle, curl_infotype info, char * buffer, size_t len, void * userdata) { - HttpOpRequest * op(static_cast(userdata)); + HttpOpRequest::ptr_t op(HttpOpRequest::fromHandle(userdata)); std::string safe_line; std::string tag; @@ -1108,7 +1115,7 @@ int HttpOpRequest::debugCallback(CURL * handle, curl_infotype info, char * buffe if (logit) { LL_INFOS(LOG_CORE) << "TRACE, LibcurlDebug, Handle: " - << static_cast(op) + << op->getHandle() << ", Type: " << tag << ", Data: " << safe_line << LL_ENDL; diff --git a/indra/llcorehttp/_httpoprequest.h b/indra/llcorehttp/_httpoprequest.h index 1b449a5abc..dbcc57d0fd 100755 --- a/indra/llcorehttp/_httpoprequest.h +++ b/indra/llcorehttp/_httpoprequest.h @@ -66,9 +66,10 @@ class BufferArray; class HttpOpRequest : public HttpOperation { public: + typedef boost::shared_ptr ptr_t; + HttpOpRequest(); -protected: virtual ~HttpOpRequest(); // Use release() private: diff --git a/indra/llcorehttp/_httpopsetget.h b/indra/llcorehttp/_httpopsetget.h index a1e76dd429..eabd41e79f 100755 --- a/indra/llcorehttp/_httpopsetget.h +++ b/indra/llcorehttp/_httpopsetget.h @@ -53,9 +53,10 @@ namespace LLCore class HttpOpSetGet : public HttpOperation { public: + typedef boost::shared_ptr ptr_t; + HttpOpSetGet(); -protected: virtual ~HttpOpSetGet(); // Use release() private: diff --git a/indra/llcorehttp/_httpopsetpriority.h b/indra/llcorehttp/_httpopsetpriority.h index 31706b737c..43e2aa081b 100755 --- a/indra/llcorehttp/_httpopsetpriority.h +++ b/indra/llcorehttp/_httpopsetpriority.h @@ -51,7 +51,6 @@ class HttpOpSetPriority : public HttpOperation public: HttpOpSetPriority(HttpHandle handle, HttpRequest::priority_t priority); -protected: virtual ~HttpOpSetPriority(); private: diff --git a/indra/llcorehttp/_httppolicy.cpp b/indra/llcorehttp/_httppolicy.cpp index e5d6321401..fd78a5dadc 100755 --- a/indra/llcorehttp/_httppolicy.cpp +++ b/indra/llcorehttp/_httppolicy.cpp @@ -116,21 +116,19 @@ void HttpPolicy::shutdown() HttpRetryQueue & retryq(state.mRetryQueue); while (! retryq.empty()) { - HttpOpRequest * op(retryq.top()); + HttpOpRequest::ptr_t op(retryq.top()); retryq.pop(); op->cancel(); - op->release(); } HttpReadyQueue & readyq(state.mReadyQueue); while (! readyq.empty()) { - HttpOpRequest * op(readyq.top()); + HttpOpRequest::ptr_t op(readyq.top()); readyq.pop(); op->cancel(); - op->release(); } } } @@ -141,7 +139,7 @@ void HttpPolicy::start() } -void HttpPolicy::addOp(HttpOpRequest * op) +void HttpPolicy::addOp(const HttpOpRequest::ptr_t &op) { const int policy_class(op->mReqPolicy); @@ -151,7 +149,7 @@ void HttpPolicy::addOp(HttpOpRequest * op) } -void HttpPolicy::retryOp(HttpOpRequest * op) +void HttpPolicy::retryOp(const HttpOpRequest::ptr_t &op) { static const HttpTime retry_deltas[] = { @@ -180,7 +178,7 @@ void HttpPolicy::retryOp(HttpOpRequest * op) { ++op->mPolicy503Retries; } - LL_DEBUGS(LOG_CORE) << "HTTP request " << static_cast(op) + LL_DEBUGS(LOG_CORE) << "HTTP request " << op->getHandle() << " retry " << op->mPolicyRetries << " scheduled in " << (delta / HttpTime(1000)) << " mS (" << (external_delta ? "external" : "internal") @@ -189,10 +187,10 @@ void HttpPolicy::retryOp(HttpOpRequest * op) if (op->mTracing > HTTP_TRACE_OFF) { LL_INFOS(LOG_CORE) << "TRACE, ToRetryQueue, Handle: " - << static_cast(op) - << ", Delta: " << (delta / HttpTime(1000)) - << ", Retries: " << op->mPolicyRetries - << LL_ENDL; + << op->getHandle() + << ", Delta: " << (delta / HttpTime(1000)) + << ", Retries: " << op->mPolicyRetries + << LL_ENDL; } mClasses[policy_class]->mRetryQueue.push(op); } @@ -264,14 +262,14 @@ HttpService::ELoopSpeed HttpPolicy::processReadyQueue() // First see if we have any retries... while (needed > 0 && ! retryq.empty()) { - HttpOpRequest * op(retryq.top()); + HttpOpRequest::ptr_t op(retryq.top()); if (op->mPolicyRetryAt > now) break; retryq.pop(); op->stageFromReady(mService); - op->release(); + op.reset(); ++state.mRequestCount; --needed; @@ -296,11 +294,11 @@ HttpService::ELoopSpeed HttpPolicy::processReadyQueue() // Now go on to the new requests... while (needed > 0 && ! readyq.empty()) { - HttpOpRequest * op(readyq.top()); + HttpOpRequest::ptr_t op(readyq.top()); readyq.pop(); op->stageFromReady(mService); - op->release(); + op.reset(); ++state.mRequestCount; --needed; @@ -351,9 +349,9 @@ bool HttpPolicy::changePriority(HttpHandle handle, HttpRequest::priority_t prior { HttpReadyQueue::container_type::iterator cur(iter++); - if (static_cast(*cur) == handle) + if ((*cur)->getHandle() == handle) { - HttpOpRequest * op(*cur); + HttpOpRequest::ptr_t op(*cur); c.erase(cur); // All iterators are now invalidated op->mReqPriority = priority; state.mReadyQueue.push(op); // Re-insert using adapter class @@ -378,12 +376,11 @@ bool HttpPolicy::cancel(HttpHandle handle) { HttpRetryQueue::container_type::iterator cur(iter++); - if (static_cast(*cur) == handle) + if ((*cur)->getHandle() == handle) { - HttpOpRequest * op(*cur); + HttpOpRequest::ptr_t op(*cur); c1.erase(cur); // All iterators are now invalidated op->cancel(); - op->release(); return true; } } @@ -394,12 +391,11 @@ bool HttpPolicy::cancel(HttpHandle handle) { HttpReadyQueue::container_type::iterator cur(iter++); - if (static_cast(*cur) == handle) + if ((*cur)->getHandle() == handle) { - HttpOpRequest * op(*cur); + HttpOpRequest::ptr_t op(*cur); c2.erase(cur); // All iterators are now invalidated op->cancel(); - op->release(); return true; } } @@ -409,7 +405,7 @@ bool HttpPolicy::cancel(HttpHandle handle) } -bool HttpPolicy::stageAfterCompletion(HttpOpRequest * op) +bool HttpPolicy::stageAfterCompletion(const HttpOpRequest::ptr_t &op) { // Retry or finalize if (! op->mStatus) @@ -438,7 +434,7 @@ bool HttpPolicy::stageAfterCompletion(HttpOpRequest * op) // This op is done, finalize it delivering it to the reply queue... if (! op->mStatus) { - LL_WARNS(LOG_CORE) << "HTTP request " << static_cast(op) + LL_WARNS(LOG_CORE) << "HTTP request " << op->getHandle() << " failed after " << op->mPolicyRetries << " retries. Reason: " << op->mStatus.toString() << " (" << op->mStatus.toTerseString() << ")" @@ -446,13 +442,12 @@ bool HttpPolicy::stageAfterCompletion(HttpOpRequest * op) } else if (op->mPolicyRetries) { - LL_DEBUGS(LOG_CORE) << "HTTP request " << static_cast(op) + LL_DEBUGS(LOG_CORE) << "HTTP request " << op->getHandle() << " succeeded on retry " << op->mPolicyRetries << "." << LL_ENDL; } op->stageFromActive(mService); - op->release(); return false; // not active } diff --git a/indra/llcorehttp/_httppolicy.h b/indra/llcorehttp/_httppolicy.h index 11cd89bbd1..3c4126e14b 100755 --- a/indra/llcorehttp/_httppolicy.h +++ b/indra/llcorehttp/_httppolicy.h @@ -60,6 +60,8 @@ private: void operator=(const HttpPolicy &); // Not defined public: + typedef boost::shared_ptr opReqPtr_t; + /// Threading: called by init thread. HttpRequest::policy_t createPolicyClass(); @@ -96,7 +98,7 @@ public: /// from queue. /// /// Threading: called by worker thread - void addOp(HttpOpRequest *); + void addOp(const opReqPtr_t &); /// Similar to addOp, used when a caller wants to retry a /// request that has failed. It's placed on a special retry @@ -106,7 +108,7 @@ public: /// order. /// /// Threading: called by worker thread - void retryOp(HttpOpRequest *); + void retryOp(const opReqPtr_t &); /// Attempt to change the priority of an earlier request. /// Request that Shadows HttpService's method @@ -130,7 +132,7 @@ public: /// sent on to the reply queue. /// /// Threading: called by worker thread - bool stageAfterCompletion(HttpOpRequest * op); + bool stageAfterCompletion(const opReqPtr_t &op); /// Get a reference to global policy options. Caller is expected /// to do context checks like no setting once running. These diff --git a/indra/llcorehttp/_httpreadyqueue.h b/indra/llcorehttp/_httpreadyqueue.h index 5f19a9c5f9..7418988ec1 100755 --- a/indra/llcorehttp/_httpreadyqueue.h +++ b/indra/llcorehttp/_httpreadyqueue.h @@ -56,12 +56,12 @@ namespace LLCore #if LLCORE_HTTP_READY_QUEUE_IGNORES_PRIORITY -typedef std::deque HttpReadyQueueBase; +typedef std::deque HttpReadyQueueBase; #else -typedef std::priority_queue, +typedef std::priority_queue, LLCore::HttpOpRequestCompare> HttpReadyQueueBase; #endif // LLCORE_HTTP_READY_QUEUE_IGNORES_PRIORITY diff --git a/indra/llcorehttp/_httpreplyqueue.cpp b/indra/llcorehttp/_httpreplyqueue.cpp index 912655d328..2b138f3ad5 100755 --- a/indra/llcorehttp/_httpreplyqueue.cpp +++ b/indra/llcorehttp/_httpreplyqueue.cpp @@ -45,16 +45,11 @@ HttpReplyQueue::HttpReplyQueue() HttpReplyQueue::~HttpReplyQueue() { - while (! mQueue.empty()) - { - HttpOperation * op = mQueue.back(); - mQueue.pop_back(); - op->release(); - } + mQueue.clear(); } -void HttpReplyQueue::addOp(HttpOperation * op) +void HttpReplyQueue::addOp(const HttpReplyQueue::opPtr_t &op) { { HttpScopedLock lock(mQueueMutex); @@ -65,15 +60,15 @@ void HttpReplyQueue::addOp(HttpOperation * op) } -HttpOperation * HttpReplyQueue::fetchOp() +HttpReplyQueue::opPtr_t HttpReplyQueue::fetchOp() { - HttpOperation * result(NULL); + HttpOperation::ptr_t result; { HttpScopedLock lock(mQueueMutex); if (mQueue.empty()) - return NULL; + return opPtr_t(); result = mQueue.front(); mQueue.erase(mQueue.begin()); @@ -97,9 +92,6 @@ void HttpReplyQueue::fetchAll(OpContainer & ops) mQueue.swap(ops); } } - - // Caller also acquires the reference counts on each op. - return; } diff --git a/indra/llcorehttp/_httpreplyqueue.h b/indra/llcorehttp/_httpreplyqueue.h index 7ad65c581f..0e39e22dde 100755 --- a/indra/llcorehttp/_httpreplyqueue.h +++ b/indra/llcorehttp/_httpreplyqueue.h @@ -62,13 +62,15 @@ class HttpReplyQueue : private boost::noncopyable { public: + typedef boost::shared_ptr opPtr_t; typedef boost::shared_ptr ptr_t; HttpReplyQueue(); virtual ~HttpReplyQueue(); public: - typedef std::vector OpContainer; + + typedef std::vector< opPtr_t > OpContainer; /// Insert an object at the back of the reply queue. /// @@ -76,7 +78,7 @@ public: /// through the queue. /// /// Threading: callable by any thread. - void addOp(HttpOperation * op); + void addOp(const opPtr_t &op); /// Fetch an operation from the head of the queue. Returns /// NULL if none exists. @@ -84,7 +86,7 @@ public: /// Caller acquires reference count on returned operation. /// /// Threading: callable by any thread. - HttpOperation * fetchOp(); + opPtr_t fetchOp(); /// Caller acquires reference count on each returned operation /// diff --git a/indra/llcorehttp/_httprequestqueue.cpp b/indra/llcorehttp/_httprequestqueue.cpp index c16966d078..c6f4ad789f 100755 --- a/indra/llcorehttp/_httprequestqueue.cpp +++ b/indra/llcorehttp/_httprequestqueue.cpp @@ -47,12 +47,7 @@ HttpRequestQueue::HttpRequestQueue() HttpRequestQueue::~HttpRequestQueue() { - while (! mQueue.empty()) - { - HttpOperation * op = mQueue.back(); - mQueue.pop_back(); - op->release(); - } + mQueue.clear(); } @@ -73,7 +68,7 @@ void HttpRequestQueue::term() } -HttpStatus HttpRequestQueue::addOp(HttpOperation * op) +HttpStatus HttpRequestQueue::addOp(const HttpRequestQueue::opPtr_t &op) { bool wake(false); { @@ -95,9 +90,9 @@ HttpStatus HttpRequestQueue::addOp(HttpOperation * op) } -HttpOperation * HttpRequestQueue::fetchOp(bool wait) +HttpRequestQueue::opPtr_t HttpRequestQueue::fetchOp(bool wait) { - HttpOperation * result(NULL); + HttpOperation::ptr_t result; { HttpScopedLock lock(mQueueMutex); @@ -105,7 +100,7 @@ HttpOperation * HttpRequestQueue::fetchOp(bool wait) while (mQueue.empty()) { if (! wait || mQueueStopped) - return NULL; + return HttpOperation::ptr_t(); mQueueCV.wait(lock); } diff --git a/indra/llcorehttp/_httprequestqueue.h b/indra/llcorehttp/_httprequestqueue.h index c9c52b7233..3c3d134b07 100755 --- a/indra/llcorehttp/_httprequestqueue.h +++ b/indra/llcorehttp/_httprequestqueue.h @@ -61,6 +61,8 @@ private: void operator=(const HttpRequestQueue &); // Not defined public: + typedef boost::shared_ptr opPtr_t; + static void init(); static void term(); @@ -71,7 +73,7 @@ public: } public: - typedef std::vector OpContainer; + typedef std::vector OpContainer; /// Insert an object at the back of the request queue. /// @@ -83,7 +85,7 @@ public: /// an explicit release() call. /// /// Threading: callable by any thread. - HttpStatus addOp(HttpOperation * op); + HttpStatus addOp(const opPtr_t &op); /// Return the operation on the front of the queue. If /// the queue is empty and @wait is false, call returns @@ -95,7 +97,7 @@ public: /// Caller acquires reference count any returned operation /// /// Threading: callable by any thread. - HttpOperation * fetchOp(bool wait); + opPtr_t fetchOp(bool wait); /// Return all queued requests to caller. The @ops argument /// should be empty when called and will be swap()'d with diff --git a/indra/llcorehttp/_httpretryqueue.h b/indra/llcorehttp/_httpretryqueue.h index 745adec09d..5d8c529cff 100755 --- a/indra/llcorehttp/_httpretryqueue.h +++ b/indra/llcorehttp/_httpretryqueue.h @@ -49,15 +49,15 @@ namespace LLCore struct HttpOpRetryCompare { - bool operator()(const HttpOpRequest * lhs, const HttpOpRequest * rhs) + bool operator()(const HttpOpRequest::ptr_t &lhs, const HttpOpRequest::ptr_t &rhs) { return lhs->mPolicyRetryAt < rhs->mPolicyRetryAt; } }; -typedef std::priority_queue, +typedef std::priority_queue, LLCore::HttpOpRetryCompare> HttpRetryQueueBase; class HttpRetryQueue : public HttpRetryQueueBase diff --git a/indra/llcorehttp/_httpservice.cpp b/indra/llcorehttp/_httpservice.cpp index 252db78c89..6c39fdc61b 100755 --- a/indra/llcorehttp/_httpservice.cpp +++ b/indra/llcorehttp/_httpservice.cpp @@ -263,14 +263,13 @@ void HttpService::shutdown() // Cancel requests already on the request queue HttpRequestQueue::OpContainer ops; mRequestQueue->fetchAll(false, ops); - while (! ops.empty()) - { - HttpOperation * op(ops.front()); - ops.erase(ops.begin()); - op->cancel(); - op->release(); - } + for (HttpRequestQueue::OpContainer::iterator it = ops.begin(); + it != ops.end(); ++it) + { + (*it)->cancel(); + } + ops.clear(); // Shutdown transport canceling requests, freeing resources mTransport->shutdown(); @@ -324,7 +323,7 @@ HttpService::ELoopSpeed HttpService::processRequestQueue(ELoopSpeed loop) mRequestQueue->fetchAll(wait_for_req, ops); while (! ops.empty()) { - HttpOperation * op(ops.front()); + HttpOperation::ptr_t op(ops.front()); ops.erase(ops.begin()); // Process operation @@ -338,7 +337,7 @@ HttpService::ELoopSpeed HttpService::processRequestQueue(ELoopSpeed loop) if (op->mTracing > HTTP_TRACE_OFF) { LL_INFOS(LOG_CORE) << "TRACE, FromRequestQueue, Handle: " - << static_cast(op) + << op->getHandle() << LL_ENDL; } @@ -347,7 +346,7 @@ HttpService::ELoopSpeed HttpService::processRequestQueue(ELoopSpeed loop) } // Done with operation - op->release(); + op.reset(); } // Queue emptied, allow polling loop to sleep diff --git a/indra/llcorehttp/httpcommon.h b/indra/llcorehttp/httpcommon.h index 1bc20fe6b5..b2db01d038 100755 --- a/indra/llcorehttp/httpcommon.h +++ b/indra/llcorehttp/httpcommon.h @@ -209,6 +209,7 @@ namespace LLCore /// becomes invalid and may be recycled for other queued requests. typedef void * HttpHandle; + #define LLCORE_HTTP_HANDLE_INVALID (NULL) /// For internal scheduling and metrics, we use a microsecond diff --git a/indra/llcorehttp/httprequest.cpp b/indra/llcorehttp/httprequest.cpp index 24e0f582e1..1c7994927b 100755 --- a/indra/llcorehttp/httprequest.cpp +++ b/indra/llcorehttp/httprequest.cpp @@ -127,27 +127,22 @@ HttpHandle HttpRequest::setPolicyOption(EPolicyOption opt, policy_t pclass, long value, HttpHandler::ptr_t handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpSetGet * op = new HttpOpSetGet(); + HttpOpSetGet::ptr_t op(new HttpOpSetGet()); if (! (status = op->setupSet(opt, pclass, value))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } @@ -155,27 +150,22 @@ HttpHandle HttpRequest::setPolicyOption(EPolicyOption opt, policy_t pclass, const std::string & value, HttpHandler::ptr_t handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpSetGet * op = new HttpOpSetGet(); + HttpOpSetGet::ptr_t op (new HttpOpSetGet()); if (! (status = op->setupSet(opt, pclass, value))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } @@ -198,27 +188,22 @@ HttpHandle HttpRequest::requestGet(policy_t policy_id, HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(); + HttpOpRequest::ptr_t op(new HttpOpRequest()); if (! (status = op->setupGet(policy_id, priority, url, options, headers))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, user_handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } @@ -232,27 +217,22 @@ HttpHandle HttpRequest::requestGetByteRange(policy_t policy_id, HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(); + HttpOpRequest::ptr_t op(new HttpOpRequest()); if (! (status = op->setupGetByteRange(policy_id, priority, url, offset, len, options, headers))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, user_handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } @@ -265,27 +245,22 @@ HttpHandle HttpRequest::requestPost(policy_t policy_id, HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(); + HttpOpRequest::ptr_t op(new HttpOpRequest()); if (! (status = op->setupPost(policy_id, priority, url, body, options, headers))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, user_handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } @@ -298,27 +273,22 @@ HttpHandle HttpRequest::requestPut(policy_t policy_id, HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(); + HttpOpRequest::ptr_t op (new HttpOpRequest()); if (! (status = op->setupPut(policy_id, priority, url, body, options, headers))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, user_handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } HttpHandle HttpRequest::requestDelete(policy_t policy_id, @@ -329,27 +299,22 @@ HttpHandle HttpRequest::requestDelete(policy_t policy_id, HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(); + HttpOpRequest::ptr_t op(new HttpOpRequest()); if (!(status = op->setupDelete(policy_id, priority, url, options, headers))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, user_handler); if (!(status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } HttpHandle HttpRequest::requestPatch(policy_t policy_id, @@ -361,27 +326,22 @@ HttpHandle HttpRequest::requestPatch(policy_t policy_id, HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(); + HttpOpRequest::ptr_t op (new HttpOpRequest()); if (!(status = op->setupPatch(policy_id, priority, url, body, options, headers))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, user_handler); if (!(status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } HttpHandle HttpRequest::requestCopy(policy_t policy_id, @@ -392,27 +352,23 @@ HttpHandle HttpRequest::requestCopy(policy_t policy_id, HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(); + HttpOpRequest::ptr_t op(new HttpOpRequest()); if (!(status = op->setupCopy(policy_id, priority, url, options, headers))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, user_handler); if (!(status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); + return op->getHandle(); - return handle; } HttpHandle HttpRequest::requestMove(policy_t policy_id, @@ -423,54 +379,45 @@ HttpHandle HttpRequest::requestMove(policy_t policy_id, HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpRequest * op = new HttpOpRequest(); + HttpOpRequest::ptr_t op (new HttpOpRequest()); if (!(status = op->setupMove(policy_id, priority, url, options, headers))) { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } op->setReplyPath(mReplyQueue, user_handler); if (!(status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } HttpHandle HttpRequest::requestNoOp(HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpNull * op = new HttpOpNull(); + HttpOperation::ptr_t op (new HttpOpNull()); op->setReplyPath(mReplyQueue, user_handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - handle = static_cast(op); - - return handle; + return op->getHandle(); } HttpStatus HttpRequest::update(long usecs) { - HttpOperation * op(NULL); + HttpOperation::ptr_t op; if (usecs) { @@ -481,7 +428,7 @@ HttpStatus HttpRequest::update(long usecs) op->visitNotifier(this); // We're done with the operation - op->release(); + op.reset(); } } else @@ -502,7 +449,7 @@ HttpStatus HttpRequest::update(long usecs) op->visitNotifier(this); // We're done with the operation - op->release(); + op.reset(); } } } @@ -520,21 +467,17 @@ HttpStatus HttpRequest::update(long usecs) HttpHandle HttpRequest::requestCancel(HttpHandle request, HttpHandler::ptr_t user_handler) { HttpStatus status; - HttpHandle ret_handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpCancel * op = new HttpOpCancel(request); + HttpOperation::ptr_t op(new HttpOpCancel(request)); op->setReplyPath(mReplyQueue, user_handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return ret_handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - ret_handle = static_cast(op); - - return ret_handle; + return op->getHandle(); } @@ -542,21 +485,17 @@ HttpHandle HttpRequest::requestSetPriority(HttpHandle request, priority_t priori HttpHandler::ptr_t handler) { HttpStatus status; - HttpHandle ret_handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpSetPriority * op = new HttpOpSetPriority(request, priority); + HttpOperation::ptr_t op (new HttpOpSetPriority(request, priority)); op->setReplyPath(mReplyQueue, handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; - return ret_handle; + return LLCORE_HTTP_HANDLE_INVALID; } mLastReqStatus = status; - ret_handle = static_cast(op); - - return ret_handle; + return op->getHandle(); } @@ -610,17 +549,16 @@ HttpHandle HttpRequest::requestStopThread(HttpHandler::ptr_t user_handler) HttpStatus status; HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpStop * op = new HttpOpStop(); + HttpOperation::ptr_t op(new HttpOpStop()); op->setReplyPath(mReplyQueue, user_handler); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; return handle; } mLastReqStatus = status; - handle = static_cast(op); + handle = op->getHandle(); return handle; } @@ -631,17 +569,16 @@ HttpHandle HttpRequest::requestSpin(int mode) HttpStatus status; HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID); - HttpOpSpin * op = new HttpOpSpin(mode); + HttpOperation::ptr_t op(new HttpOpSpin(mode)); op->setReplyPath(mReplyQueue, HttpHandler::ptr_t()); if (! (status = mRequestQueue->addOp(op))) // transfers refcount { - op->release(); mLastReqStatus = status; return handle; } mLastReqStatus = status; - handle = static_cast(op); + handle = op->getHandle(); return handle; } diff --git a/indra/llcorehttp/httprequest.h b/indra/llcorehttp/httprequest.h index 2eb3caa11e..17cfdcd7b6 100755 --- a/indra/llcorehttp/httprequest.h +++ b/indra/llcorehttp/httprequest.h @@ -655,7 +655,6 @@ public: /// @} protected: - void generateNotification(HttpOperation * op); private: typedef boost::shared_ptr HttpReplyQueuePtr_t; diff --git a/indra/llcorehttp/tests/test_httpoperation.hpp b/indra/llcorehttp/tests/test_httpoperation.hpp index 890e5fdd9c..e7df2337de 100755 --- a/indra/llcorehttp/tests/test_httpoperation.hpp +++ b/indra/llcorehttp/tests/test_httpoperation.hpp @@ -76,12 +76,12 @@ namespace tut mMemTotal = GetMemTotal(); // create a new ref counted object with an implicit reference - HttpOpNull * op = new HttpOpNull(); - ensure(op->getRefCount() == 1); + HttpOperation::ptr_t op (new HttpOpNull()); + ensure(op.use_count() == 1); ensure(mMemTotal < GetMemTotal()); // release the implicit reference, causing the object to be released - op->release(); + op.reset(); // make sure we didn't leak any memory ensure(mMemTotal == GetMemTotal()); @@ -99,18 +99,17 @@ namespace tut LLCore::HttpHandler::ptr_t h1 (new TestHandler()); // create a new ref counted object with an implicit reference - HttpOpNull * op = new HttpOpNull(); + HttpOperation::ptr_t op (new HttpOpNull()); // Add the handlers op->setReplyPath(LLCore::HttpOperation::HttpReplyQueuePtr_t(), h1); // Check ref count - ensure(op->getRefCount() == 1); + ensure(op.unique() == 1); // release the reference, releasing the operation but // not the handlers. - op->release(); - op = NULL; + op.reset(); ensure(mMemTotal != GetMemTotal()); // release the handlers diff --git a/indra/llcorehttp/tests/test_httprequestqueue.hpp b/indra/llcorehttp/tests/test_httprequestqueue.hpp index 1de2d8f9ab..ef4ce0479b 100755 --- a/indra/llcorehttp/tests/test_httprequestqueue.hpp +++ b/indra/llcorehttp/tests/test_httprequestqueue.hpp @@ -113,16 +113,16 @@ void HttpRequestqueueTestObjectType::test<3>() HttpRequestQueue * rq = HttpRequestQueue::instanceOf(); - HttpOperation * op = new HttpOpNull(); + HttpOperation::ptr_t op(new HttpOpNull()); rq->addOp(op); // transfer my refcount op = rq->fetchOp(true); // Potentially hangs the test on failure - ensure("One goes in, one comes out", NULL != op); - op->release(); + ensure("One goes in, one comes out", static_cast(op)); + op.reset(); op = rq->fetchOp(false); - ensure("Better not be two of them", NULL == op); + ensure("Better not be two of them", !op); // release the singleton, hold on to the object HttpRequestQueue::term(); @@ -144,13 +144,13 @@ void HttpRequestqueueTestObjectType::test<4>() HttpRequestQueue * rq = HttpRequestQueue::instanceOf(); - HttpOperation * op = new HttpOpNull(); + HttpOperation::ptr_t op (new HttpOpNull()); rq->addOp(op); // transfer my refcount - op = new HttpOpNull(); + op.reset(new HttpOpNull()); rq->addOp(op); // transfer my refcount - op = new HttpOpNull(); + op.reset(new HttpOpNull()); rq->addOp(op); // transfer my refcount { @@ -159,8 +159,9 @@ void HttpRequestqueueTestObjectType::test<4>() ensure("Three go in, three come out", 3 == ops.size()); op = rq->fetchOp(false); - ensure("Better not be any more of them", NULL == op); - + ensure("Better not be any more of them", !op); + op.reset(); + // release the singleton, hold on to the object HttpRequestQueue::term(); @@ -168,12 +169,13 @@ void HttpRequestqueueTestObjectType::test<4>() ensure(mMemTotal < GetMemTotal()); // Release them - while (! ops.empty()) - { - HttpOperation * op = ops.front(); - ops.erase(ops.begin()); - op->release(); - } + ops.clear(); +// while (! ops.empty()) +// { +// HttpOperation * op = ops.front(); +// ops.erase(ops.begin()); +// op->release(); +// } } // Should be clean diff --git a/indra/newview/llmaterialmgr.cpp b/indra/newview/llmaterialmgr.cpp index 6dc0525365..9ac560c217 100755 --- a/indra/newview/llmaterialmgr.cpp +++ b/indra/newview/llmaterialmgr.cpp @@ -594,6 +594,9 @@ void LLMaterialMgr::processGetQueue() while (mGetQueue.end() != loopRegionQueue) { #if 1 + //* $TODO: This block is screaming to be turned into a coroutine. + // see processGetQueueCoro() below. + // get_queue_t::iterator itRegionQueue = loopRegionQueue++; const LLUUID& region_id = itRegionQueue->first; @@ -789,50 +792,10 @@ void LLMaterialMgr::processGetAllQueue() getall_queue_t::iterator itRegion = loopRegion++; const LLUUID& region_id = *itRegion; -#if 1 + LLCoros::instance().launch("LLMaterialMgr::processGetAllQueueCoro", boost::bind(&LLMaterialMgr::processGetAllQueueCoro, this, region_id)); -#else - LLViewerRegion* regionp = LLWorld::instance().getRegionFromID(region_id); - if (regionp == NULL) - { - LL_WARNS("Materials") << "Unknown region with id " << region_id.asString() << LL_ENDL; - clearGetQueues(region_id); // Invalidates region_id - continue; - } - else if (!regionp->capabilitiesReceived() || regionp->materialsCapThrottled()) - { - continue; - } - std::string capURL = regionp->getCapability(MATERIALS_CAPABILITY_NAME); - if (capURL.empty()) - { - LL_WARNS("Materials") << "Capability '" << MATERIALS_CAPABILITY_NAME - << "' is not defined on the current region '" << regionp->getName() << "'" << LL_ENDL; - clearGetQueues(region_id); // Invalidates region_id - continue; - } - - LL_DEBUGS("Materials") << "GET all for region " << region_id << "url " << capURL << LL_ENDL; - LLMaterialHttpHandler *handler = - new LLMaterialHttpHandler("GET", - boost::bind(&LLMaterialMgr::onGetAllResponse, this, _1, _2, *itRegion) - ); - - LLCore::HttpHandle handle = mHttpRequest->requestGet(mHttpPolicy, mHttpPriority, capURL, - mHttpOptions, mHttpHeaders, handler); - - if (handle == LLCORE_HTTP_HANDLE_INVALID) - { - delete handler; - LLCore::HttpStatus status = mHttpRequest->getStatus(); - LL_ERRS("Meterials") << "Failed to execute material GET. Status = " << - status.toULong() << "\"" << status.toString() << "\"" << LL_ENDL; - } - - regionp->resetMaterialsCapThrottle(); -#endif mGetAllPending.insert(std::pair(region_id, LLFrameTimer::getTotalSeconds())); mGetAllQueue.erase(itRegion); // Invalidates region_id } -- cgit v1.3