private async Task AcceptTcpClientsAsync() { while (true) { try { var tcpClient = await TcpListener.AcceptTcpClientAsync().ConfigureAwait(false); // TcpListener.Stop() will trigger ObjectDisposedException var totClient = new TotClient(tcpClient); await totClient.StartAsync().ConfigureAwait(false); totClient.RequestArrived += TotClient_RequestArrived; using (await ClientsLock.LockAsync().ConfigureAwait(false)) { Clients.Add(totClient); } } catch (ObjectDisposedException ex) { // If TcpListener.Stop() is called, this exception will be triggered. Logger.LogInfo <TotServer>("Server stopped accepting incoming connections."); Logger.LogTrace <TotServer>(ex); return; } catch (Exception ex) { Logger.LogWarning <TotServer>(ex, LogLevel.Debug); } } }
private void OnRequestArrived(TotClient client, TotRequest request) => RequestArrived?.Invoke(client, request);