private async Task Read() { while (!_tokenSource.IsCancellationRequested) { try { var client = await _listener.AcceptTcpClientAsync() .ConfigureAwait(false); var connection = await MllpHost.Create( client, _messageLog, _middleware, _parser, _encoding, _serverCertificate, _userCertificateValidationCallback) .ConfigureAwait(false); lock (_connections) { _connections.Add(connection); } } catch (ObjectDisposedException) { // Ignore } } }
private async Task HandleClientRequestAsync(TcpClient client) { var clientEndpoint = (IPEndPoint)client.Client.RemoteEndPoint; MllpHost connection; try { connection = await MllpHost.Create(client, _middleware, _connectionDetails.Encoding, _connectionDetails.SecurityDetails, _token); } catch (AuthenticationException) { // don't bring down server just because a client wasn't table to authenticate. this.TriggerClientAuthenticationFailedEvent(clientEndpoint); return; } lock (_connections) { _connections.Add(connection); } this.TriggerClientConnectedEvent(clientEndpoint); }