| | | 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 | | { |
| | 769 | 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 | | { |
| | 769 | 36 | | get => _initialStreamWindowSize; |
| | 23 | 37 | | set => _initialStreamWindowSize = |
| | 23 | 38 | | value < 1024 ? |
| | 23 | 39 | | throw new ArgumentException( |
| | 23 | 40 | | $"The {nameof(InitialStreamWindowSize)} value cannot be less than 1 KB.", |
| | 23 | 41 | | nameof(value)) : |
| | 23 | 42 | | value; |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary>Gets or sets the maximum number of Pong frames that can be queued for sending. A Pong frame is queued |
| | | 46 | | /// for sending when a Ping frame is received, and remains queued until it is written to the underlying duplex |
| | | 47 | | /// connection. The connection is aborted when a Ping frame is received while this limit is reached; this protects |
| | | 48 | | /// against a peer that doesn't read from the connection but keeps sending Ping frames, which would otherwise |
| | | 49 | | /// queue Pong frame writes without limit.</summary> |
| | | 50 | | /// <value>The maximum number of Pong frames queued for sending. It can't be less than <c>1</c>. Defaults to |
| | | 51 | | /// <c>100</c>.</value> |
| | | 52 | | public int MaxOutstandingPongs |
| | | 53 | | { |
| | 770 | 54 | | get => _maxOutstandingPongs; |
| | 2 | 55 | | set => _maxOutstandingPongs = |
| | 2 | 56 | | value < 1 ? |
| | 2 | 57 | | throw new ArgumentException( |
| | 2 | 58 | | $"The {nameof(MaxOutstandingPongs)} value cannot be less than 1.", |
| | 2 | 59 | | nameof(value)) : |
| | 2 | 60 | | value; |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | /// <summary>Gets or sets the maximum stream frame size in bytes.</summary> |
| | | 64 | | /// <value>The maximum stream frame size in bytes. It can't be less than <c>1024</c> or greater than |
| | | 65 | | /// <c>16,777,215</c> (2^24 - 1). Defaults to <c>32,768</c>.</value> |
| | | 66 | | public int MaxStreamFrameSize |
| | | 67 | | { |
| | 769 | 68 | | get => _maxStreamFrameSize; |
| | 4 | 69 | | set => _maxStreamFrameSize = |
| | 4 | 70 | | value < 1024 ? |
| | 4 | 71 | | throw new ArgumentException( |
| | 4 | 72 | | $"The {nameof(MaxStreamFrameSize)} value cannot be less than 1 KB.", |
| | 4 | 73 | | nameof(value)) : |
| | 4 | 74 | | value > MaxStreamFrameSizeCeiling ? |
| | 4 | 75 | | throw new ArgumentException( |
| | 4 | 76 | | $"The {nameof(MaxStreamFrameSize)} value cannot be larger than {MaxStreamFrameSizeCeiling}.", |
| | 4 | 77 | | nameof(value)) : |
| | 4 | 78 | | value; |
| | | 79 | | } |
| | | 80 | | |
| | | 81 | | /// <summary>Gets or sets the per-connection pause writer threshold. It defines the maximum amount of data that |
| | | 82 | | /// Slic buffers locally on the connection's outbound pipe before |
| | | 83 | | /// <see cref="System.IO.Pipelines.PipeWriter.FlushAsync" /> on the underlying pipe starts blocking. This bounds the |
| | | 84 | | /// memory used by the connection's outbound buffering when a peer is slow or not reading.</summary> |
| | | 85 | | /// <value>The pause writer threshold in bytes. Set to <c>0</c> to disable this flow control mechanism. Otherwise, |
| | | 86 | | /// it can't be less than <c>1</c> KB. Defaults to <c>64</c> KB (the <see cref="System.IO.Pipelines.Pipe" /> |
| | | 87 | | /// default).</value> |
| | | 88 | | // The default specified by System.IO.Pipelines.PipeOptions. |
| | 1605 | 89 | | public int PauseWriterThreshold { get; set => field = ValidatePauseWriterThreshold(value); } = 65_536; |
| | | 90 | | |
| | | 91 | | // Upper bound on MaxStreamFrameSize (local and peer-advertised). Matches HTTP/2's SETTINGS_MAX_FRAME_SIZE |
| | | 92 | | // ceiling. Larger frames worsen head-of-line blocking across multiplexed streams without improving |
| | | 93 | | // throughput at any realistic link speed. |
| | | 94 | | internal const int MaxStreamFrameSizeCeiling = 16_777_215; |
| | | 95 | | |
| | | 96 | | private static int ValidatePauseWriterThreshold(int value) => |
| | 16 | 97 | | value < 0 ? |
| | 16 | 98 | | throw new ArgumentException( |
| | 16 | 99 | | $"The {nameof(PauseWriterThreshold)} value cannot be negative.", |
| | 16 | 100 | | nameof(value)) : |
| | 16 | 101 | | value > 0 && value < 1024 ? |
| | 16 | 102 | | throw new ArgumentException( |
| | 16 | 103 | | $"The {nameof(PauseWriterThreshold)} value cannot be less than 1 KB unless it is 0.", |
| | 16 | 104 | | nameof(value)) : |
| | 16 | 105 | | value; |
| | | 106 | | |
| | | 107 | | // We use the HTTP/2 maximum window size (2GB). |
| | | 108 | | internal const int MaxWindowSize = int.MaxValue; |
| | | 109 | | |
| | 817 | 110 | | private TimeSpan _idleTimeout = TimeSpan.FromSeconds(30); |
| | | 111 | | |
| | | 112 | | // The default specified in the HTTP/2 specification. |
| | 817 | 113 | | private int _initialStreamWindowSize = 65_536; |
| | 817 | 114 | | private int _maxOutstandingPongs = 100; |
| | 817 | 115 | | private int _maxStreamFrameSize = 32_768; |
| | | 116 | | } |