Repository: dotnet/runtime
File: src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs (C#)

Code before:
                    break;
            }

            // Don't log transferred byte count in case of a failure.

            Complete();
        }

        internal void FinishOperationAsyncFailure(SocketError socketError, int bytesTransferred, SocketFlags flags)
        {
            ExecutionContext? context = _context; // store context before it's cleared as part of finishing the operation

            FinishOperationSyncFailure(socketError, bytesTransferred, flags);

            if (context == null)
            {
                OnCompletedInternal();
            }
            else
            {
                ExecutionContext.Run(context, s_executionCallback, this);
            }
        }

        /// <summary>Gets the index of the next address in the specified family.</summary>
        /// <param name="addresses">The array of IP addresses to search, typycally from DNS resolution</param>
        /// <param name="addressFamily">The address family to match.</param>
        /// <param name="lastIndex">The index of the last matched address or -1 on first round. </param>
        /// <returns>The index of the next matching address, or -1 if none found.</returns>
        private static int GetNextAddressIndex(IPAddress[] addresses, AddressFamily addressFamily, int lastIndex)
        {
            for (int i = lastIndex + 1; i < addresses.Length; i++)
            {
                if (addresses[i].AddressFamily == addressFamily)
                {
                    return i;
                }
            }

            return -1;
        }

        /// <summary>Performs an asynchronous connect involving a DNS lookup.</summary>
        /// <param name="endPoint">The DNS end point to which to connect.</param>
        /// <param name="socketType">The SocketType to use to construct new sockets, if necessary.</param>
        /// <param name="protocolType">The ProtocolType to use to construct new sockets, if necessary.</param>
        /// <param name="connectAlgorithm">Connect strategy.</param>
        /// <returns>true if the operation is pending; otherwise, false if it's already completed.</returns>
        internal bool DnsConnectAsync(DnsEndPoint endPoint, SocketType socketType, ProtocolType protocolType, ConnectAlgorithm connectAlgorithm = ConnectAlgorithm.Default)
        {
            Debug.Assert(endPoint.AddressFamily == AddressFamily.Unspecified ||

Review comment (suggestion):
```suggestion
        /// <param name="addresses">The array of IP addresses to search, typically from DNS resolution</param>
```

Code after:
            {
                case SocketAsyncOperation.SendPackets:
                    // We potentially own FileStreams that need to be disposed.
                    FinishOperationSendPackets();
                    break;
            }

            // Don't log transferred byte count in case of a failure.

            Complete();
        }

        internal void FinishOperationAsyncFailure(SocketError socketError, int bytesTransferred, SocketFlags flags)
        {
            ExecutionContext? context = _context; // store context before it's cleared as part of finishing the operation

            FinishOperationSyncFailure(socketError, bytesTransferred, flags);

            if (context == null)
            {
                OnCompletedInternal();
            }
            else
            {
                ExecutionContext.Run(context, s_executionCallback, this);
            }
        }

        /// <summary>Performs an asynchronous connect involving a DNS lookup.</summary>
        /// <param name="endPoint">The DNS end point to which to connect.</param>
        /// <param name="socketType">The SocketType to use to construct new sockets, if necessary.</param>
        /// <param name="protocolType">The ProtocolType to use to construct new sockets, if necessary.</param>
        /// <param name="connectAlgorithm">Connect strategy.</param>
        /// <param name="cancellationToken">The CancellationToken.</param>
        /// <returns>true if the operation is pending; otherwise, false if it's already completed.</returns>
        internal bool DnsConnectAsync(DnsEndPoint endPoint, SocketType socketType, ProtocolType protocolType, ConnectAlgorithm connectAlgorithm, CancellationToken cancellationToken)
        {
            Debug.Assert(endPoint.AddressFamily == AddressFamily.Unspecified ||
                         endPoint.AddressFamily == AddressFamily.InterNetwork ||
                         endPoint.AddressFamily == AddressFamily.InterNetworkV6);

            if (_multipleConnectCancellation is not null)
            {
                Debug.Assert(!cancellationToken.CanBeCanceled, "Task-based connect logic should not use _multipleConnectCancellation for cancellation.");
                // We registered a CancellationTokenSource in StartOperationConnect.
                cancellationToken = _multipleConnectCancellation.Token;
            }

            // We can do parallel connect only if socket was not specified and when there is at least one address of each AF.
            bool parallelConnect = connectAlgorithm == ConnectAlgorithm.Parallel &&
                                            _currentSocket == null &&