Files
UnrealEngineUWP/Engine/Source/Runtime/Sockets/Private/HTML5/Simulator/SocketX.cpp
Ben Marsh 4ba423868f Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3209340 on 2016/11/23 by Ben.Marsh

	Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.

	Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.

	  * Every header now includes everything it needs to compile.
	        * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
	        * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
	  * Every .cpp file includes its matching .h file first.
	        * This helps validate that each header is including everything it needs to compile.
	  * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
	        * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
	        * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
	  * No engine code explicitly includes a precompiled header any more.
	        * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
	        * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.

	Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.

[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00

181 lines
4.5 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "SocketX.h"
#include "Sockets/SocketRaw.h"
#include "Sockets/IPAddressRaw.h"
#define ADDTOPIMPL(BasePtr) *((FInternetAddrX*)&BasePtr)->GetPimpl()
bool FSocketX::Close()
{
return Pimpl->Close();
}
bool FSocketX::Bind( const FInternetAddr& Addr )
{
return Pimpl->Bind(ADDTOPIMPL(Addr)) == 0;
}
bool FSocketX::Connect( const FInternetAddr& Addr )
{
int32 Return = Pimpl->Connect(ADDTOPIMPL(Addr));
check(SocketSubsystem);
ESocketErrors Error = SocketSubsystem->TranslateErrorCode(Return);
// "would block" is not an error
return ((Error == SE_NO_ERROR) || (Error == SE_EWOULDBLOCK));
}
bool FSocketX::Listen( int32 MaxBacklog )
{
return Pimpl->Listen(MaxBacklog);
}
bool FSocketX::HasPendingConnection( bool& bHasPendingConnection )
{
return Pimpl->HasPendingConnection(bHasPendingConnection);
}
bool FSocketX::HasPendingData( uint32& PendingDataSize )
{
return Pimpl->HasPendingData(PendingDataSize);
}
class FSocket* FSocketX::Accept( const FString& SocketDescription )
{
FSocketRaw* RawSocket = Pimpl->Accept();
return new FSocketX( RawSocket, SocketType, SocketDescription,SocketSubsystem);
}
class FSocket* FSocketX::Accept( FInternetAddr& OutAddr, const FString& SocketDescription )
{
FSocketRaw* RawSocket = Pimpl->Accept(ADDTOPIMPL(OutAddr));
return new FSocketX( RawSocket, SocketType, SocketDescription,SocketSubsystem);
}
bool FSocketX::SendTo( const uint8* Data, int32 Count, int32& BytesSent, const FInternetAddr& Destination )
{
return Pimpl->SendTo(Data,Count,(unsigned int&)BytesSent, ADDTOPIMPL(Destination));
}
bool FSocketX::Send( const uint8* Data, int32 Count, int32& BytesSent )
{
return Pimpl->Send( Data, Count, (unsigned int&)BytesSent);
}
bool FSocketX::RecvFrom( uint8* Data, int32 BufferSize, int32& BytesRead, FInternetAddr& Source, ESocketReceiveFlags::Type Flags /*= ESocketReceiveFlags::None */ )
{
return Pimpl->RecvFrom( Data, BufferSize, (unsigned int&) BytesRead, ADDTOPIMPL(Source), (int)Flags );
}
bool FSocketX::Recv( uint8* Data, int32 BufferSize, int32& BytesRead, ESocketReceiveFlags::Type Flags /*= ESocketReceiveFlags::None */ )
{
return Pimpl->Recv(Data,BufferSize,(unsigned int&)BytesRead,(int)Flags);
}
bool FSocketX::Wait( ESocketWaitConditions::Type Condition, FTimespan WaitTime )
{
if ((Condition == ESocketWaitConditions::WaitForRead) )
{
return Pimpl->WaitForRead( WaitTime.GetMilliseconds() );
}
if ( Condition == ESocketWaitConditions::WaitForWrite)
{
return Pimpl->WaitForWrite( WaitTime.GetMilliseconds() );
}
return Pimpl->WaitForReadWrite( WaitTime.GetMilliseconds() );
}
ESocketConnectionState FSocketX::GetConnectionState()
{
// @fix-me -
if ( !Pimpl->WaitForReadWrite( 1 ) )
{
return ESocketConnectionState::SCS_ConnectionError;
}
else
{
return ESocketConnectionState::SCS_Connected;
}
}
void FSocketX::GetAddress( FInternetAddr& OutAddr )
{
Pimpl->GetAddress(ADDTOPIMPL(OutAddr) );
}
bool FSocketX::GetPeerAddress( FInternetAddr& OutAddr )
{
Pimpl->GetPeerAddress(ADDTOPIMPL(OutAddr));
}
bool FSocketX::SetNonBlocking( bool bIsNonBlocking /*= true */ )
{
return Pimpl->SetNonBlocking( bIsNonBlocking );
}
bool FSocketX::SetBroadcast( bool bAllowBroadcast /*= true */ )
{
return Pimpl->SetBroadcast( bAllowBroadcast );
}
bool FSocketX::JoinMulticastGroup( const FInternetAddr& GroupAddress )
{
return Pimpl->JoinMulticastGroup( ADDTOPIMPL(GroupAddress) );
}
bool FSocketX::LeaveMulticastGroup( const FInternetAddr& GroupAddress )
{
return Pimpl->LeaveMulticastGroup( ADDTOPIMPL(GroupAddress) );
}
bool FSocketX::SetMulticastLoopback( bool bLoopback )
{
return Pimpl->SetMulticastLoopback(bLoopback);
}
bool FSocketX::SetMulticastTtl( uint8 TimeToLive )
{
return Pimpl->SetMulticastTtl( TimeToLive);
}
bool FSocketX::SetReuseAddr( bool bAllowReuse /*= true */ )
{
return Pimpl->SetReuseAddr( bAllowReuse );
}
bool FSocketX::SetLinger( bool bShouldLinger /*= true*/, int32 Timeout /*= 0 */ )
{
return Pimpl->SetLinger( bShouldLinger, Timeout);
}
bool FSocketX::SetRecvErr( bool bUseErrorQueue /*= true */ )
{
return Pimpl->SetLinger(bUseErrorQueue);
}
bool FSocketX::SetSendBufferSize( int32 Size, int32& NewSize )
{
return Pimpl->SetSendBufferSize( Size, (unsigned int&)NewSize );
}
bool FSocketX::SetReceiveBufferSize( int32 Size, int32& NewSize )
{
return Pimpl->SetReceiveBufferSize( Size, (unsigned int&)NewSize);
}
int32 FSocketX::GetPortNo()
{
bool bOK = false;
int32 PortNo = Pimpl->GetPortNo(bOK);
check ( bOK );
return PortNo;
}
bool FSocketX::IsValid()
{
return Pimpl->IsValid();
}