private async Task openStreamAsync() { var buffer = new byte[TcpBufferSize]; while (!_cancellationToken.IsCancellationRequested) { var timeoutTask = Task.Delay(TimeSpan.FromMilliseconds(TcpReadTimeoutMs)); var amountReadTask = _client.ReadStream.ReadAsync(buffer, 0, buffer.Length, _cancellationToken); var completedTask = await Task.WhenAny(timeoutTask, amountReadTask) .ConfigureAwait(false); if (completedTask == timeoutTask) { _log.LogInfo("Client timed out"); break; } int amountRead = amountReadTask.Result; if (amountRead == 0) { break; } parseCitpPackets(amountRead, buffer); } Disconnected?.Invoke(this, EventArgs.Empty); }
private void tcpListenService_ClientDisconnect(object sender, IpEndpoint e) { _log.LogDebug($"TCP client disconnected from {e}"); var peer = Peers.FirstOrDefault(p => p.RemoteTcpPorts.Contains(e.Port)); if (peer == null) { _log.LogDebug("Failed to identify disconnecting peer"); return; } peer.RemoveTcpConnection(e.Port); peer.LastUpdateReceived = DateTime.Now; _log.LogInfo($"CITP Peer '{peer}' disconnected on TCP Port {e.Port}"); }