< Summary

Information
Class: IceRpc.ConnectionOptions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/ConnectionOptions.cs
Tag: 2300_35243572715
Line coverage
76%
Covered lines: 32
Uncovered lines: 10
Coverable lines: 42
Total lines: 156
Line coverage: 76.1%
Branch coverage
36%
Covered branches: 8
Total branches: 22
Branch coverage: 36.3%
Method coverage
85%
Covered methods: 18
Fully covered methods: 18
Total methods: 21
Method coverage: 85.7%
Full method coverage: 85.7%

Metrics

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/ConnectionOptions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Transports;
 4using System.Buffers;
 5
 6namespace IceRpc;
 7
 8/// <summary>Represents a property bag used to configure client and server connections.</summary>
 9public record class ConnectionOptions
 10{
 11    /// <summary>Gets or sets the dispatcher that dispatches requests received by this connection.</summary>
 12    /// <value>The dispatcher that dispatches requests received by this connection, or <see langword="null" /> if this
 13    /// connection does not accept requests.</value>
 201514    public IDispatcher? Dispatcher { get; set; }
 15
 16    /// <summary>Gets or sets a value indicating whether or not to enable the Ice idle check. This option is specific to
 17    /// the ice protocol. When the Ice idle check is enabled, a read operation on the underlying transport connection
 18    /// fails when this read waits for over <see cref="IceIdleTimeout" /> to receive any byte. When the Ice idle check
 19    /// is disabled, the <see cref="IceIdleTimeout" /> has no effect on reads: a read on the underlying transport
 20    /// connection can wait forever to receive a byte.</summary>
 21    /// <value><see langword="true"/> if the Ice idle check is enabled; otherwise, <see langword="false"/>. Defaults to
 22    /// <see langword="true"/>.</value>
 23    /// <remarks>Set to <see langword="false"/> when the peer is an Ice application using Ice 3.7 or earlier and you
 24    /// can't update this application to turn on HeartbeatAlways with
 25    /// <see href="https://archive.zeroc.com/ice/3.7/property-reference/ice-acm#id-.Ice.ACM.*v3.7-Ice.ACM.Heartbeat"/>.
 26    /// When this value is set to <see langword="true"/>, make sure the peer's idle timeout is equal to
 27    /// <see cref="IceIdleTimeout" />.</remarks>
 97628    public bool EnableIceIdleCheck { get; set; } = true;
 29
 30    /// <summary>Gets or sets the Ice idle timeout. This option is specific to the ice protocol. Once the connection is
 31    /// established, the runtime sends a heartbeat to the peer when there is no write on the connection for half this
 32    /// Ice idle timeout.</summary>
 33    /// <value>The Ice idle timeout. Defaults to <c>60</c> seconds to match the default ACM configuration in Ice 3.7.
 34    /// </value>
 35    /// <seealso cref="EnableIceIdleCheck" />
 36    public TimeSpan IceIdleTimeout
 37    {
 68738        get => _iceIdleTimeout;
 339        set => _iceIdleTimeout = value != TimeSpan.Zero ? value :
 340            throw new ArgumentException($"0 is not a valid value for {nameof(IceIdleTimeout)}", nameof(value));
 41    }
 42
 43    /// <summary>Gets or sets the inactivity timeout. This timeout is used to gracefully shut down the connection if
 44    /// it's inactive for longer than this timeout. A connection is considered inactive when there's no invocation or
 45    /// dispatch in progress.</summary>
 46    /// <value>The inactivity timeout. Defaults to <c>5</c> minutes.</value>
 47    public TimeSpan InactivityTimeout
 48    {
 64449        get => _inactivityTimeout;
 1150        set => _inactivityTimeout = value != TimeSpan.Zero ? value :
 1151            throw new ArgumentException($"0 is not a valid value for {nameof(InactivityTimeout)}", nameof(value));
 52    }
 53
 54    /// <summary>Gets or sets the maximum number of requests that a connection can dispatch concurrently. Once this
 55    /// limit is reached, the connection stops reading new requests off its underlying transport connection.</summary>
 56    /// <value>The maximum number of requests that a connection can dispatch concurrently. <c>0</c> means no maximum.
 57    /// Defaults to <c>100</c> requests.</value>
 58    /// <remarks>With the icerpc protocol, you may also need to set <see cref="MaxIceRpcBidirectionalStreams" /> and
 59    /// <see cref="MaxIceRpcUnidirectionalStreams" />. A typical two-way dispatch holds onto one bidirectional stream
 60    /// while a typical one-way dispatch quickly releases its unidirectional stream and then executes without consuming
 61    /// any stream.</remarks>
 62    public int MaxDispatches
 63    {
 193264        get => _maxDispatches;
 1165        set => _maxDispatches = value >= 0 ? value :
 1166            throw new ArgumentOutOfRangeException(nameof(value), "value must be 0 or greater");
 67    }
 68
 69    /// <summary>Gets or sets the maximum size of a frame received over the ice protocol.</summary>
 70    /// <value>The maximum size of an incoming frame, in bytes. This value must be at least <c>256</c>. Defaults to
 71    /// <c>1</c> MB.</value>
 72    /// <remarks>This property is the counterpart of the Ice property
 73    /// <see href="https://docs.zeroc.com/ice/3.8/cpp/ice#Ice.MessageSizeMax">Ice.MessageSizeMax</see>: both limit
 74    /// the size of a whole frame, header included, and both close the connection when the size of an incoming frame
 75    /// exceeds this limit. Unlike Ice.MessageSizeMax, this property is expressed in bytes rather than kilobytes and
 76    /// cannot be set to <c>0</c> to disable the limit.</remarks>
 77    public int MaxIceFrameSize
 78    {
 22979        get => _maxIceFrameSize;
 180        set => _maxIceFrameSize = value >= IceMinFrameSize ? value :
 181            throw new ArgumentOutOfRangeException(
 182                nameof(value),
 183                $"{nameof(MaxIceFrameSize)} must be at least {IceMinFrameSize}");
 84    }
 85
 86    /// <summary>Gets or sets the maximum allowed number of simultaneous remote bidirectional streams that can be
 87    /// accepted on an icerpc connection. When this limit is reached, the peer is not allowed to open any new
 88    /// bidirectional stream. Since an bidirectional stream is opened for each two-way invocation, the sending of the
 89    /// two-way invocation will be delayed until another two-way invocation's stream completes.</summary>
 90    /// <value>The maximum number of bidirectional streams. It can't be less than <c>1</c> or greater than
 91    /// <c>65,535</c>. Defaults to <c>100</c>.</value>
 92    public int MaxIceRpcBidirectionalStreams
 93    {
 7094        get => _maxIceRpcBidirectionalStreams;
 095        set => _maxIceRpcBidirectionalStreams = value is > 0 and <= ushort.MaxValue ? value :
 096            throw new ArgumentException(
 097                $"{nameof(MaxIceRpcBidirectionalStreams)} must be between 1 and {ushort.MaxValue}",
 098                nameof(value));
 99    }
 100
 101    /// <summary>Gets or sets the maximum size of icerpc protocol header.</summary>
 102    /// <value>The maximum size in bytes of the header of an incoming request, response or control frame. Defaults to
 103    /// <c>16,383</c>, and the range of this value is <c>63</c> to <c>1,048,575</c>.</value>
 104    public int MaxIceRpcHeaderSize
 105    {
 415106        get => _maxIceRpcHeaderSize;
 2107        set => _maxIceRpcHeaderSize = IceRpcCheckMaxHeaderSize(value);
 108    }
 109
 110    /// <summary>Gets or sets the maximum allowed number of simultaneous remote unidirectional streams that can be
 111    /// accepted on an icerpc connection. When this limit is reached, the peer is not allowed to open any new
 112    /// unidirectional stream. Since an unidirectional stream is opened for each one-way invocation, the sending of the
 113    /// one-way invocation will be delayed until another one-way invocation's stream completes.</summary>
 114    /// <value>The maximum number of unidirectional streams. It can't be less than <c>1</c> or greater than
 115    /// <c>65,535</c>. Defaults to <c>100</c>.</value>
 116    public int MaxIceRpcUnidirectionalStreams
 117    {
 70118        get => _maxIceRpcUnidirectionalStreams;
 0119        set => _maxIceRpcUnidirectionalStreams = value is > 0 and <= ushort.MaxValue ? value :
 0120            throw new ArgumentException(
 0121                $"{nameof(MaxIceRpcUnidirectionalStreams)} must be between 1 and {ushort.MaxValue}",
 0122                nameof(value));
 123    }
 124
 125    /// <summary>Gets or sets the minimum size of the segment requested from the <see cref="Pool" />.</summary>
 126    /// <value>The minimum size of the segment requested from the <see cref="Pool" />. Defaults to <c>4096</c>.</value>
 127    public int MinSegmentSize
 128    {
 988129        get => _minSegmentSize;
 0130        set => _minSegmentSize = value >= 1024 ? value :
 0131            throw new ArgumentException($"{nameof(MinSegmentSize)} can't be less than 1KB", nameof(value));
 132    }
 133
 134    /// <summary>Gets or sets the <see cref="MemoryPool{T}" /> object used by the connection for allocating memory
 135    /// blocks.</summary>
 136    /// <value>A pool of memory blocks used for buffer management. Defaults to <see cref="MemoryPool{T}.Shared"
 137    /// />.</value>
 1735138    public MemoryPool<byte> Pool { get; set; } = MemoryPool<byte>.Shared;
 139
 140    /// <summary>The default value for <see cref="MaxIceRpcHeaderSize" />.</summary>
 141    internal const int DefaultMaxIceRpcHeaderSize = 16_383;
 142
 143    private const int IceMinFrameSize = 256;
 144
 747145    private TimeSpan _iceIdleTimeout = TimeSpan.FromSeconds(60);
 747146    private TimeSpan _inactivityTimeout = TimeSpan.FromMinutes(5);
 747147    private int _maxDispatches = 100;
 747148    private int _maxIceFrameSize = 1024 * 1024;
 747149    private int _maxIceRpcBidirectionalStreams = MultiplexedConnectionOptions.DefaultMaxBidirectionalStreams;
 747150    private int _maxIceRpcHeaderSize = DefaultMaxIceRpcHeaderSize;
 747151    private int _maxIceRpcUnidirectionalStreams = MultiplexedConnectionOptions.DefaultMaxUnidirectionalStreams;
 747152    private int _minSegmentSize = 4096;
 153
 5154    internal static int IceRpcCheckMaxHeaderSize(long value) => value is >= 63 and <= 1_048_575 ? (int)value :
 5155        throw new ArgumentOutOfRangeException(nameof(value), "value must be between 63 and 1,048,575");
 156}