diff --git a/Source/Engine/Platform/Base/NetworkBase.cpp b/Source/Engine/Platform/Base/NetworkBase.cpp
index ab05a4c06..6a83cd9f6 100644
--- a/Source/Engine/Platform/Base/NetworkBase.cpp
+++ b/Source/Engine/Platform/Base/NetworkBase.cpp
@@ -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;
diff --git a/Source/Engine/Platform/Base/NetworkBase.h b/Source/Engine/Platform/Base/NetworkBase.h
index 805ca246e..e5c816b77 100644
--- a/Source/Engine/Platform/Base/NetworkBase.h
+++ b/Source/Engine/Platform/Base/NetworkBase.h
@@ -74,17 +74,6 @@ struct FLAXENGINE_API NetworkSocketGroup
class FLAXENGINE_API NetworkBase
{
public:
- ///
- /// Initializes the network module.
- ///
- /// Return true on error. Otherwise false.
- static bool Init();
-
- ///
- /// Deinitializes the network module.
- ///
- static void Exit();
-
///
/// Creates a new native socket.
///
diff --git a/Source/Engine/Platform/Win32/Win32Network.cpp b/Source/Engine/Platform/Win32/Win32Network.cpp
index a25a8653a..3783cd879 100644
--- a/Source/Engine/Platform/Win32/Win32Network.cpp
+++ b/Source/Engine/Platform/Win32/Win32Network.cpp
@@ -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;
diff --git a/Source/Engine/Platform/Win32/Win32Network.h b/Source/Engine/Platform/Win32/Win32Network.h
index 8700d9f19..b0e313056 100644
--- a/Source/Engine/Platform/Win32/Win32Network.h
+++ b/Source/Engine/Platform/Win32/Win32Network.h
@@ -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);
diff --git a/Source/Engine/Platform/Win32/Win32Platform.cpp b/Source/Engine/Platform/Win32/Win32Platform.cpp
index db6151a17..f74485748 100644
--- a/Source/Engine/Platform/Win32/Win32Platform.cpp
+++ b/Source/Engine/Platform/Win32/Win32Platform.cpp
@@ -12,6 +12,7 @@
#include "IncludeWindowsHeaders.h"
#include "Engine/Core/Collections/HashFunctions.h"
#include "Engine/Platform/Network.h"
+#include "Engine/Core/Log.h"
#include
#include
@@ -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(&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()