From 4127f8ce4b0eea0ee14113e1f0cf8773c8481854 Mon Sep 17 00:00:00 2001 From: andrew1481432 Date: Sun, 21 Jul 2024 00:15:51 +0300 Subject: [PATCH 1/3] fix: startup server on MACOS --- src/MiNET/MiNET.Console/Startup.cs | 20 ++++++++++++++------ src/MiNET/MiNET/Net/RakNet/RakConnection.cs | 13 +++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/MiNET/MiNET.Console/Startup.cs b/src/MiNET/MiNET.Console/Startup.cs index 3b27caab2..948bef433 100644 --- a/src/MiNET/MiNET.Console/Startup.cs +++ b/src/MiNET/MiNET.Console/Startup.cs @@ -23,12 +23,12 @@ #endregion -using System; using System.Diagnostics; using System.IO; using System.Net; using System.Net.Sockets; using System.Reflection; +using System.Runtime.InteropServices; using System.Threading; using log4net; using log4net.Config; @@ -61,12 +61,15 @@ static void Main(string[] args) Log.Info(MiNetServer.MiNET); System.Console.WriteLine(MiNetServer.MiNET); - var currentProcess = Process.GetCurrentProcess(); - - var processorAffinity = Config.GetProperty("ProcessorAffinity", -1); - if (processorAffinity != -1) + if (IsSupportSystem()) { - currentProcess.ProcessorAffinity = processorAffinity; + var currentProcess = Process.GetCurrentProcess(); + + var processorAffinity = Config.GetProperty("ProcessorAffinity", -1); + if (processorAffinity != -1) + { + currentProcess.ProcessorAffinity = processorAffinity; + } } var service = new MiNetServer(); @@ -84,5 +87,10 @@ static void Main(string[] args) System.Console.ReadLine(); service.StopServer(); } + + private static bool IsSupportSystem() + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + } } } \ No newline at end of file diff --git a/src/MiNET/MiNET/Net/RakNet/RakConnection.cs b/src/MiNET/MiNET/Net/RakNet/RakConnection.cs index 81a15d83a..ce74d9a23 100644 --- a/src/MiNET/MiNET/Net/RakNet/RakConnection.cs +++ b/src/MiNET/MiNET/Net/RakNet/RakConnection.cs @@ -31,6 +31,7 @@ using System.Net; using System.Net.Sockets; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using log4net; @@ -203,16 +204,16 @@ public void Stop() private static UdpClient CreateListener(IPEndPoint endpoint) { var listener = new UdpClient(); - - if (Environment.OSVersion.Platform != PlatformID.MacOSX) + + if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - //_listener.Client.ReceiveBufferSize = 1600*40000; listener.Client.ReceiveBufferSize = int.MaxValue; - //_listener.Client.SendBufferSize = 1600*40000; listener.Client.SendBufferSize = int.MaxValue; + + listener.DontFragment = false; } - - listener.DontFragment = false; + + //listener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 500); listener.EnableBroadcast = true; if (Environment.OSVersion.Platform != PlatformID.Unix && Environment.OSVersion.Platform != PlatformID.MacOSX) From 5ae7bef7f54cda15fe22db09f6d53661ffd8fa65 Mon Sep 17 00:00:00 2001 From: andrew1481432 Date: Sun, 21 Jul 2024 00:20:34 +0300 Subject: [PATCH 2/3] fix --- src/MiNET/MiNET.Console/Startup.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/MiNET/MiNET.Console/Startup.cs b/src/MiNET/MiNET.Console/Startup.cs index 948bef433..b89ec65bc 100644 --- a/src/MiNET/MiNET.Console/Startup.cs +++ b/src/MiNET/MiNET.Console/Startup.cs @@ -61,7 +61,7 @@ static void Main(string[] args) Log.Info(MiNetServer.MiNET); System.Console.WriteLine(MiNetServer.MiNET); - if (IsSupportSystem()) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { var currentProcess = Process.GetCurrentProcess(); @@ -87,10 +87,5 @@ static void Main(string[] args) System.Console.ReadLine(); service.StopServer(); } - - private static bool IsSupportSystem() - { - return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - } } } \ No newline at end of file From a5be632d74149af9d2920af7543af47ee7d873f8 Mon Sep 17 00:00:00 2001 From: andrew1481432 Date: Wed, 23 Oct 2024 18:03:34 +0300 Subject: [PATCH 3/3] Format code fixed --- src/MiNET/MiNET/Net/RakNet/RakConnection.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/MiNET/MiNET/Net/RakNet/RakConnection.cs b/src/MiNET/MiNET/Net/RakNet/RakConnection.cs index ce74d9a23..25cf08fa6 100644 --- a/src/MiNET/MiNET/Net/RakNet/RakConnection.cs +++ b/src/MiNET/MiNET/Net/RakNet/RakConnection.cs @@ -204,7 +204,7 @@ public void Stop() private static UdpClient CreateListener(IPEndPoint endpoint) { var listener = new UdpClient(); - + if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { listener.Client.ReceiveBufferSize = int.MaxValue; @@ -212,7 +212,6 @@ private static UdpClient CreateListener(IPEndPoint endpoint) listener.DontFragment = false; } - //listener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 500); listener.EnableBroadcast = true;