< 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: 701_22528036593
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/>
 10812    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()
 3221        : this(new TcpServerTransportOptions())
 3222    {
 3223    }
 24
 25    /// <summary>Constructs a <see cref="TcpServerTransport" />.</summary>
 26    /// <param name="options">The transport options.</param>
 26427    public TcpServerTransport(TcpServerTransportOptions options) => _options = options;
 28
 29    /// <inheritdoc/>
 30    public IListener<IDuplexConnection> Listen(
 31        ServerAddress serverAddress,
 32        DuplexConnectionOptions options,
 33        SslServerAuthenticationOptions? serverAuthenticationOptions)
 13134    {
 13135        if (serverAddress.Transport is string transport && !IsValidTransportName(transport, serverAddress.Protocol))
 336        {
 337            throw new NotSupportedException(
 338                $"The Tcp server transport does not support server addresses with transport '{transport}'.");
 39        }
 40
 12841        if (serverAddress.Params.Count > 0)
 542        {
 543            throw new ArgumentException(
 544                $"The server address '{serverAddress}' contains parameters that are not valid for the Tcp server transpo
 545                nameof(serverAddress));
 46        }
 47
 12348        if (serverAddress.Transport is null)
 9949        {
 9950            serverAddress = serverAddress with { Transport = Name };
 9951        }
 2452        else if (serverAddress.Transport == SslName && serverAuthenticationOptions is null)
 153        {
 154            throw new ArgumentNullException(
 155                nameof(serverAuthenticationOptions),
 156                "The SSL server transport requires the SSL server authentication options to be set.");
 57        }
 58
 12259        return new TcpListener(serverAddress, options, serverAuthenticationOptions, _options);
 60
 61        static bool IsValidTransportName(string transportName, Protocol protocol) =>
 2962            protocol == Protocol.Ice ? transportName is TcpName or SslName : transportName is TcpName;
 11663    }
 64}