| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using System.Net.Security; |
| | | 4 | | |
| | | 5 | | namespace IceRpc; |
| | | 6 | | |
| | | 7 | | /// <summary>Represents a property bag used to configure a <see cref="Server" />.</summary> |
| | | 8 | | public sealed record class ServerOptions |
| | | 9 | | { |
| | | 10 | | /// <summary>Gets or sets the connection options for server connections.</summary> |
| | | 11 | | /// <value>The connection options. Defaults to a default constructed <see cref="ConnectionOptions" />.</value> |
| | 704 | 12 | | public ConnectionOptions ConnectionOptions { get; set; } = new(); |
| | | 13 | | |
| | | 14 | | /// <summary>Gets or sets the connection establishment timeout for connections accepted by the server.</summary> |
| | | 15 | | /// <value>Defaults to <c>10</c> seconds.</value> |
| | | 16 | | public TimeSpan ConnectTimeout |
| | | 17 | | { |
| | 162 | 18 | | get => _connectTimeout; |
| | 3 | 19 | | set => _connectTimeout = value != TimeSpan.Zero ? value : |
| | 3 | 20 | | throw new ArgumentException($"0 is not a valid value for {nameof(ConnectTimeout)}", nameof(value)); |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary>Gets or sets the maximum number of accepted server connections. Once the maximum number of connections |
| | | 24 | | /// has been reached, the server will refuse any new connections.</summary> |
| | | 25 | | /// <value>The maximum number of connections. Defaults to <c>0</c>, meaning unlimited.</value> |
| | | 26 | | public int MaxConnections |
| | | 27 | | { |
| | 94 | 28 | | get => _maxConnections; |
| | 9 | 29 | | set => _maxConnections = value >= 0 ? value : |
| | 9 | 30 | | throw new ArgumentOutOfRangeException( |
| | 9 | 31 | | nameof(value), |
| | 9 | 32 | | value, |
| | 9 | 33 | | $"{nameof(MaxConnections)} must be greater than or equal to 0 (where 0 means unlimited)."); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary>Gets or sets the maximum number of server connections waiting for connection establishment to complete. |
| | | 37 | | /// Once the maximum number of pending connections has been reached, the server will stop accepting new connections |
| | | 38 | | /// to ensure that the transport rejects new connections once its connection backlog is full.</summary> |
| | | 39 | | /// <value>The maximum number of connection waiting for connection establishment to complete. Defaults to |
| | | 40 | | /// <c>100</c>.</value> |
| | | 41 | | public int MaxPendingConnections |
| | | 42 | | { |
| | 94 | 43 | | get => _maxPendingConnections; |
| | 4 | 44 | | set => _maxPendingConnections = value > 0 ? value : |
| | 4 | 45 | | throw new ArgumentOutOfRangeException( |
| | 4 | 46 | | nameof(value), |
| | 4 | 47 | | value, |
| | 4 | 48 | | $"{nameof(MaxPendingConnections)} must be greater than 0."); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary>Gets or sets the server's address. The server address host is usually an IP address, and it cannot be a |
| | | 52 | | /// DNS name.</summary> |
| | | 53 | | /// <value>The <see cref="ServerAddress" /> of this <see cref="Server" />. Defaults to a <see cref="ServerAddress" |
| | | 54 | | /// /> constructed with <see cref="Protocol.IceRpc" />.</value> |
| | 286 | 55 | | public ServerAddress ServerAddress { get; set; } = new(Protocol.IceRpc); |
| | | 56 | | |
| | | 57 | | /// <summary>Gets or sets the SSL server authentication options.</summary> |
| | | 58 | | /// <value>The SSL server authentication options. When not <see langword="null" />, the server will accept only |
| | | 59 | | /// secure connections.</value> |
| | 222 | 60 | | public SslServerAuthenticationOptions? ServerAuthenticationOptions { get; set; } |
| | | 61 | | |
| | | 62 | | /// <summary>Gets or sets the shutdown timeout. This timeout is used when gracefully shutting down a connection |
| | | 63 | | /// managed by the server.</summary> |
| | | 64 | | /// <value>Defaults to <c>10</c> seconds.</value> |
| | | 65 | | public TimeSpan ShutdownTimeout |
| | | 66 | | { |
| | 94 | 67 | | get => _shutdownTimeout; |
| | 0 | 68 | | set => _shutdownTimeout = value != TimeSpan.Zero ? value : |
| | 0 | 69 | | throw new ArgumentException($"0 is not a valid value for {nameof(ShutdownTimeout)}", nameof(value)); |
| | | 70 | | } |
| | | 71 | | |
| | 99 | 72 | | private TimeSpan _connectTimeout = TimeSpan.FromSeconds(10); |
| | | 73 | | private int _maxConnections; |
| | 99 | 74 | | private int _maxPendingConnections = 100; |
| | 99 | 75 | | private TimeSpan _shutdownTimeout = TimeSpan.FromSeconds(10); |
| | | 76 | | } |