Fixes disconnect, and publishing to windows. (#114)

This commit is contained in:
Kamron Batman 2020-04-26 01:43:53 -07:00 committed by GitHub
parent cffb32d6ef
commit 63bf71ea47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 56 deletions

View file

@ -20,6 +20,7 @@
*************************************************************************/
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
using Microsoft.Extensions.Logging;
@ -49,47 +50,9 @@ namespace Server.Network
var ns = new NetState(connection);
TcpServer.Instances.Add(ns);
_logger.LogInformation($"Client: {ns}: Connected. [{TcpServer.Instances.Count} Online]");
Console.WriteLine($"Client: {ns}: Connected. [{TcpServer.Instances.Count} Online]");
connection.ConnectionClosed.Register(() => { TcpServer.Instances.Remove(ns); });
await ProcessIncoming(ns).ConfigureAwait(false);
}
private async Task ProcessIncoming(NetState ns)
{
var inPipe = ns.Connection.Transport.Input;
while (true)
{
if (NetState.AsyncState.Paused)
continue;
try
{
var result = await inPipe.ReadAsync();
if (result.IsCanceled || result.IsCompleted)
return;
var seq = result.Buffer;
if (seq.IsEmpty)
break;
var pos = PacketHandlers.ProcessPacket(_messagePumpService, ns, seq);
if (pos <= 0)
break;
inPipe.AdvanceTo(seq.Slice(0, pos).End);
}
catch
{
// ignored
}
}
inPipe.Complete();
await ns.ProcessIncoming(_messagePumpService).ConfigureAwait(false);
}
private static bool VerifySocket(ConnectionContext connection)