< 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: 1321_24790053727
Line coverage
87%
Covered lines: 27
Uncovered lines: 4
Coverable lines: 31
Total lines: 64
Line coverage: 87%
Branch coverage
88%
Covered branches: 16
Total branches: 18
Branch coverage: 88.8%
Method coverage
100%
Covered methods: 4
Fully covered methods: 3
Total methods: 4
Method coverage: 100%
Full method coverage: 75%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_DefaultName()100%11100%
.ctor()100%11100%
.ctor(...)100%11100%
Listen(...)88.88%191884.61%

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/>
 1112    public string DefaultName => "tcp";
 13
 14    private readonly TcpServerTransportOptions _options;
 15
 16    /// <summary>Constructs a <see cref="TcpServerTransport" />.</summary>
 17    public TcpServerTransport()
 2718        : this(new TcpServerTransportOptions())
 2719    {
 2720    }
 21
 22    /// <summary>Constructs a <see cref="TcpServerTransport" />.</summary>
 23    /// <param name="options">The transport options.</param>
 25424    public TcpServerTransport(TcpServerTransportOptions options) => _options = options;
 25
 26    /// <inheritdoc/>
 27    public IListener<IDuplexConnection> Listen(
 28        TransportAddress transportAddress,
 29        DuplexConnectionOptions options,
 30        SslServerAuthenticationOptions? serverAuthenticationOptions)
 13031    {
 32        // "ssl" is only accepted for the ice protocol, identified by the ALPN.
 13033        if (transportAddress.TransportName == "ssl")
 234        {
 235            if (serverAuthenticationOptions is null)
 036            {
 037                throw new ArgumentNullException(
 038                    nameof(serverAuthenticationOptions),
 039                    "The SSL server transport requires the SSL server authentication options to be set.");
 40            }
 241            else if (serverAuthenticationOptions?.ApplicationProtocols
 242                is not List<SslApplicationProtocol> alpnProtocols ||
 243                alpnProtocols.Count != 1 ||
 244                alpnProtocols[0] != new SslApplicationProtocol("ice"))
 145            {
 146                throw new NotSupportedException(
 147                    "The 'ssl' transport name is only supported with the ice protocol.");
 48            }
 149        }
 12850        else if (transportAddress.TransportName is string name && name != "tcp")
 151        {
 152            throw new NotSupportedException($"The TCP server transport does not support transport '{name}'.");
 53        }
 54
 12855        if (transportAddress.Params.Count > 0)
 456        {
 457            throw new ArgumentException(
 458                "The transport address contains parameters that are not valid for the TCP server transport.",
 459                nameof(transportAddress));
 60        }
 61
 12462        return new TcpListener(transportAddress, options, serverAuthenticationOptions, _options);
 11963    }
 64}