Files
UnrealEngineUWP/Engine/Source/Runtime/Sockets/Private/IPAddress.cpp
ryan durand 0f0464a30e Updating copyright for Engine Runtime.
#rnx
#rb none


#ROBOMERGE-OWNER: ryan.durand
#ROBOMERGE-AUTHOR: ryan.durand
#ROBOMERGE-SOURCE: CL 10869210 via CL 10869511 via CL 10869900
#ROBOMERGE-BOT: (v613-10869866)

[CL 10870549 by ryan durand in Main branch]
2019-12-26 14:45:42 -05:00

72 lines
1.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "IPAddress.h"
#include "SocketSubsystem.h"
#include "AddressInfoTypes.h"
/**
* Sets the address to return to the caller
*
* @param InAddr the address that is being cached
*/
FResolveInfoCached::FResolveInfoCached(const FInternetAddr& InAddr)
{
Addr = InAddr.Clone();
}
/**
* Copies the host name for async resolution
*
* @param InHostName the host name to resolve
*/
FResolveInfoAsync::FResolveInfoAsync(const ANSICHAR* InHostName) :
ErrorCode(SE_NO_ERROR),
bShouldAbandon(false),
AsyncTask(this)
{
FCStringAnsi::Strncpy(HostName,InHostName,256);
}
/**
* Resolves the specified host name
*/
void FResolveInfoAsync::DoWork()
{
int32 AttemptCount = 0;
ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get();
// Make up to 3 attempts to resolve it
do
{
FAddressInfoResult GAIResults = SocketSubsystem->GetAddressInfo(ANSI_TO_TCHAR(HostName), nullptr, EAddressInfoFlags::Default, NAME_None);
ErrorCode = GAIResults.ReturnCode;
if (ErrorCode != SE_NO_ERROR)
{
if (ErrorCode == SE_HOST_NOT_FOUND || ErrorCode == SE_NO_DATA || ErrorCode == SE_ETIMEDOUT)
{
// Force a failure
AttemptCount = 3;
}
}
else if(GAIResults.Results.Num() > 0)
{
// Pull out the address
Addr = GAIResults.Results[0].Address;
// Cache for reuse
SocketSubsystem->AddHostNameToCache(HostName, Addr);
return;
}
else
{
ErrorCode = SE_NO_DATA;
}
AttemptCount++;
}
while (ErrorCode != SE_NO_ERROR && AttemptCount < 3 && bShouldAbandon == false);
}