You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rb none #rnx #ushell-unshelve of 11071762 [CL 11071846 by Martin Ridgers in Dev-Core branch]
104 lines
2.0 KiB
C++
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
|