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

Code before:

            DoBind(csep.IPEndPoint, csep.SocketAddress);
        }

        private void EnableReuseUnicastPort()
        {
            // By enabling SO_REUSE_UNICASTPORT, we defer actual port allocation until the ConnectEx call,
            // so it can bind to ports from the Windows auto-reuse port range, if configured by an admin.
            // The socket option is supported on Windows 10+, we are ignoring the SocketError in case setsockopt fails.
            int optionValue = 1;
            SocketError error = Interop.Winsock.setsockopt(
                _handle,
                SocketOptionLevel.Socket,
                SocketOptionName.ReuseUnicastPort,
                ref optionValue,
                sizeof(int));

            if (NetEventSource.Log.IsEnabled() && error != SocketError.Success)
            {
                error = SocketPal.GetLastSocketError();
                NetEventSource.Info($"Enabling SO_REUSE_UNICASTPORT failed with error code: {error}");
            }
        }

        internal unsafe bool ConnectEx(SafeSocketHandle socketHandle,
            Span<byte> socketAddress,
            IntPtr buffer,
            int dataLength,
            out int bytesSent,
            NativeOverlapped* overlapped)
        {
            ConnectExDelegate connectEx = GetDynamicWinsockMethods().GetConnectExDelegate(socketHandle);

            return connectEx(socketHandle, socketAddress, buffer, dataLength, out bytesSent, overlapped);
        }

        internal unsafe SocketError WSARecvMsg(SafeSocketHandle socketHandle, IntPtr msg, out int bytesTransferred, NativeOverlapped* overlapped, IntPtr completionRoutine)
        {
            WSARecvMsgDelegate recvMsg = GetDynamicWinsockMethods().GetWSARecvMsgDelegate(socketHandle);

            return recvMsg(socketHandle, msg, out bytesTransferred, overlapped, completionRoutine);
        }

        internal unsafe SocketError WSARecvMsgBlocking(SafeSocketHandle socketHandle, IntPtr msg, out int bytesTransferred)
        {
            WSARecvMsgDelegate recvMsg = GetDynamicWinsockMethods().GetWSARecvMsgDelegate(_handle);

            return recvMsg(socketHandle, msg, out bytesTransferred, null, IntPtr.Zero);
        }

        internal unsafe bool TransmitPackets(SafeSocketHandle socketHandle, IntPtr packetArray, int elementCount, int sendSize, NativeOverlapped* overlapped, TransmitFileOptions flags)

Review comment (suggestion):
```suggestion
            ReadOnlySpan<byte> socketAddress,
```

Code after:

            DoBind(csep.IPEndPoint, csep.SocketAddress);
        }

        private void EnableReuseUnicastPort()
        {
            // By enabling SO_REUSE_UNICASTPORT, we defer actual port allocation until the ConnectEx call,
            // so it can bind to ports from the Windows auto-reuse port range, if configured by an admin.
            // The socket option is supported on Windows 10+, we are ignoring the SocketError in case setsockopt fails.
            int optionValue = 1;
            SocketError error = Interop.Winsock.setsockopt(
                _handle,
                SocketOptionLevel.Socket,
                SocketOptionName.ReuseUnicastPort,
                ref optionValue,
                sizeof(int));

            if (NetEventSource.Log.IsEnabled() && error != SocketError.Success)
            {
                error = SocketPal.GetLastSocketError();
                NetEventSource.Info($"Enabling SO_REUSE_UNICASTPORT failed with error code: {error}");
            }
        }

        internal unsafe bool ConnectEx(SafeSocketHandle socketHandle,
            ReadOnlySpan<byte> socketAddress,
            IntPtr buffer,
            int dataLength,
            out int bytesSent,
            NativeOverlapped* overlapped)
        {
            ConnectExDelegate connectEx = GetDynamicWinsockMethods().GetConnectExDelegate(socketHandle);

            return connectEx(socketHandle, socketAddress, buffer, dataLength, out bytesSent, overlapped);
        }

        internal unsafe SocketError WSARecvMsg(SafeSocketHandle socketHandle, IntPtr msg, out int bytesTransferred, NativeOverlapped* overlapped, IntPtr completionRoutine)
        {
            WSARecvMsgDelegate recvMsg = GetDynamicWinsockMethods().GetWSARecvMsgDelegate(socketHandle);

            return recvMsg(socketHandle, msg, out bytesTransferred, overlapped, completionRoutine);
        }

        internal unsafe SocketError WSARecvMsgBlocking(SafeSocketHandle socketHandle, IntPtr msg, out int bytesTransferred)
        {
            WSARecvMsgDelegate recvMsg = GetDynamicWinsockMethods().GetWSARecvMsgDelegate(_handle);

            return recvMsg(socketHandle, msg, out bytesTransferred, null, IntPtr.Zero);
        }

        internal unsafe bool TransmitPackets(SafeSocketHandle socketHandle, IntPtr packetArray, int elementCount, int sendSize, NativeOverlapped* overlapped, TransmitFileOptions flags)