/// <summary> /// Checks the completed connection objects. /// </summary> /// <returns>True if everything completed normally and false if there were any client disconnections.</returns> private bool CheckConnectionTask(List <ConnectionData> connectionList, ref TimeSpan?keepAlive, ref bool isKeepAliveDefault) { var allFine = true; foreach (var current in connectionList) { if (current.ChangeKeepAliveTask != null && current.ChangeKeepAliveTask.IsCompleted) { ChangeKeepAlive(current.ChangeKeepAliveTask, ref keepAlive, ref isKeepAliveDefault); current.ChangeKeepAliveTask = null; } if (current.ConnectionTask.IsCompleted) { Debug.Assert(current.ChangeKeepAliveTask == null); if (current.ConnectionTask.Result == CompletionReason.ClientDisconnect) { allFine = false; } } } // Finally remove any ConnectionData for connections which are no longer active. int processedCount = connectionList.RemoveAll(x => x.ConnectionTask.IsCompleted); if (processedCount > 0) { _diagnosticListener.ConnectionProcessed(processedCount); } return(allFine); }
/// <summary> /// Checks the completed connection objects. /// </summary> /// <returns>True if everything completed normally and false if there were any client disconnections.</returns> private bool CheckConnectionTask(List <Task <ConnectionData> > connectionList, ref TimeSpan?keepAlive, ref bool isKeepAliveDefault) { var allFine = true; var processedCount = 0; var i = 0; while (i < connectionList.Count) { var current = connectionList[i]; if (!current.IsCompleted) { i++; continue; } connectionList.RemoveAt(i); processedCount++; var connectionData = current.Result; ChangeKeepAlive(connectionData.KeepAlive, ref keepAlive, ref isKeepAliveDefault); if (connectionData.CompletionReason == CompletionReason.ClientDisconnect) { allFine = false; } } if (processedCount > 0) { _diagnosticListener.ConnectionProcessed(processedCount); } return(allFine); }