Remove Init & Exit, logic is now in Win32Platform.cpp.

This commit is contained in:
Jean-Baptiste Perrier
2021-01-26 15:55:51 +01:00
parent 54b9eaa969
commit c20f0fa430
5 changed files with 18 additions and 39 deletions

View File

@@ -2,15 +2,6 @@
#include "NetworkBase.h"
bool NetworkBase::Init()
{
return true;
}
void NetworkBase::Exit()
{
}
bool NetworkBase::CreateSocket(NetworkSocket& socket, NetworkProtocolType proto, NetworkIPVersion ipv)
{
return true;

View File

@@ -74,17 +74,6 @@ struct FLAXENGINE_API NetworkSocketGroup
class FLAXENGINE_API NetworkBase
{
public:
/// <summary>
/// Initializes the network module.
/// </summary>
/// <returns>Return true on error. Otherwise false.</returns>
static bool Init();
/// <summary>
/// Deinitializes the network module.
/// </summary>
static void Exit();
/// <summary>
/// Creates a new native socket.
/// </summary>

View File

@@ -14,7 +14,6 @@ static_assert(sizeof NetworkEndPoint::Data >= sizeof sockaddr_in6, "NetworkEndPo
static const IN6_ADDR v4MappedPrefix = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } };
static WSAData _wsaData;
/*
* Known issues :
@@ -136,18 +135,6 @@ static void TranslateSockOptToNative(NetworkSocketOption option, int32* level, i
}
}
bool Win32Network::Init()
{
if (WSAStartup(MAKEWORD(2, 0), &_wsaData) != 0)
return true;
return false;
}
void Win32Network::Exit()
{
WSACleanup();
}
bool Win32Network::CreateSocket(NetworkSocket& socket, NetworkProtocolType proto, NetworkIPVersion ipv)
{
socket.Protocol = proto;

View File

@@ -13,8 +13,6 @@ class FLAXENGINE_API Win32Network : public NetworkBase
public:
// [NetworkBase]
static bool Init();
static void Exit();
static bool CreateSocket(NetworkSocket& socket, NetworkProtocolType proto, NetworkIPVersion ipv);
static bool DestroySocket(NetworkSocket& socket);
static bool SetSocketOption(NetworkSocket& socket, NetworkSocketOption option, bool value);

View File

@@ -12,6 +12,7 @@
#include "IncludeWindowsHeaders.h"
#include "Engine/Core/Collections/HashFunctions.h"
#include "Engine/Platform/Network.h"
#include "Engine/Core/Log.h"
#include <Psapi.h>
#include <WinSock2.h>
@@ -28,6 +29,8 @@ namespace
double CyclesToSeconds;
}
static WSAData _wsaData;
// Helper function to count set bits in the processor mask
DWORD CountSetBits(ULONG_PTR bitMask)
{
@@ -45,6 +48,18 @@ DWORD CountSetBits(ULONG_PTR bitMask)
return bitSetCount;
}
static String GetLastErrorMessage()
{
wchar_t* s = nullptr;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, WSAGetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&s), 0, nullptr);
String str(s);
LocalFree(s);
return str;
}
bool Win32Platform::Init()
{
if (PlatformBase::Init())
@@ -213,15 +228,14 @@ bool Win32Platform::Init()
DeviceId.D = (uint32)cpuInfo.ClockSpeed * cpuInfo.LogicalProcessorCount * cpuInfo.ProcessorCoreCount * cpuInfo.CacheLineSize;
}
//TODO: log error if true
Win32Network::Init();
if (WSAStartup(MAKEWORD(2, 0), &_wsaData) != 0)
LOG(Error, "Unable to initializes native network! Error : {0}", GetLastErrorMessage().Get());
return false;
}
void Win32Platform::Exit()
{
Network::Exit();
WSACleanup();
}
void Win32Platform::MemoryBarrier()