| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Net; |
| | 4 | |
|
| | 5 | | namespace IceRpc.Transports.Quic; |
| | 6 | |
|
| | 7 | | /// <summary>The base options class for QUIC transports.</summary> |
| | 8 | | public record class QuicTransportOptions |
| | 9 | | { |
| | 10 | | /// <summary>Gets or sets the idle timeout. This timeout is used to monitor the transport connection health. If no |
| | 11 | | /// data is received within the idle timeout period, the transport connection is aborted.</summary> |
| | 12 | | /// <value>The idle timeout. Defaults to 30 seconds. <see cref="TimeSpan.Zero" /> means "use the default value |
| | 13 | | /// provided by the underlying implementation".</value> |
| | 14 | | /// <remarks>The idle timeout is negotiated by QUIC during connection establishment. The actual idle timeout value |
| | 15 | | /// for a connection can be lower than the value you've set here.</remarks> |
| 962 | 16 | | public TimeSpan IdleTimeout { get; set; } = TimeSpan.FromSeconds(30); |
| | 17 | | } |
| | 18 | |
|
| | 19 | | /// <summary>The options class for configuring <see cref="QuicClientTransport"/>.</summary> |
| | 20 | | public sealed record class QuicClientTransportOptions : QuicTransportOptions |
| | 21 | | { |
| | 22 | | /// <summary>Gets or sets the address and port represented by a .NET <see cref="IPEndPoint"/> to use for a client |
| | 23 | | /// QUIC connection. If specified the client QUIC connection will bind to this address and port before connection |
| | 24 | | /// establishment.</summary> |
| | 25 | | /// <value>The address and port to bind to. Defaults to <see langword="null" />.</value> |
| | 26 | | public IPEndPoint? LocalNetworkAddress { get; set; } |
| | 27 | |
|
| | 28 | | /// <summary>Gets or sets the interval at which the client sends QUIC PING frames to the server to keep the |
| | 29 | | /// connection alive.</summary> |
| | 30 | | /// <value>The keep-alive interval. Defaults to 15 seconds. <see cref="TimeSpan.Zero" /> means: use the default |
| | 31 | | /// value provided by the underlying implementation. <see cref="Timeout.InfiniteTimeSpan" /> means: never send |
| | 32 | | /// PING frames.</value> |
| | 33 | | /// <remarks>Unlike the idle timeout, the keep-alive interval is not negotiated during connection establishment. We |
| | 34 | | /// recommend setting this interval at half the negotiated idle timeout value to keep a healthy connection alive |
| | 35 | | /// forever - really until it's closed due to inactivity at the RPC level via the |
| | 36 | | /// <see cref="ConnectionOptions.InactivityTimeout" />. |
| | 37 | | /// This option is a stop-gap: ideally the .NET QUIC implementation would provide a way to automatically send PING |
| | 38 | | /// frames to keep the connection alive based on the negotiated idle timeout. See |
| | 39 | | /// <see href="https://github.com/microsoft/msquic/issues/3880" />.</remarks> |
| | 40 | | /// <remarks>This option is only implemented for .NET 9.0. With .NET 8.0, neither the client nor the server sends |
| | 41 | | /// PING frames to keep the connection alive.</remarks> |
| | 42 | | public TimeSpan KeepAliveInterval { get; set; } = TimeSpan.FromSeconds(15); |
| | 43 | | } |
| | 44 | |
|
| | 45 | | /// <summary>The options class for configuring <see cref="QuicServerTransport"/>.</summary> |
| | 46 | | public sealed record class QuicServerTransportOptions : QuicTransportOptions |
| | 47 | | { |
| | 48 | | /// <summary>Gets or sets the length of the server listen queue for accepting new connections. If a new connection |
| | 49 | | /// request arrives and the queue is full, the client connection establishment will fail with a <see |
| | 50 | | /// cref="IceRpcException"/> and the <see cref="IceRpcError.ConnectionRefused"/> error code.</summary> |
| | 51 | | /// <value>The server listen backlog size. Defaults to <c>511</c>.</value> |
| | 52 | | public int ListenBacklog |
| | 53 | | { |
| | 54 | | get => _listenBacklog; |
| | 55 | | set => _listenBacklog = value > 0 ? value : |
| | 56 | | throw new ArgumentOutOfRangeException( |
| | 57 | | nameof(value), |
| | 58 | | $"Invalid value '{value}' for {nameof(ListenBacklog)}, it cannot be less than 1."); |
| | 59 | | } |
| | 60 | |
|
| | 61 | | private int _listenBacklog = 511; |
| | 62 | | } |