Browse Source

perf improvement in Hybi13

pull/123/head
notgiven688 2 years ago
parent
commit
3068ec7586
2 changed files with 30 additions and 12 deletions
  1. +14
    -8
      server/Server/Fleck/Handlers/Hybi13Handler.cs
  2. +16
    -4
      server/Server/Fleck/WebSocketServer.cs

+ 14
- 8
server/Server/Fleck/Handlers/Hybi13Handler.cs View File

@ -121,14 +121,20 @@ namespace Fleck.Handlers
if (data.Count < index + payloadLength)
return; //Not complete
var payload = data
.Skip(index)
.Take(payloadLength)
.Select((x, i) => (byte)(x ^ maskBytes[i % 4]));
readState.Data.AddRange(payload);
byte[] playloadData = new byte[payloadLength];
for (int i = 0; i < payloadLength; i++)
playloadData[i] = (byte)(data[index+i] ^ maskBytes[i % 4]);
//var payload = data
// .Skip(index)
// .Take(payloadLength)
// .Select((x, i) => (byte)(x ^ maskBytes[i % 4]));
//readState.Data.AddRange(payload);
readState.Data.AddRange(playloadData);
data.RemoveRange(0, index + payloadLength);
if (frameType != FrameType.Continuation)

+ 16
- 4
server/Server/Fleck/WebSocketServer.cs View File

@ -68,11 +68,23 @@ namespace Fleck
_locationIP = ParseIPAddress(uri);
_scheme = uri.Scheme;
var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);
if(!MonoHelper.IsRunningOnMono()){
#if __MonoCS__
#else
if (!MonoHelper.IsRunningOnMono())
{
#if __MonoCS__
#else
#if !NET45
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
{
socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
#endif
}
#if !NET45
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
}
#endif
#endif
}
ListenerSocket = new SocketWrapper(socket);
SupportedSubProtocols = new string[0];

Loading…
Cancel
Save