/// <summary>
 /// Set the socket security information.
 /// </summary>
 /// <param name="socket">The socket to set.</param>
 /// <param name="settings">The security settings.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The NT status code.</returns>
 public static NtStatus SetSecurity(this Socket socket, SocketSecuritySettings settings, bool throw_on_error)
 {
     using (var buffer = settings?.ToBuffer() ?? SafeHGlobalBuffer.Null)
     {
         return(SocketNativeMethods.WSASetSocketSecurity(socket.Handle, buffer,
                                                         buffer.Length, IntPtr.Zero, IntPtr.Zero).GetNtStatus(throw_on_error));
     }
 }
 /// <summary>
 /// Set the socket security information.
 /// </summary>
 /// <param name="client">The TCP client to set.</param>
 /// <param name="settings">The security settings.</param>
 public static void SetSecurity(this TcpClient client, SocketSecuritySettings settings = null)
 {
     SetSecurity(client, settings, true);
 }
 /// <summary>
 /// Set the socket security information.
 /// </summary>
 /// <param name="client">The TCP client to set.</param>
 /// <param name="settings">The security settings.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The NT status code.</returns>
 public static NtStatus SetSecurity(this TcpClient client, SocketSecuritySettings settings, bool throw_on_error)
 {
     return(SetSecurity(client.Client, settings, throw_on_error));
 }
 /// <summary>
 /// Set the socket security information.
 /// </summary>
 /// <param name="listener">The TCP listener to set.</param>
 /// <param name="settings">The security settings.</param>
 public static void SetSecurity(this TcpListener listener, SocketSecuritySettings settings = null)
 {
     SetSecurity(listener, settings, true);
 }
 /// <summary>
 /// Set the socket security information.
 /// </summary>
 /// <param name="listener">The TCP listener to set.</param>
 /// <param name="settings">The security settings.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The NT status code.</returns>
 public static NtStatus SetSecurity(this TcpListener listener, SocketSecuritySettings settings, bool throw_on_error)
 {
     return(SetSecurity(listener.Server, settings, throw_on_error));
 }
 /// <summary>
 /// Set the socket security information.
 /// </summary>
 /// <param name="socket">The socket to set.</param>
 /// <param name="settings">The security settings.</param>
 public static void SetSecurity(this Socket socket, SocketSecuritySettings settings = null)
 {
     SetSecurity(socket, settings, true);
 }