Fixes disconnect, and publishing to windows. (#114)
This commit is contained in:
parent
cffb32d6ef
commit
63bf71ea47
6 changed files with 72 additions and 56 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue