< Summary

Information
Class: IceRpc.ClientProtocolConnectionFactory
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/ClientProtocolConnectionFactory.cs
Tag: 701_22528036593
Line coverage
100%
Covered lines: 56
Uncovered lines: 0
Coverable lines: 56
Total lines: 104
Line coverage: 100%
Branch coverage
93%
Covered branches: 15
Total branches: 16
Branch coverage: 93.7%
Method coverage
100%
Covered methods: 2
Total methods: 2
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)90%1010100%
CreateConnection(...)100%66100%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Internal;
 4using IceRpc.Transports;
 5using Microsoft.Extensions.Logging;
 6using Microsoft.Extensions.Logging.Abstractions;
 7using System.Net.Security;
 8
 9namespace IceRpc;
 10
 11/// <summary>Default implementation of <see cref="IClientProtocolConnectionFactory" />.</summary>
 12public sealed class ClientProtocolConnectionFactory : IClientProtocolConnectionFactory
 13{
 14    private readonly SslClientAuthenticationOptions? _clientAuthenticationOptions;
 15    private readonly ConnectionOptions _connectionOptions;
 16    private readonly IDuplexClientTransport _duplexClientTransport;
 17    private readonly DuplexConnectionOptions _duplexConnectionOptions;
 18    private readonly ILogger _logger;
 19    private readonly IMultiplexedClientTransport _multiplexedClientTransport;
 20    private readonly MultiplexedConnectionOptions _multiplexedConnectionOptions;
 21
 22    /// <summary>Constructs a client protocol connection factory.</summary>
 23    /// <param name="connectionOptions">The connection options.</param>
 24    /// <param name="connectTimeout">The connect timeout.</param>
 25    /// <param name="clientAuthenticationOptions">The client authentication options.</param>
 26    /// <param name="duplexClientTransport">The duplex client transport. <see langword="null" /> is equivalent to <see
 27    /// cref="IDuplexClientTransport.Default" />.</param>
 28    /// <param name="multiplexedClientTransport">The multiplexed client transport. <see langword="null" /> is equivalent
 29    /// to <see cref="IMultiplexedClientTransport.Default" />.</param>
 30    /// <param name="logger">The logger. <see langword="null" /> is equivalent to <see cref="NullLogger.Instance" />.
 31    /// </param>
 8932    public ClientProtocolConnectionFactory(
 8933        ConnectionOptions connectionOptions,
 8934        TimeSpan connectTimeout,
 8935        SslClientAuthenticationOptions? clientAuthenticationOptions = null,
 8936        IDuplexClientTransport? duplexClientTransport = null,
 8937        IMultiplexedClientTransport? multiplexedClientTransport = null,
 8938        ILogger? logger = null)
 8939    {
 8940        _clientAuthenticationOptions = clientAuthenticationOptions;
 8941        _connectionOptions = connectionOptions;
 42
 8943        _duplexClientTransport = duplexClientTransport ?? IDuplexClientTransport.Default;
 8944        _duplexConnectionOptions = new DuplexConnectionOptions
 8945        {
 8946            Pool = connectionOptions.Pool,
 8947            MinSegmentSize = connectionOptions.MinSegmentSize,
 8948        };
 49
 8950        _multiplexedClientTransport = multiplexedClientTransport ?? IMultiplexedClientTransport.Default;
 51
 52        // If the dispatcher is null, we don't allow the peer to open streams for incoming requests. The only stream
 53        // which is accepted locally is the control stream created by the peer.
 8954        _multiplexedConnectionOptions = new MultiplexedConnectionOptions
 8955        {
 8956            HandshakeTimeout = connectTimeout,
 8957
 8958            MaxBidirectionalStreams = connectionOptions.Dispatcher is null ? 0 :
 8959                connectionOptions.MaxIceRpcBidirectionalStreams,
 8960
 8961            // Add an additional stream for the icerpc protocol control stream.
 8962            MaxUnidirectionalStreams = connectionOptions.Dispatcher is null ? 1 :
 8963                connectionOptions.MaxIceRpcUnidirectionalStreams + 1,
 8964
 8965            Pool = connectionOptions.Pool,
 8966            MinSegmentSize = connectionOptions.MinSegmentSize,
 8967        };
 68
 8969        _logger = logger ?? NullLogger.Instance;
 8970    }
 71
 72    /// <summary>Creates a protocol connection to the specified server address.</summary>
 73    /// <param name="serverAddress">The address of the server.</param>
 74    /// <returns>The new protocol connection.</returns>
 75    /// <remarks>The protocol connection returned by this factory method is not connected. The caller must call
 76    /// <see cref="IProtocolConnection.ConnectAsync" /> exactly once on this connection before calling
 77    /// <see cref="IInvoker.InvokeAsync" />.</remarks>
 78    public IProtocolConnection CreateConnection(ServerAddress serverAddress)
 9279    {
 9280        IProtocolConnection connection =
 9281            serverAddress.Protocol == Protocol.Ice ?
 9282                new IceProtocolConnection(
 9283                    _duplexClientTransport.CreateConnection(
 9284                        serverAddress,
 9285                        _duplexConnectionOptions,
 9286                        _clientAuthenticationOptions),
 9287                    transportConnectionInformation: null,
 9288                    _connectionOptions) :
 9289                new IceRpcProtocolConnection(
 9290                    _multiplexedClientTransport.CreateConnection(
 9291                        serverAddress,
 9292                        _multiplexedConnectionOptions,
 9293                        _clientAuthenticationOptions),
 9294                    transportConnectionInformation: null,
 9295                    _connectionOptions,
 9296                    taskExceptionObserver: _logger == NullLogger.Instance ? null :
 9297                        new LogTaskExceptionObserver(_logger));
 98
 9299        connection = new MetricsProtocolConnectionDecorator(connection, Metrics.ClientMetrics, connectStarted: false);
 100
 92101        return _logger == NullLogger.Instance ? connection :
 92102            new LogProtocolConnectionDecorator(connection, serverAddress, remoteNetworkAddress: null, _logger);
 92103    }
 104}