You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden ============================ MAJOR FEATURES & CHANGES ============================ Change 3661955 by Rob.Cannaday Change access pattern to FHttpThread to remove critical section #http #ue4 Change 3672463 by Rob.Cannaday Revert Curl/WinINet HTTP implementation of GetHeader/GetAllHeaders to not allowing access until the request is complete Some optimizations to Curl/WinINet GetAllHeaders Add bIsAsyncProcessingFinished to FHttpResponseWinInet, set when the request is finished on the HTTP thread, and only set bIsReady when we have finished processing all received headers Use FThreadSafeBool instead of volatile int32 in WinINet HTTP Change 3855724 by Michael.Kirzinger Fix include paths Change 3949903 by Ian.Fox #OnlineSubsystemSteam - Add IsValid check to SteamSessionInfo to fix a rare crash - Misc cleanup / casting fixes #github #4532 Change 3949914 by Ian.Fox #ShooterGame - Wait for session creation to finish before cleaning up session on network errors #review-3831601 Change 3662317 by Rob.Cannaday Add delegate for when we receive an http header Add FHttpRequestImpl to implement simple virtual functions that all platforms implement in the same way Add lock access to Curl/WinInet response headers access so game thread can safely read while processing #jira OGS-832 #jira OGS-833 #http #ue4 #rb none [CL 4040611 by James Hopkin in Main branch]
191 lines
7.6 KiB
C++
191 lines
7.6 KiB
C++
// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Interfaces/IHttpRequest.h"
|
|
#include "HttpRequestAdapter.h"
|
|
|
|
/**
|
|
* Helpers of various types for the retry system
|
|
*/
|
|
namespace FHttpRetrySystem
|
|
{
|
|
typedef uint32 RetryLimitCountType;
|
|
typedef double RetryTimeoutRelativeSecondsType;
|
|
|
|
inline RetryLimitCountType RetryLimitCount(uint32 Value) { return Value; }
|
|
inline RetryTimeoutRelativeSecondsType RetryTimeoutRelativeSeconds(double Value) { return Value; }
|
|
|
|
template <typename IntrinsicType>
|
|
IntrinsicType TZero();
|
|
|
|
template <> inline float TZero<float>() { return 0.0f; }
|
|
template <> inline RetryLimitCountType TZero<RetryLimitCountType>() { return RetryLimitCount(0); }
|
|
template <> inline RetryTimeoutRelativeSecondsType TZero<RetryTimeoutRelativeSecondsType>() { return RetryTimeoutRelativeSeconds(0.0); }
|
|
|
|
/**
|
|
* TOptionalSetting merges a bool and an intrinsic value to remove the need
|
|
* for having special values to indicate if the option is valid
|
|
*/
|
|
template <typename IntrinsicType>
|
|
struct TOptionalSetting
|
|
{
|
|
TOptionalSetting() : bUseValue(false), Value(TZero<IntrinsicType>()) {}
|
|
explicit TOptionalSetting(IntrinsicType InValue) : bUseValue(true), Value(InValue) {}
|
|
TOptionalSetting(const TOptionalSetting& InValue) : bUseValue(InValue.bUseValue), Value(InValue.Value) {}
|
|
|
|
static TOptionalSetting Unused() { return TOptionalSetting(); }
|
|
static TOptionalSetting Create(IntrinsicType InValue) { return TOptionalSetting(InValue); }
|
|
|
|
bool bUseValue;
|
|
IntrinsicType Value;
|
|
};
|
|
|
|
typedef TOptionalSetting<float> FRandomFailureRateSetting;
|
|
typedef TOptionalSetting<RetryLimitCountType> FRetryLimitCountSetting;
|
|
typedef TOptionalSetting<RetryTimeoutRelativeSecondsType> FRetryTimeoutRelativeSecondsSetting;
|
|
typedef TSet<int32> FRetryResponseCodes;
|
|
typedef TSet<FName> FRetryVerbs;
|
|
};
|
|
|
|
/**
|
|
* Delegate called when an Http request will be retried in the future
|
|
*
|
|
* @param first parameter - original Http request that started things
|
|
* @param second parameter - response received from the server if a successful connection was established
|
|
* @param third parameter - seconds in the future when the response will be retried
|
|
*/
|
|
DECLARE_DELEGATE_ThreeParams(FHttpRequestWillRetryDelegate, FHttpRequestPtr, FHttpResponsePtr, float);
|
|
|
|
namespace FHttpRetrySystem
|
|
{
|
|
/**
|
|
* class FRequest is what the retry system accepts as inputs
|
|
*/
|
|
class FRequest
|
|
: public FHttpRequestAdapterBase
|
|
{
|
|
public:
|
|
struct EStatus
|
|
{
|
|
enum Type
|
|
{
|
|
NotStarted = 0,
|
|
Processing,
|
|
ProcessingLockout,
|
|
Cancelled,
|
|
FailedRetry,
|
|
FailedTimeout,
|
|
Succeeded
|
|
};
|
|
};
|
|
|
|
public:
|
|
// IHttpRequest interface
|
|
HTTP_API virtual bool ProcessRequest() override;
|
|
HTTP_API virtual void CancelRequest() override;
|
|
virtual FHttpRequestWillRetryDelegate& OnRequestWillRetry() { return OnRequestWillRetryDelegate; }
|
|
|
|
// FRequest
|
|
EStatus::Type GetRetryStatus() const { return Status; }
|
|
|
|
protected:
|
|
friend class FManager;
|
|
|
|
HTTP_API FRequest(
|
|
class FManager& InManager,
|
|
const TSharedRef<IHttpRequest>& HttpRequest,
|
|
const FRetryLimitCountSetting& InRetryLimitCountOverride = FRetryLimitCountSetting::Unused(),
|
|
const FRetryTimeoutRelativeSecondsSetting& InRetryTimeoutRelativeSecondsOverride = FRetryTimeoutRelativeSecondsSetting::Unused(),
|
|
const FRetryResponseCodes& InRetryResponseCodes = FRetryResponseCodes(),
|
|
const FRetryVerbs& InRetryVerbs = FRetryVerbs()
|
|
);
|
|
|
|
void HttpOnRequestProgress(FHttpRequestPtr InHttpRequest, int32 BytesSent, int32 BytesRcv);
|
|
|
|
EStatus::Type Status;
|
|
|
|
FRetryLimitCountSetting RetryLimitCountOverride;
|
|
FRetryTimeoutRelativeSecondsSetting RetryTimeoutRelativeSecondsOverride;
|
|
FRetryResponseCodes RetryResponseCodes;
|
|
FRetryVerbs RetryVerbs;
|
|
|
|
FHttpRequestWillRetryDelegate OnRequestWillRetryDelegate;
|
|
|
|
FManager& RetryManager;
|
|
};
|
|
}
|
|
|
|
namespace FHttpRetrySystem
|
|
{
|
|
class FManager
|
|
{
|
|
public:
|
|
// FManager
|
|
HTTP_API FManager(const FRetryLimitCountSetting& InRetryLimitCountDefault, const FRetryTimeoutRelativeSecondsSetting& InRetryTimeoutRelativeSecondsDefault);
|
|
|
|
/**
|
|
* Create a new http request with retries
|
|
*/
|
|
HTTP_API TSharedRef<class FHttpRetrySystem::FRequest> CreateRequest(
|
|
const FRetryLimitCountSetting& InRetryLimitCountOverride = FRetryLimitCountSetting::Unused(),
|
|
const FRetryTimeoutRelativeSecondsSetting& InRetryTimeoutRelativeSecondsOverride = FRetryTimeoutRelativeSecondsSetting::Unused(),
|
|
const FRetryResponseCodes& InRetryResponseCodes = FRetryResponseCodes(),
|
|
const FRetryVerbs& InRetryVerbs = FRetryVerbs()
|
|
);
|
|
|
|
|
|
/**
|
|
* Updates the entries in the list of retry requests. Optional parameters are for future connection health assessment
|
|
*
|
|
* @param FileCount optional parameter that will be filled with the total files updated
|
|
* @param FailingCount optional parameter that will be filled with the total files that have are in a retrying state
|
|
* @param FailedCount optional parameter that will be filled with the total files that have failed
|
|
* @param CompletedCount optional parameter that will be filled with the total files that have completed
|
|
*
|
|
* @return true if there are no failures or retries
|
|
*/
|
|
HTTP_API bool Update(uint32* FileCount = NULL, uint32* FailingCount = NULL, uint32* FailedCount = NULL, uint32* CompletedCount = NULL);
|
|
HTTP_API void SetRandomFailureRate(float Value) { RandomFailureRate = FRandomFailureRateSetting::Create(Value); }
|
|
|
|
protected:
|
|
friend class FRequest;
|
|
|
|
struct FHttpRetryRequestEntry
|
|
{
|
|
FHttpRetryRequestEntry(TSharedRef<FRequest>& InRequest);
|
|
|
|
bool bShouldCancel;
|
|
uint32 CurrentRetryCount;
|
|
double RequestStartTimeAbsoluteSeconds;
|
|
double LockoutEndTimeAbsoluteSeconds;
|
|
|
|
TSharedRef<FRequest> Request;
|
|
};
|
|
|
|
bool ProcessRequest(TSharedRef<FRequest>& HttpRequest);
|
|
void CancelRequest(TSharedRef<FRequest>& HttpRequest);
|
|
|
|
// @return true if there is a no formal response to the request
|
|
// @TODO return true if a variety of 5xx errors are the result of a formal response
|
|
bool ShouldRetry(const FHttpRetryRequestEntry& HttpRetryRequestEntry);
|
|
|
|
// @return true if retry chances have not been exhausted
|
|
bool CanRetry(const FHttpRetryRequestEntry& HttpRetryRequestEntry);
|
|
|
|
// @return true if the retry request has timed out
|
|
bool HasTimedOut(const FHttpRetryRequestEntry& HttpRetryRequestEntry, const double NowAbsoluteSeconds);
|
|
|
|
// @return number of seconds to lockout for
|
|
float GetLockoutPeriodSeconds(const FHttpRetryRequestEntry& HttpRetryRequestEntry);
|
|
|
|
// Default configuration for the retry system
|
|
FRandomFailureRateSetting RandomFailureRate;
|
|
FRetryLimitCountSetting RetryLimitCountDefault;
|
|
FRetryTimeoutRelativeSecondsSetting RetryTimeoutRelativeSecondsDefault;
|
|
|
|
TArray<FHttpRetryRequestEntry> RequestList;
|
|
};
|
|
}
|