< Summary

Information
Class: IceRpc.Transports.Tcp.TcpServerTransport
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Transports/Tcp/TcpServerTransport.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 64
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage
100%
Covered methods: 5
Total methods: 5
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Name()100%11100%
.ctor()100%11100%
.ctor(...)100%11100%
Listen(...)100%1212100%
IsValidTransportName()100%66100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Transports/Tcp/TcpServerTransport.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Transports.Tcp.Internal;
 4using System.Net.Security;
 5
 6namespace IceRpc.Transports.Tcp;
 7
 8/// <summary>Implements <see cref="IDuplexServerTransport" /> for the tcp transport.</summary>
 9public class TcpServerTransport : IDuplexServerTransport
 10{
 11    /// <inheritdoc/>
 21812    public string Name => TcpName;
 13
 14    private const string SslName = "ssl";
 15    private const string TcpName = "tcp";
 16
 17    private readonly TcpServerTransportOptions _options;
 18
 19    /// <summary>Constructs a <see cref="TcpServerTransport" />.</summary>
 20    public TcpServerTransport()
 4121        : this(new TcpServerTransportOptions())
 4122    {
 4123    }
 24
 25    /// <summary>Constructs a <see cref="TcpServerTransport" />.</summary>
 26    /// <param name="options">The transport options.</param>
 48227    public TcpServerTransport(TcpServerTransportOptions options) => _options = options;
 28
 29    /// <inheritdoc/>
 30    public IListener<IDuplexConnection> Listen(
 31        ServerAddress serverAddress,
 32        DuplexConnectionOptions options,
 33        SslServerAuthenticationOptions? serverAuthenticationOptions)
 26034    {
 26035        if (serverAddress.Transport is string transport && !IsValidTransportName(transport, serverAddress.Protocol))
 636        {
 637            throw new NotSupportedException(
 638                $"The Tcp server transport does not support server addresses with transport '{transport}'.");
 39        }
 40
 25441        if (serverAddress.Params.Count > 0)
 1042        {
 1043            throw new ArgumentException(
 1044                $"The server address '{serverAddress}' contains parameters that are not valid for the Tcp server transpo
 1045                nameof(serverAddress));
 46        }
 47
 24448        if (serverAddress.Transport is null)
 19849        {
 19850            serverAddress = serverAddress with { Transport = Name };
 19851        }
 4652        else if (serverAddress.Transport == SslName && serverAuthenticationOptions is null)
 253        {
 254            throw new ArgumentNullException(
 255                nameof(serverAuthenticationOptions),
 256                "The Ssl server transport requires the Ssl server authentication options to be set.");
 57        }
 58
 24259        return new TcpListener(serverAddress, options, serverAuthenticationOptions, _options);
 60
 61        static bool IsValidTransportName(string transportName, Protocol protocol) =>
 5662            protocol == Protocol.Ice ? transportName is TcpName or SslName : transportName is TcpName;
 23063    }
 64}