From 5c06afc977d173435dc063936cdc7c9d2afbcf47 Mon Sep 17 00:00:00 2001 From: Inusaito Sayori Date: Thu, 17 Apr 2014 20:23:48 -0400 Subject: [PATCH] [LLMeshRepo sync] AICurl updates toward LLCurl LLHTTPClient::getByteRange no longer throws AICurlNoEasyHandle, instead it returns whether or not it threw, to match the true/false convention of LLCurl. - In addition, the header param has been shifted to earlier in this function to ease diffings. ResponderBase now has static bool isGoodStatus, introduced into the Responder base class of LLCurl --- indra/llmessage/llhttpclient.cpp | 16 ++- indra/llmessage/llhttpclient.h | 14 +- indra/newview/llfloateravatarpicker.cpp | 2 +- indra/newview/llmeshrepository.cpp | 167 +++++++++++------------- indra/newview/llmeshrepository.h | 2 +- indra/newview/llvoavatarself.cpp | 2 +- 6 files changed, 99 insertions(+), 104 deletions(-) diff --git a/indra/llmessage/llhttpclient.cpp b/indra/llmessage/llhttpclient.cpp index 1374a1b93..bd40d8e69 100644 --- a/indra/llmessage/llhttpclient.cpp +++ b/indra/llmessage/llhttpclient.cpp @@ -237,13 +237,21 @@ void LLHTTPClient::request( req->run(parent, new_parent_state, parent != NULL, true, default_engine); } -void LLHTTPClient::getByteRange(std::string const& url, S32 offset, S32 bytes, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug)) +bool LLHTTPClient::getByteRange(std::string const& url, AIHTTPHeaders& headers, S32 offset, S32 bytes, ResponderPtr responder/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug)) { - if(offset > 0 || bytes > 0) + try { - headers.addHeader("Range", llformat("bytes=%d-%d", offset, offset + bytes - 1)); + if (offset > 0 || bytes > 0) + { + headers.addHeader("Range", llformat("bytes=%d-%d", offset, offset + bytes - 1)); + } + request(url, HTTP_GET, NULL, responder, headers, NULL/*,*/ DEBUG_CURLIO_PARAM(debug)); } - request(url, HTTP_GET, NULL, responder, headers, NULL/*,*/ DEBUG_CURLIO_PARAM(debug)); + catch(AICurlNoEasyHandle const&) + { + return false; + } + return true; } void LLHTTPClient::head(std::string const& url, ResponderHeadersOnly* responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug)) diff --git a/indra/llmessage/llhttpclient.h b/indra/llmessage/llhttpclient.h index a366811d6..3bb60b04f 100644 --- a/indra/llmessage/llhttpclient.h +++ b/indra/llmessage/llhttpclient.h @@ -133,6 +133,14 @@ public: public: typedef boost::shared_ptr buffer_ptr_t; + /** + * @brief return true if the status code indicates success. + */ + static bool isGoodStatus(U32 status) + { + return((200 <= status) && (status < 300)); + } + protected: ResponderBase(void); virtual ~ResponderBase(); @@ -452,9 +460,9 @@ public: static void head(std::string const& url, ResponderHeadersOnly* responder/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug = debug_off)) { AIHTTPHeaders headers; head(url, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug)); } - static void getByteRange(std::string const& url, S32 offset, S32 bytes, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug = debug_off)); - static void getByteRange(std::string const& url, S32 offset, S32 bytes, ResponderPtr responder/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug = debug_off)) - { AIHTTPHeaders headers; getByteRange(url, offset, bytes, responder, headers/*,*/ DEBUG_CURLIO_PARAM(debug)); } + static bool getByteRange(std::string const& url, AIHTTPHeaders& headers, S32 offset, S32 bytes, ResponderPtr responder/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug = debug_off)); + static bool getByteRange(std::string const& url, S32 offset, S32 bytes, ResponderPtr responder/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug = debug_off)) + { AIHTTPHeaders headers; return getByteRange(url, headers, offset, bytes, responder/*,*/ DEBUG_CURLIO_PARAM(debug)); } static void get(std::string const& url, ResponderPtr responder, AIHTTPHeaders& headers/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug = debug_off)); static void get(std::string const& url, ResponderPtr responder/*,*/ DEBUG_CURLIO_PARAM(EDebugCurl debug = debug_off)) diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp index f503fa3ba..718750b5f 100644 --- a/indra/newview/llfloateravatarpicker.cpp +++ b/indra/newview/llfloateravatarpicker.cpp @@ -427,7 +427,7 @@ public: // in case of invalid characters, the avatar picker returns a 400 // just set it to process so it displays 'not found' - if ((200 <= status && status < 300) || status == 400) + if (isGoodStatus(status) || status == 400) { if (LLFloaterAvatarPicker::instanceExists()) { diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp index 5a55d2562..4b46e1ca0 100644 --- a/indra/newview/llmeshrepository.cpp +++ b/indra/newview/llmeshrepository.cpp @@ -239,7 +239,7 @@ public: } } - /*virtual*/ void completedRaw(U32 status, const std::string& reason, + virtual void completedRaw(U32 status, const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer); @@ -278,7 +278,7 @@ public: } } - /*virtual*/ void completedRaw(U32 status, const std::string& reason, + virtual void completedRaw(U32 status, const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer); @@ -306,7 +306,7 @@ public: llassert(mProcessed || LLApp::isExiting()); } - /*virtual*/ void completedRaw(U32 status, const std::string& reason, + virtual void completedRaw(U32 status, const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer); @@ -334,7 +334,7 @@ public: llassert(mProcessed || LLApp::isExiting()); } - /*virtual*/ void completedRaw(U32 status, const std::string& reason, + virtual void completedRaw(U32 status, const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer); @@ -362,7 +362,7 @@ public: llassert(mProcessed || LLApp::isExiting()); } - /*virtual*/ void completedRaw(U32 status, const std::string& reason, + virtual void completedRaw(U32 status, const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer); @@ -437,7 +437,7 @@ public: { } - /*virtual*/ void completed(U32 status, + virtual void completed(U32 status, const std::string& reason, const LLSD& content) { @@ -451,7 +451,7 @@ public: LLWholeModelFeeObserver* observer = mObserverHandle.get(); - if (((200 <= status) && (status < 300)) && + if (isGoodStatus(status) && cc["state"].asString() == "upload") { mWholeModelUploadURL = cc["uploader"].asString(); @@ -495,7 +495,7 @@ public: { } - /*virtual*/ void completed(U32 status, + virtual void completed(U32 status, const std::string& reason, const LLSD& content) { @@ -511,7 +511,7 @@ public: // requested "mesh" asset type isn't actually the type // of the resultant object, fix it up here. - if (((200 <= status) && (status < 300)) && + if (isGoodStatus(status) && cc["state"].asString() == "complete") { mModelData["asset_type"] = "object"; @@ -583,50 +583,35 @@ void LLMeshRepoThread::run() while (!mLODReqQ.empty() && count < MAX_MESH_REQUESTS_PER_SECOND && sActiveLODRequests < (S32)sMaxConcurrentRequests) { + if (mMutex) { mMutex->lock(); LODRequest req = mLODReqQ.front(); mLODReqQ.pop(); LLMeshRepository::sLODProcessing--; mMutex->unlock(); - try + if (!fetchMeshLOD(req.mMeshParams, req.mLOD, count))//failed, resubmit { - fetchMeshLOD(req.mMeshParams, req.mLOD, count); - } - catch(AICurlNoEasyHandle const& error) - { - llwarns << "fetchMeshLOD() failed: " << error.what() << llendl; mMutex->lock(); - LLMeshRepository::sLODProcessing++; mLODReqQ.push(req); mMutex->unlock(); - break; } } } while (!mHeaderReqQ.empty() && count < MAX_MESH_REQUESTS_PER_SECOND && sActiveHeaderRequests < (S32)sMaxConcurrentRequests) { + if (mMutex) { mMutex->lock(); HeaderRequest req = mHeaderReqQ.front(); mHeaderReqQ.pop(); mMutex->unlock(); - bool success = false; - try - { - success = fetchMeshHeader(req.mMeshParams, count); - } - catch(AICurlNoEasyHandle const& error) - { - llwarns << "fetchMeshHeader() failed: " << error.what() << llendl; - } - if (!success) + if (!fetchMeshHeader(req.mMeshParams, count))//failed, resubmit { mMutex->lock(); mHeaderReqQ.push(req) ; mMutex->unlock(); - break; } } } @@ -636,16 +621,7 @@ void LLMeshRepoThread::run() for (std::set::iterator iter = mSkinRequests.begin(); iter != mSkinRequests.end(); ++iter) { LLUUID mesh_id = *iter; - bool success = false; - try - { - success = fetchMeshSkinInfo(mesh_id); - } - catch(AICurlNoEasyHandle const& error) - { - llwarns << "fetchMeshSkinInfo(" << mesh_id << ") failed: " << error.what() << llendl; - } - if (!success) + if (!fetchMeshSkinInfo(mesh_id)) { incomplete.insert(mesh_id); } @@ -658,16 +634,7 @@ void LLMeshRepoThread::run() for (std::set::iterator iter = mDecompositionRequests.begin(); iter != mDecompositionRequests.end(); ++iter) { LLUUID mesh_id = *iter; - bool success = false; - try - { - success = fetchMeshDecomposition(mesh_id); - } - catch(AICurlNoEasyHandle const& error) - { - llwarns << "fetchMeshDecomposition(" << mesh_id << ") failed: " << error.what() << llendl; - } - if (!success) + if (!fetchMeshDecomposition(mesh_id)) { incomplete.insert(mesh_id); } @@ -680,16 +647,7 @@ void LLMeshRepoThread::run() for (std::set::iterator iter = mPhysicsShapeRequests.begin(); iter != mPhysicsShapeRequests.end(); ++iter) { LLUUID mesh_id = *iter; - bool success = false; - try - { - success = fetchMeshPhysicsShape(mesh_id); - } - catch(AICurlNoEasyHandle const& error) - { - llwarns << "fetchMeshPhysicsShape(" << mesh_id << ") failed: " << error.what() << llendl; - } - if (!success) + if (!fetchMeshPhysicsShape(mesh_id)) { incomplete.insert(mesh_id); } @@ -799,6 +757,7 @@ bool LLMeshRepoThread::fetchMeshSkinInfo(const LLUUID& mesh_id) return false; } + bool ret = true ; U32 header_size = mMeshHeaderSize[mesh_id]; if (header_size > 0) @@ -820,7 +779,7 @@ bool LLMeshRepoThread::fetchMeshSkinInfo(const LLUUID& mesh_id) U8* buffer = new U8[size]; file.read(buffer, size); - //make sure buffer isn't all 0's (reserved block but not written) + //make sure buffer isn't all 0's by checking the first 1KB (reserved block but not written) bool zero = true; for (S32 i = 0; i < llmin(size, 1024) && zero; ++i) { @@ -845,9 +804,12 @@ bool LLMeshRepoThread::fetchMeshSkinInfo(const LLUUID& mesh_id) std::string http_url = constructUrl(mesh_id); if (!http_url.empty()) { - LLHTTPClient::getByteRange(http_url, offset, size, - new LLMeshSkinInfoResponder(mesh_id, offset, size), headers); - LLMeshRepository::sHTTPRequestCount++; + ret = LLHTTPClient::getByteRange(http_url, headers, offset, size, + new LLMeshSkinInfoResponder(mesh_id, offset, size)); + if (ret) + { + LLMeshRepository::sHTTPRequestCount++; + } } } } @@ -857,7 +819,7 @@ bool LLMeshRepoThread::fetchMeshSkinInfo(const LLUUID& mesh_id) } //early out was not hit, effectively fetched - return true; + return ret; } //return false if failed to get header @@ -873,6 +835,7 @@ bool LLMeshRepoThread::fetchMeshDecomposition(const LLUUID& mesh_id) } U32 header_size = mMeshHeaderSize[mesh_id]; + bool ret = true ; if (header_size > 0) { @@ -893,7 +856,7 @@ bool LLMeshRepoThread::fetchMeshDecomposition(const LLUUID& mesh_id) U8* buffer = new U8[size]; file.read(buffer, size); - //make sure buffer isn't all 0's (reserved block but not written) + //make sure buffer isn't all 0's by checking the first 1KB (reserved block but not written) bool zero = true; for (S32 i = 0; i < llmin(size, 1024) && zero; ++i) { @@ -918,10 +881,12 @@ bool LLMeshRepoThread::fetchMeshDecomposition(const LLUUID& mesh_id) std::string http_url = constructUrl(mesh_id); if (!http_url.empty()) { - // This might throw AICurlNoEasyHandle. - LLHTTPClient::getByteRange(http_url, offset, size, - new LLMeshDecompositionResponder(mesh_id, offset, size), headers); - LLMeshRepository::sHTTPRequestCount++; + ret = LLHTTPClient::getByteRange(http_url, headers, offset, size, + new LLMeshDecompositionResponder(mesh_id, offset, size)); + if(ret) + { + LLMeshRepository::sHTTPRequestCount++; + } } } } @@ -931,7 +896,7 @@ bool LLMeshRepoThread::fetchMeshDecomposition(const LLUUID& mesh_id) } //early out was not hit, effectively fetched - return true; + return ret; } //return false if failed to get header @@ -947,6 +912,7 @@ bool LLMeshRepoThread::fetchMeshPhysicsShape(const LLUUID& mesh_id) } U32 header_size = mMeshHeaderSize[mesh_id]; + bool ret = true ; if (header_size > 0) { @@ -992,10 +958,13 @@ bool LLMeshRepoThread::fetchMeshPhysicsShape(const LLUUID& mesh_id) std::string http_url = constructUrl(mesh_id); if (!http_url.empty()) { - // This might throw AICurlNoEasyHandle. - LLHTTPClient::getByteRange(http_url, offset, size, - new LLMeshPhysicsShapeResponder(mesh_id, offset, size), headers); - LLMeshRepository::sHTTPRequestCount++; + ret = LLHTTPClient::getByteRange(http_url, headers, offset, size, + new LLMeshPhysicsShapeResponder(mesh_id, offset, size)); + + if(ret) + { + LLMeshRepository::sHTTPRequestCount++; + } } } else @@ -1009,7 +978,7 @@ bool LLMeshRepoThread::fetchMeshPhysicsShape(const LLUUID& mesh_id) } //early out was not hit, effectively fetched - return true; + return ret; } //static @@ -1056,14 +1025,14 @@ bool LLMeshRepoThread::fetchMeshHeader(const LLVolumeParams& mesh_params, U32& c LLMeshRepository::sCacheBytesRead += bytes; file.read(buffer, bytes); if (headerReceived(mesh_params, buffer, bytes)) - { - // Already have header, no need to retry. + { //did not do an HTTP request, return false return true; } } } //either cache entry doesn't exist or is corrupt, request header from simulator + bool retval = true; AIHTTPHeaders headers("Accept", "application/octet-stream"); std::string http_url = constructUrl(mesh_params.getSculptID()); @@ -1072,19 +1041,24 @@ bool LLMeshRepoThread::fetchMeshHeader(const LLVolumeParams& mesh_params, U32& c //grab first 4KB if we're going to bother with a fetch. Cache will prevent future fetches if a full mesh fits //within the first 4KB //NOTE -- this will break of headers ever exceed 4KB - // This might throw AICurlNoEasyHandle. - LLHTTPClient::getByteRange(http_url, 0, 4096, new LLMeshHeaderResponder(mesh_params), headers); - LLMeshRepository::sHTTPRequestCount++; + retval = LLHTTPClient::getByteRange(http_url, headers, 0, 4096, new LLMeshHeaderResponder(mesh_params)); + if (retval) + { + LLMeshRepository::sHTTPRequestCount++; + } count++; } - return true; + return retval; } -void LLMeshRepoThread::fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod, U32& count) +//return false if failed to get mesh lod. +bool LLMeshRepoThread::fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod, U32& count) { //protected by mMutex mHeaderMutex->lock(); + bool retval = true; + LLUUID mesh_id = mesh_params.getSculptID(); U32 header_size = mMeshHeaderSize[mesh_id]; @@ -1120,7 +1094,7 @@ void LLMeshRepoThread::fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod, if (lodReceived(mesh_params, lod, buffer, size)) { delete[] buffer; - return; + return true; } } @@ -1133,10 +1107,13 @@ void LLMeshRepoThread::fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod, std::string http_url = constructUrl(mesh_id); if (!http_url.empty()) { - // This might throw AICurlNoEasyHandle. - LLHTTPClient::getByteRange(constructUrl(mesh_id), offset, size, - new LLMeshLODResponder(mesh_params, lod, offset, size), headers); - LLMeshRepository::sHTTPRequestCount++; + retval = LLHTTPClient::getByteRange(constructUrl(mesh_id), headers, offset, size, + new LLMeshLODResponder(mesh_params, lod, offset, size)); + + if (retval) + { + LLMeshRepository::sHTTPRequestCount++; + } count++; } else @@ -1476,18 +1453,18 @@ bool LLMeshUploadThread::run() void LLMeshUploadThread::postRequest(std::string& whole_model_upload_url, AIMeshUpload* state_machine) { - if (!mDoUpload) - { - LLHTTPClient::post(mWholeModelFeeCapability, mModelData, - new LLWholeModelFeeResponder(mModelData, mFeeObserverHandle, whole_model_upload_url)/*,*/ - DEBUG_CURLIO_PARAM(debug_on), keep_alive, state_machine, AIMeshUpload_responderFinished); - } - else + if (mDoUpload) { LLHTTPClient::post(whole_model_upload_url, mBody, new LLWholeModelUploadResponder(mModelData, mUploadObserverHandle)/*,*/ DEBUG_CURLIO_PARAM(debug_off), keep_alive, state_machine, AIMeshUpload_responderFinished); } + else + { + LLHTTPClient::post(mWholeModelFeeCapability, mModelData, + new LLWholeModelFeeResponder(mModelData, mFeeObserverHandle, whole_model_upload_url)/*,*/ + DEBUG_CURLIO_PARAM(debug_on), keep_alive, state_machine, AIMeshUpload_responderFinished); + } } void dump_llsd_to_file(const LLSD& content, std::string filename) @@ -1877,6 +1854,7 @@ void LLMeshLODResponder::completedRaw(U32 status, const std::string& reason, } else { + llassert(status == HTTP_INTERNAL_ERROR || status == HTTP_SERVICE_UNAVAILABLE); //intentionally trigger a breakpoint llwarns << "Unhandled status " << status << llendl; } return; @@ -1928,12 +1906,13 @@ void LLMeshSkinInfoResponder::completedRaw(U32 status, const std::string& reason { if (is_internal_http_error_that_warrants_a_retry(status) || status == HTTP_SERVICE_UNAVAILABLE) { //timeout or service unavailable, try again - llwarns << "Timeout or service unavailable, retrying." << llendl; + llwarns << "Timeout or service unavailable, retrying loadMeshSkinInfo() for " << mMeshID << llendl; LLMeshRepository::sHTTPRetryCount++; gMeshRepo.mThread->loadMeshSkinInfo(mMeshID); } else { + llassert(status == HTTP_INTERNAL_ERROR || status == HTTP_SERVICE_UNAVAILABLE); //intentionally trigger a breakpoint llwarns << "Unhandled status " << status << llendl; } return; diff --git a/indra/newview/llmeshrepository.h b/indra/newview/llmeshrepository.h index 33447db7b..4ef99f1b1 100644 --- a/indra/newview/llmeshrepository.h +++ b/indra/newview/llmeshrepository.h @@ -324,7 +324,7 @@ public: void lockAndLoadMeshLOD(const LLVolumeParams& mesh_params, S32 lod); void loadMeshLOD(const LLVolumeParams& mesh_params, S32 lod); bool fetchMeshHeader(const LLVolumeParams& mesh_params, U32& count); - void fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod, U32& count); + bool fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod, U32& count); bool headerReceived(const LLVolumeParams& mesh_params, U8* data, S32 data_size); bool lodReceived(const LLVolumeParams& mesh_params, S32 lod, U8* data, S32 data_size); bool skinInfoReceived(const LLUUID& mesh_id, U8* data, S32 data_size); diff --git a/indra/newview/llvoavatarself.cpp b/indra/newview/llvoavatarself.cpp index c3ead99db..14cbd4993 100644 --- a/indra/newview/llvoavatarself.cpp +++ b/indra/newview/llvoavatarself.cpp @@ -2492,7 +2492,7 @@ public: /*virtual*/ void completedHeaders(U32 status, std::string const& reason, AIHTTPReceivedHeaders const& headers) { - if (200 <= status && status < 300) + if (isGoodStatus(status)) { LL_DEBUGS("Avatar") << "status OK" << llendl; }