| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | namespace IceRpc.Transports.Slic; |
| | | 4 | | |
| | | 5 | | /// <summary>A property bag used to configure a <see cref="SlicClientTransport" /> or |
| | | 6 | | /// <see cref="SlicServerTransport" />.</summary> |
| | | 7 | | public sealed record class SlicTransportOptions |
| | | 8 | | { |
| | | 9 | | /// <summary>Gets or sets the idle timeout. This timeout is used to monitor the transport connection health. If no |
| | | 10 | | /// data is received within the idle timeout period, the transport connection is aborted. The effective idle timeout |
| | | 11 | | /// is negotiated with the peer: use <see cref="Timeout.InfiniteTimeSpan" /> to defer to the peer's idle timeout. |
| | | 12 | | /// Idle timeout monitoring is disabled only when both sides use <see cref="Timeout.InfiniteTimeSpan" />.</summary> |
| | | 13 | | /// <value>The idle timeout. It must be positive or <see cref="Timeout.InfiniteTimeSpan" />. |
| | | 14 | | /// Defaults to <c>30</c> s.</value> |
| | | 15 | | public TimeSpan IdleTimeout |
| | | 16 | | { |
| | 753 | 17 | | get => _idleTimeout; |
| | | 18 | | set |
| | 6 | 19 | | { |
| | 6 | 20 | | if (value != Timeout.InfiniteTimeSpan && value <= TimeSpan.Zero) |
| | 0 | 21 | | { |
| | 0 | 22 | | throw new ArgumentException( |
| | 0 | 23 | | $"The {nameof(IdleTimeout)} value must be positive or Timeout.InfiniteTimeSpan.", |
| | 0 | 24 | | nameof(value)); |
| | | 25 | | } |
| | 6 | 26 | | _idleTimeout = value; |
| | 6 | 27 | | } |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary>Gets or sets the initial stream window size. It defines the initial size of the stream receive buffer |
| | | 31 | | /// for data that has not been consumed yet by the application. When this buffer is full the sender should stop |
| | | 32 | | /// sending additional data.</summary> |
| | | 33 | | /// <value>The initial window size in bytes. It can't be less than <c>1</c> KB. Defaults to <c>64</c> KB.</value> |
| | | 34 | | public int InitialStreamWindowSize |
| | | 35 | | { |
| | 753 | 36 | | get => _initialStreamWindowSize; |
| | 20 | 37 | | set => _initialStreamWindowSize = |
| | 20 | 38 | | value < 1024 ? |
| | 20 | 39 | | throw new ArgumentException( |
| | 20 | 40 | | $"The {nameof(InitialStreamWindowSize)} value cannot be less than 1 KB.", |
| | 20 | 41 | | nameof(value)) : |
| | 20 | 42 | | value; |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary>Gets or sets the maximum stream frame size in bytes.</summary> |
| | | 46 | | /// <value>The maximum stream frame size in bytes. It can't be less than <c>1024</c> or greater than |
| | | 47 | | /// <c>16,777,215</c> (2^24 - 1). Defaults to <c>32,768</c>.</value> |
| | | 48 | | public int MaxStreamFrameSize |
| | | 49 | | { |
| | 753 | 50 | | get => _maxStreamFrameSize; |
| | 4 | 51 | | set => _maxStreamFrameSize = |
| | 4 | 52 | | value < 1024 ? |
| | 4 | 53 | | throw new ArgumentException( |
| | 4 | 54 | | $"The {nameof(MaxStreamFrameSize)} value cannot be less than 1 KB.", |
| | 4 | 55 | | nameof(value)) : |
| | 4 | 56 | | value > MaxStreamFrameSizeCeiling ? |
| | 4 | 57 | | throw new ArgumentException( |
| | 4 | 58 | | $"The {nameof(MaxStreamFrameSize)} value cannot be larger than {MaxStreamFrameSizeCeiling}.", |
| | 4 | 59 | | nameof(value)) : |
| | 4 | 60 | | value; |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | /// <summary>Gets or sets the per-connection pause writer threshold. It defines the maximum amount of data that |
| | | 64 | | /// Slic buffers locally on the connection's outbound pipe before |
| | | 65 | | /// <see cref="System.IO.Pipelines.PipeWriter.FlushAsync" /> on the underlying pipe starts blocking. This bounds the |
| | | 66 | | /// memory used by the connection's outbound buffering when a peer is slow or not reading.</summary> |
| | | 67 | | /// <value>The pause writer threshold in bytes. Set to <c>0</c> to disable this flow control mechanism. Otherwise, |
| | | 68 | | /// it can't be less than <c>1</c> KB. Defaults to <c>64</c> KB (the <see cref="System.IO.Pipelines.Pipe" /> |
| | | 69 | | /// default).</value> |
| | | 70 | | // The default specified by System.IO.Pipelines.PipeOptions. |
| | 1566 | 71 | | public int PauseWriterThreshold { get; set => field = ValidatePauseWriterThreshold(value); } = 65_536; |
| | | 72 | | |
| | | 73 | | // Upper bound on MaxStreamFrameSize (local and peer-advertised). Matches HTTP/2's SETTINGS_MAX_FRAME_SIZE |
| | | 74 | | // ceiling. Larger frames worsen head-of-line blocking across multiplexed streams without improving |
| | | 75 | | // throughput at any realistic link speed. |
| | | 76 | | internal const int MaxStreamFrameSizeCeiling = 16_777_215; |
| | | 77 | | |
| | | 78 | | private static int ValidatePauseWriterThreshold(int value) => |
| | 13 | 79 | | value < 0 ? |
| | 13 | 80 | | throw new ArgumentException( |
| | 13 | 81 | | $"The {nameof(PauseWriterThreshold)} value cannot be negative.", |
| | 13 | 82 | | nameof(value)) : |
| | 13 | 83 | | value > 0 && value < 1024 ? |
| | 13 | 84 | | throw new ArgumentException( |
| | 13 | 85 | | $"The {nameof(PauseWriterThreshold)} value cannot be less than 1 KB unless it is 0.", |
| | 13 | 86 | | nameof(value)) : |
| | 13 | 87 | | value; |
| | | 88 | | |
| | | 89 | | // We use the HTTP/2 maximum window size (2GB). |
| | | 90 | | internal const int MaxWindowSize = int.MaxValue; |
| | | 91 | | |
| | 797 | 92 | | private TimeSpan _idleTimeout = TimeSpan.FromSeconds(30); |
| | | 93 | | |
| | | 94 | | // The default specified in the HTTP/2 specification. |
| | 797 | 95 | | private int _initialStreamWindowSize = 65_536; |
| | 797 | 96 | | private int _maxStreamFrameSize = 32_768; |
| | | 97 | | } |