Files
UnrealEngineUWP/Engine/Source/Developer/TraceAnalysis/Private/Store/AsioTraceRelay.cpp
Martin Ridgers 0ba09babde Always consider a trace live for now while store services are self-hosted.
#rb none
#rnx
#ushell-unshelve of 11071762

[CL 11071846 by Martin Ridgers in Dev-Core branch]
2020-01-21 09:26:45 -05:00

104 lines
2.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "AsioTraceRelay.h"
#if TRACE_WITH_ASIO
#include "AsioRecorder.h"
#include "AsioSocket.h"
namespace Trace
{
////////////////////////////////////////////////////////////////////////////////
FAsioTraceRelay::FAsioTraceRelay(
asio::io_context& IoContext,
FAsioReadable* InInput,
uint32 InSessionId,
FAsioRecorder& InRecorder)
: FAsioTcpServer(IoContext)
, Input(InInput)
, Recorder(InRecorder)
, SessionId(InSessionId)
{
StartServer();
}
////////////////////////////////////////////////////////////////////////////////
FAsioTraceRelay::~FAsioTraceRelay()
{
if (Output != nullptr)
{
delete Output;
}
delete Input;
}
////////////////////////////////////////////////////////////////////////////////
void FAsioTraceRelay::Close()
{
if (Output != nullptr)
{
Output->Close();
}
Input->Close();
}
////////////////////////////////////////////////////////////////////////////////
bool FAsioTraceRelay::OnAccept(asio::ip::tcp::socket& Socket)
{
Output = new FAsioSocket(Socket);
OnIoComplete(OpStart, 0);
return false;
}
////////////////////////////////////////////////////////////////////////////////
void FAsioTraceRelay::OnIoComplete(uint32 Id, int32 Size)
{
if (Size < 0)
{
#if !defined(TRACE_WITH_ASIO)
if (Id == OpRead && SessionId)
{
for (int i = 0, n = Recorder.GetSessionCount(); i < n; ++i)
{
const FAsioRecorder::FSession* Session = Recorder.GetSessionInfo(i);
if (Session->GetId() == SessionId)
{
FPlatformProcess::SleepNoStats(0.2f);
return OnIoComplete(OpStart, 0);
}
}
}
Output->Close();
Input->Close();
return;
#else
if (Id == OpRead)
{
FPlatformProcess::SleepNoStats(0.2f);
OnIoComplete(OpStart, 0);
}
return;
#endif
}
switch (Id)
{
case OpStart:
case OpSend:
Input->Read(Buffer, BufferSize, this, OpRead);
break;
case OpRead:
Output->Write(Buffer, Size, this, OpSend);
break;
}
}
} // namespace Trace
#endif // TRACE_WITH_ASIO