-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixing nanosockets build error on some platforms
Removing support for nanosockets for platforms other than Windows and Linux. nanosockets is mostly for increasing performance for high CCU servers, which should mostly be Windows and Linux. Adding optional define to force disable nanosockets EXCLUDE_NANOSOCKETS Can be used when compiling fails because of nanosockets functions
- Loading branch information
1 parent
c9469a2
commit fbd136c
Showing
8 changed files
with
130 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// windows, linux or standalone c#, unless EXCLUDE_NANOSOCKETS is defined | ||
#if !EXCLUDE_NANOSOCKETS && (UNITY_EDITOR_WIN || UNITY_EDITOR_LINUX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || NETCOREAPP || NET_5_0_OR_GREATER) | ||
using NanoSockets; | ||
using UnityEngine; | ||
|
||
namespace Mirage.Sockets.Udp | ||
{ | ||
public static class InitUDP | ||
{ | ||
private static int initCount; | ||
|
||
/// <summary> | ||
/// Initializes the NanoSockets native library. If it fails, it resorts to C# Managed Sockets. | ||
/// </summary> | ||
public static void Init() | ||
{ | ||
if (initCount == 0) | ||
{ | ||
var status = UDP.Initialize(); | ||
if (status == Status.Error) | ||
Debug.LogError("Error calling UDP.Initialize"); | ||
} | ||
|
||
initCount++; | ||
} | ||
|
||
public static void Deinit() | ||
{ | ||
initCount--; | ||
|
||
if (initCount == 0) UDP.Deinitialize(); | ||
} | ||
|
||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] | ||
private static void ClearCounter() | ||
{ | ||
// todo do we need to call Deinitialize here? | ||
initCount = 0; | ||
} | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Assets/Mirage/Runtime/Sockets/Udp/NanoSocket_NotSupported.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// windows or linux, unless EXCLUDE_NANOSOCKETS is defined | ||
#if EXCLUDE_NANOSOCKETS || !(UNITY_EDITOR_WIN || UNITY_EDITOR_LINUX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || NETCOREAPP || NET_5_0_OR_GREATER) | ||
// these classes are copies of the real classes but throw NotSupported | ||
// this is needed so that NanoSocket scripts can be excluded from builds because this breaks on some targets | ||
using System; | ||
using Mirage.SocketLayer; | ||
|
||
namespace Mirage.Sockets.Udp | ||
{ | ||
public static class InitUDP | ||
{ | ||
public static void Init() => throw new NotSupportedException(); | ||
public static void Deinit() => throw new NotSupportedException(); | ||
} | ||
public sealed class NanoSocket : ISocket | ||
{ | ||
public static bool Supported => false; | ||
|
||
public NanoSocket(UdpSocketFactory factory) => throw new NotSupportedException(); | ||
public void Bind(IEndPoint endPoint) => throw new NotSupportedException(); | ||
public void Connect(IEndPoint endPoint) => throw new NotSupportedException(); | ||
public void Close() => throw new NotSupportedException(); | ||
public bool Poll() => throw new NotSupportedException(); | ||
public int Receive(byte[] buffer, out IEndPoint endPoint) => throw new NotSupportedException(); | ||
public void Send(IEndPoint endPoint, byte[] packet, int length) => throw new NotSupportedException(); | ||
} | ||
public sealed class NanoEndPoint : IEndPoint | ||
{ | ||
public NanoEndPoint(string host, ushort port) => throw new NotSupportedException(); | ||
public IEndPoint CreateCopy() => throw new NotSupportedException(); | ||
} | ||
} | ||
#endif |
11 changes: 11 additions & 0 deletions
11
Assets/Mirage/Runtime/Sockets/Udp/NanoSocket_NotSupported.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters