| | 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="ConnectionCache" />.</summary> |
| | 8 | | public record class ConnectionCacheOptions |
| | 9 | | { |
| | 10 | | /// <summary>Gets or sets the SSL client authentication options.</summary> |
| | 11 | | /// <value>The SSL client authentication options. When not <see langword="null" />, |
| | 12 | | /// <see cref="ClientConnection.ConnectAsync(CancellationToken)" /> will either establish a secure connection or |
| | 13 | | /// fail.</value> |
| 18 | 14 | | public SslClientAuthenticationOptions? ClientAuthenticationOptions { get; set; } |
| | 15 | |
|
| | 16 | | /// <summary>Gets or sets the connection options used for connections created by the connection cache.</summary> |
| | 17 | | /// <value>The connection options. Defaults to a default constructed <see cref="ConnectionOptions" />.</value> |
| 36 | 18 | | public ConnectionOptions ConnectionOptions { get; set; } = new(); |
| | 19 | |
|
| | 20 | | /// <summary>Gets or sets the connection establishment timeout for connections created by the connection cache. |
| | 21 | | /// </summary> |
| | 22 | | /// <value>The connection establishment timeout. Defaults to <c>10</c> seconds.</value> |
| | 23 | | public TimeSpan ConnectTimeout |
| | 24 | | { |
| 18 | 25 | | get => _connectTimeout; |
| 0 | 26 | | set => _connectTimeout = value != TimeSpan.Zero ? value : |
| 0 | 27 | | throw new ArgumentException($"0 is not a valid value for {nameof(ConnectTimeout)}", nameof(value)); |
| | 28 | | } |
| | 29 | |
|
| | 30 | | /// <summary>Gets or sets a value indicating whether or not the connection cache prefers an active connection over |
| | 31 | | /// creating a new one.</summary> |
| | 32 | | /// <value>When <see langword="true" />, the connection cache first checks the server addresses of the target |
| | 33 | | /// service address: if any matches an active connection it manages, it sends the request over this connection. It |
| | 34 | | /// does not check connections being connected. When <see langword="false" />, the connection cache does not prefer |
| | 35 | | /// existing connections.</value> |
| 38 | 36 | | public bool PreferExistingConnection { get; set; } = true; |
| | 37 | |
|
| | 38 | | /// <summary>Gets or sets the shutdown timeout. This timeout is used when gracefully shutting down a connection |
| | 39 | | /// managed by the connection cache.</summary> |
| | 40 | | /// <value>This shutdown timeout. Defaults to <c>10</c> seconds.</value> |
| | 41 | | public TimeSpan ShutdownTimeout |
| | 42 | | { |
| 18 | 43 | | get => _shutdownTimeout; |
| 0 | 44 | | set => _shutdownTimeout = value != TimeSpan.Zero ? value : |
| 0 | 45 | | throw new ArgumentException($"0 is not a valid value for {nameof(ShutdownTimeout)}", nameof(value)); |
| | 46 | | } |
| | 47 | |
|
| 18 | 48 | | private TimeSpan _connectTimeout = TimeSpan.FromSeconds(10); |
| 18 | 49 | | private TimeSpan _shutdownTimeout = TimeSpan.FromSeconds(10); |
| | 50 | | } |