< Summary

Information
Class: IceRpc.ConnectionOptions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/ConnectionOptions.cs
Tag: 275_13775359185
Line coverage
76%
Covered lines: 32
Uncovered lines: 10
Coverable lines: 42
Total lines: 151
Line coverage: 76.1%
Branch coverage
50%
Covered branches: 9
Total branches: 18
Branch coverage: 50%
Method coverage
85%
Covered methods: 18
Total methods: 21
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>
 339414    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://doc.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>
 161728    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    {
 111638        get => _iceIdleTimeout;
 639        set => _iceIdleTimeout = value != TimeSpan.Zero ? value :
 640            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 shutdown 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    {
 108449        get => _inactivityTimeout;
 2250        set => _inactivityTimeout = value != TimeSpan.Zero ? value :
 2251            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    {
 325264        get => _maxDispatches;
 2265        set => _maxDispatches = value >= 0 ? value :
 2266            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    public int MaxIceFrameSize
 73    {
 37274        get => _maxIceFrameSize;
 275        set => _maxIceFrameSize = value >= IceMinFrameSize ? value :
 276            throw new ArgumentOutOfRangeException(
 277                nameof(value),
 278                $"{nameof(MaxIceFrameSize)} must be at least {IceMinFrameSize}");
 79    }
 80
 81    /// <summary>Gets or sets the maximum allowed number of simultaneous remote bidirectional streams that can be
 82    /// accepted on an icerpc connection. When this limit is reached, the peer is not allowed to open any new
 83    /// bidirectional stream. Since an bidirectional stream is opened for each two-way invocation, the sending of the
 84    /// two-way invocation will be delayed until another two-way invocation's stream completes.</summary>
 85    /// <value>The maximum number of bidirectional streams. It can't be less than <c>1</c>. Defaults to <c>100</c>.
 86    /// </value>
 87    public int MaxIceRpcBidirectionalStreams
 88    {
 10789        get => _maxIceRpcBidirectionalStreams;
 090        set => _maxIceRpcBidirectionalStreams = value > 0 ? value :
 091            throw new ArgumentException(
 092                $"{nameof(MaxIceRpcBidirectionalStreams)} can't be less than 1",
 093                nameof(value));
 94    }
 95
 96    /// <summary>Gets or sets the maximum size of icerpc protocol header.</summary>
 97    /// <value>The maximum size in bytes of the header of an incoming request, response or control frame. Defaults to
 98    /// <c>16,383</c>, and the range of this value is <c>63</c> to <c>1,048,575</c>.</value>
 99    public int MaxIceRpcHeaderSize
 100    {
 712101        get => _maxIceRpcHeaderSize;
 4102        set => _maxIceRpcHeaderSize = IceRpcCheckMaxHeaderSize(value);
 103    }
 104
 105    /// <summary>Gets or sets the maximum allowed number of simultaneous remote unidirectional streams that can be
 106    /// accepted on an icerpc connection. When this limit is reached, the peer is not allowed to open any new
 107    /// unidirectional stream. Since an unidirectional stream is opened for each one-way invocation, the sending of the
 108    /// one-way invocation will be delayed until another one-way invocation's stream completes.</summary>
 109    /// <value>The maximum number of unidirectional streams. It can't be less than <c>1</c>. Defaults to
 110    /// <c>100</c>.</value>
 111    public int MaxIceRpcUnidirectionalStreams
 112    {
 107113        get => _maxIceRpcUnidirectionalStreams;
 0114        set => _maxIceRpcUnidirectionalStreams = value > 0 ? value :
 0115            throw new ArgumentException(
 0116                $"{nameof(MaxIceRpcUnidirectionalStreams)} can't be less than 1",
 0117                nameof(value));
 118    }
 119
 120    /// <summary>Gets or sets the minimum size of the segment requested from the <see cref="Pool" />.</summary>
 121    /// <value>The minimum size of the segment requested from the <see cref="Pool" />. Defaults to <c>4096</c>.</value>
 122    public int MinSegmentSize
 123    {
 1566124        get => _minSegmentSize;
 0125        set => _minSegmentSize = value >= 1024 ? value :
 0126            throw new ArgumentException($"{nameof(MinSegmentSize)} can't be less than 1KB", nameof(value));
 127    }
 128
 129    /// <summary>Gets or sets the <see cref="MemoryPool{T}" /> object used by the connection for allocating memory
 130    /// blocks.</summary>
 131    /// <value>A pool of memory blocks used for buffer management. Defaults to <see cref="MemoryPool{T}.Shared"
 132    /// />.</value>
 2811133    public MemoryPool<byte> Pool { get; set; } = MemoryPool<byte>.Shared;
 134
 135    /// <summary>The default value for <see cref="MaxIceRpcHeaderSize" />.</summary>
 136    internal const int DefaultMaxIceRpcHeaderSize = 16_383;
 137
 138    private const int IceMinFrameSize = 256;
 139
 1245140    private TimeSpan _iceIdleTimeout = TimeSpan.FromSeconds(60);
 1245141    private TimeSpan _inactivityTimeout = TimeSpan.FromMinutes(5);
 1245142    private int _maxDispatches = 100;
 1245143    private int _maxIceFrameSize = 1024 * 1024;
 1245144    private int _maxIceRpcBidirectionalStreams = MultiplexedConnectionOptions.DefaultMaxBidirectionalStreams;
 1245145    private int _maxIceRpcHeaderSize = DefaultMaxIceRpcHeaderSize;
 1245146    private int _maxIceRpcUnidirectionalStreams = MultiplexedConnectionOptions.DefaultMaxUnidirectionalStreams;
 1245147    private int _minSegmentSize = 4096;
 148
 10149    internal static int IceRpcCheckMaxHeaderSize(long value) => value is >= 63 and <= 1_048_575 ? (int)value :
 10150        throw new ArgumentOutOfRangeException(nameof(value), "value must be between 63 and 1,048,575");
 151}