diff options
author | Andrey Lihatskiy <alihatskiy@productengine.com> | 2024-05-15 11:16:27 +0300 |
---|---|---|
committer | Andrey Lihatskiy <alihatskiy@productengine.com> | 2024-05-15 11:16:27 +0300 |
commit | bccc10db9a90d365c353baebf443fde2030ce970 (patch) | |
tree | 2c2e1fd94b29667a809f8d7285d049f5ff5d424d /indra/newview/llhttpretrypolicy.cpp | |
parent | 531cd34f670170ade57f8813fe48012b61a1d3c2 (diff) | |
parent | bb3c36f5cbc0c3b542045fd27255eee24e03da22 (diff) |
Merge branch 'main' into marchcat/x-b-merge
# Conflicts:
# autobuild.xml
# indra/cmake/ConfigurePkgConfig.cmake
# indra/cmake/ICU4C.cmake
# indra/media_plugins/gstreamer010/llmediaimplgstreamer_syms.cpp
# indra/media_plugins/gstreamer010/llmediaimplgstreamer_syms.h
# indra/media_plugins/gstreamer010/llmediaimplgstreamertriviallogging.h
# indra/media_plugins/gstreamer010/llmediaimplgstreamervidplug.cpp
# indra/media_plugins/gstreamer010/llmediaimplgstreamervidplug.h
# indra/media_plugins/gstreamer010/media_plugin_gstreamer010.cpp
# indra/newview/llappviewerlinux_api.h
# indra/newview/llappviewerlinux_api_dbus.cpp
# indra/newview/llappviewerlinux_api_dbus.h
# indra/newview/llfloateremojipicker.cpp
# indra/newview/lloutfitslist.cpp
Diffstat (limited to 'indra/newview/llhttpretrypolicy.cpp')
-rw-r--r-- | indra/newview/llhttpretrypolicy.cpp | 158 |
1 files changed, 79 insertions, 79 deletions
diff --git a/indra/newview/llhttpretrypolicy.cpp b/indra/newview/llhttpretrypolicy.cpp index 1f6ad85be7..de82952b9d 100644 --- a/indra/newview/llhttpretrypolicy.cpp +++ b/indra/newview/llhttpretrypolicy.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llhttpretrypolicy.h * @brief Header for a retry policy class intended for use with http responders. * * $LicenseInfo:firstyear=2013&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2013, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -43,116 +43,116 @@ namespace } LLAdaptiveRetryPolicy::LLAdaptiveRetryPolicy(F32 min_delay, F32 max_delay, F32 backoff_factor, U32 max_retries, bool retry_on_4xx): - mMinDelay(min_delay), - mMaxDelay(max_delay), - mBackoffFactor(backoff_factor), - mMaxRetries(max_retries), - mRetryOn4xx(retry_on_4xx) + mMinDelay(min_delay), + mMaxDelay(max_delay), + mBackoffFactor(backoff_factor), + mMaxRetries(max_retries), + mRetryOn4xx(retry_on_4xx) { - init(); + init(); } void LLAdaptiveRetryPolicy::init() { - mDelay = mMinDelay; - mRetryCount = 0; - mShouldRetry = true; + mDelay = mMinDelay; + mRetryCount = 0; + mShouldRetry = true; } void LLAdaptiveRetryPolicy::reset() { - init(); + init(); } bool LLAdaptiveRetryPolicy::getRetryAfter(const LLSD& headers, F32& retry_header_time) { - return (headers.has(HTTP_IN_HEADER_RETRY_AFTER) - && getSecondsUntilRetryAfter(headers[HTTP_IN_HEADER_RETRY_AFTER].asStringRef(), retry_header_time)); + return (headers.has(HTTP_IN_HEADER_RETRY_AFTER) + && getSecondsUntilRetryAfter(headers[HTTP_IN_HEADER_RETRY_AFTER].asStringRef(), retry_header_time)); } bool LLAdaptiveRetryPolicy::getRetryAfter(const LLCore::HttpHeaders::ptr_t &headers, F32& retry_header_time) { - if (headers) - { - const std::string *retry_value = headers->find(HTTP_IN_HEADER_RETRY_AFTER.c_str()); - if (retry_value && - getSecondsUntilRetryAfter(*retry_value, retry_header_time)) - { - return true; - } - } - return false; + if (headers) + { + const std::string *retry_value = headers->find(HTTP_IN_HEADER_RETRY_AFTER.c_str()); + if (retry_value && + getSecondsUntilRetryAfter(*retry_value, retry_header_time)) + { + return true; + } + } + return false; } void LLAdaptiveRetryPolicy::onSuccess() { - init(); + init(); } void LLAdaptiveRetryPolicy::onFailure(S32 status, const LLSD& headers) { - F32 retry_header_time{}; - bool has_retry_header_time = getRetryAfter(headers,retry_header_time); - onFailureCommon(status, has_retry_header_time, retry_header_time); + F32 retry_header_time{}; + bool has_retry_header_time = getRetryAfter(headers,retry_header_time); + onFailureCommon(status, has_retry_header_time, retry_header_time); } - + void LLAdaptiveRetryPolicy::onFailure(const LLCore::HttpResponse *response) { - F32 retry_header_time{}; - const LLCore::HttpHeaders::ptr_t headers = response->getHeaders(); - bool has_retry_header_time = getRetryAfter(headers,retry_header_time); - onFailureCommon(response->getStatus().getType(), has_retry_header_time, retry_header_time); + F32 retry_header_time{}; + const LLCore::HttpHeaders::ptr_t headers = response->getHeaders(); + bool has_retry_header_time = getRetryAfter(headers,retry_header_time); + onFailureCommon(response->getStatus().getType(), has_retry_header_time, retry_header_time); } void LLAdaptiveRetryPolicy::onFailureCommon(S32 status, bool has_retry_header_time, F32 retry_header_time) { - if (!mShouldRetry) - { - LL_INFOS() << "keep on failing" << LL_ENDL; - return; - } - if (mRetryCount > 0) - { - mDelay = llclamp(mDelay*mBackoffFactor,mMinDelay,mMaxDelay); - } - // Honor server Retry-After header. - // Status 503 may ask us to wait for a certain amount of time before retrying. - F32 wait_time = mDelay; - if (has_retry_header_time) - { - wait_time = retry_header_time; - } - - if (mRetryCount>=mMaxRetries) - { - LL_INFOS() << "Too many retries " << mRetryCount << ", will not retry" << LL_ENDL; - mShouldRetry = false; - } - if (!mRetryOn4xx && !isHttpServerErrorStatus(status)) - { - LL_INFOS() << "Non-server error " << status << ", will not retry" << LL_ENDL; - mShouldRetry = false; - } - if (mShouldRetry) - { - LL_INFOS() << "Retry count " << mRetryCount << " should retry after " << wait_time << LL_ENDL; - mRetryTimer.reset(); - mRetryTimer.setTimerExpirySec(wait_time); - } - mRetryCount++; + if (!mShouldRetry) + { + LL_INFOS() << "keep on failing" << LL_ENDL; + return; + } + if (mRetryCount > 0) + { + mDelay = llclamp(mDelay*mBackoffFactor,mMinDelay,mMaxDelay); + } + // Honor server Retry-After header. + // Status 503 may ask us to wait for a certain amount of time before retrying. + F32 wait_time = mDelay; + if (has_retry_header_time) + { + wait_time = retry_header_time; + } + + if (mRetryCount>=mMaxRetries) + { + LL_INFOS() << "Too many retries " << mRetryCount << ", will not retry" << LL_ENDL; + mShouldRetry = false; + } + if (!mRetryOn4xx && !isHttpServerErrorStatus(status)) + { + LL_INFOS() << "Non-server error " << status << ", will not retry" << LL_ENDL; + mShouldRetry = false; + } + if (mShouldRetry) + { + LL_INFOS() << "Retry count " << mRetryCount << " should retry after " << wait_time << LL_ENDL; + mRetryTimer.reset(); + mRetryTimer.setTimerExpirySec(wait_time); + } + mRetryCount++; } - + bool LLAdaptiveRetryPolicy::shouldRetry(F32& seconds_to_wait) const { - if (mRetryCount == 0) - { - // Called shouldRetry before any failure. - seconds_to_wait = F32_MAX; - return false; - } - seconds_to_wait = mShouldRetry ? (F32) mRetryTimer.getRemainingTimeF32() : F32_MAX; - return mShouldRetry; + if (mRetryCount == 0) + { + // Called shouldRetry before any failure. + seconds_to_wait = F32_MAX; + return false; + } + seconds_to_wait = mShouldRetry ? (F32) mRetryTimer.getRemainingTimeF32() : F32_MAX; + return mShouldRetry; } // Moved from httpconstants. Only used by this file. |