Browse Source

updated fleck

master
notgiven688 3 months ago
parent
commit
f5c233b45b
3 changed files with 39 additions and 31 deletions
  1. +16
    -7
      server/Server/Fleck/Helpers/FleckRuntime.cs
  2. +12
    -10
      server/Server/Fleck/SocketWrapper.cs
  3. +11
    -14
      server/Server/Fleck/WebSocketServer.cs

server/Server/Fleck/Helpers/MonoHelper.cs → server/Server/Fleck/Helpers/FleckRuntime.cs View File

@ -22,15 +22,24 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
namespace Fleck.Helpers
{
public static class MonoHelper
{
public static bool IsRunningOnMono ()
internal static class FleckRuntime
{
return Type.GetType ("Mono.Runtime") != null;
public static bool IsRunningOnMono()
{
return Type.GetType("Mono.Runtime") != null;
}
public static bool IsRunningOnWindows()
{
#if NET45 || NET40
return true;
#else
return (RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
#endif
}
}
}
}
}

+ 12
- 10
server/Server/Fleck/SocketWrapper.cs View File

@ -31,6 +31,7 @@ using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.InteropServices;
using Fleck.Helpers;
namespace Fleck
{
@ -42,16 +43,17 @@ namespace Fleck
public static void SetKeepAlive(this Socket socket, UInt32 keepAliveInterval, UInt32 retryInterval)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return;
int size = sizeof(UInt32);
UInt32 on = 1;
byte[] inArray = new byte[size * 3];
Array.Copy(BitConverter.GetBytes(on), 0, inArray, 0, size);
Array.Copy(BitConverter.GetBytes(keepAliveInterval), 0, inArray, size, size);
Array.Copy(BitConverter.GetBytes(retryInterval), 0, inArray, size * 2, size);
socket.IOControl(IOControlCode.KeepAliveValues, inArray, null);
if (FleckRuntime.IsRunningOnWindows())
{
int size = sizeof(UInt32);
UInt32 on = 1;
byte[] inArray = new byte[size * 3];
Array.Copy(BitConverter.GetBytes(on), 0, inArray, 0, size);
Array.Copy(BitConverter.GetBytes(keepAliveInterval), 0, inArray, size, size);
Array.Copy(BitConverter.GetBytes(retryInterval), 0, inArray, size * 2, size);
socket.IOControl(IOControlCode.KeepAliveValues, inArray, null);
}
}
}

+ 11
- 14
server/Server/Fleck/WebSocketServer.cs View File

@ -60,38 +60,35 @@ namespace Fleck
public WebSocketServer(string location)
public WebSocketServer(string location, bool supportDualStack = true)
{
var uri = new Uri(location);
Port = uri.Port;
Location = location;
SupportDualStack = supportDualStack;
_locationIP = ParseIPAddress(uri);
_scheme = uri.Scheme;
var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);
if (!MonoHelper.IsRunningOnMono())
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
if (SupportDualStack)
{
#if __MonoCS__
#else
#if !NET45
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
if (!FleckRuntime.IsRunningOnMono() && FleckRuntime.IsRunningOnWindows())
{
socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
}
#if !NET45
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
}
#endif
#endif
}
ListenerSocket = new SocketWrapper(socket);
SupportedSubProtocols = new string[0];
}
public ISocket ListenerSocket { get; set; }
public string Location { get; private set; }
public bool SupportDualStack { get; }
public int Port { get; private set; }
public X509Certificate2 Certificate { get; set; }
public SslProtocols EnabledSslProtocols { get; set; }

Loading…
Cancel
Save