< Summary

Information
Class: IceRpc.Transports.Coloc.Internal.ColocServerTransport
Assembly: IceRpc.Transports.Coloc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Transports.Coloc/Internal/ColocServerTransport.cs
Tag: 1856_27024993493
Line coverage
87%
Covered lines: 29
Uncovered lines: 4
Coverable lines: 33
Total lines: 67
Line coverage: 87.8%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
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%
Listen(...)80%101083.33%
OnDispose()100%11100%
.ctor(...)100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Transports.Coloc/Internal/ColocServerTransport.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Collections.Concurrent;
 4using System.Net.Security;
 5
 6namespace IceRpc.Transports.Coloc.Internal;
 7
 8/// <summary>Implements <see cref="IDuplexServerTransport" /> for the coloc transport.</summary>
 9internal class ColocServerTransport : IDuplexServerTransport
 10{
 11    /// <inheritdoc/>
 13812    public string DefaultName => ColocTransport.Name;
 13
 14    private readonly ConcurrentDictionary<(string Host, ushort Port), ColocListener> _listeners;
 15    private readonly ColocTransportOptions _options;
 16
 17    /// <inheritdoc/>
 18    public IListener<IDuplexConnection> Listen(
 19        TransportAddress transportAddress,
 20        DuplexConnectionOptions options,
 21        SslServerAuthenticationOptions? serverAuthenticationOptions)
 54622    {
 54623        if (serverAuthenticationOptions is not null)
 024        {
 025            throw new NotSupportedException("The Coloc server transport does not support SSL.");
 26        }
 27
 54628        if (transportAddress.TransportName is string name && name != DefaultName)
 029        {
 030            throw new NotSupportedException($"The Coloc server transport does not support transport '{name}'.");
 31        }
 32
 54633        if (transportAddress.Params.Count > 0)
 234        {
 235            throw new ArgumentException(
 236                "The transport address contains parameters that are not valid for the Coloc server transport.",
 237                nameof(transportAddress));
 38        }
 39
 54440        var key = (transportAddress.Host, transportAddress.Port);
 41
 54442        var listener = new ColocListener(
 54443            transportAddress,
 54444            onDispose: OnDispose,
 54445            colocTransportOptions: _options,
 54446            duplexConnectionOptions: options);
 47
 54448        if (!_listeners.TryAdd(key, listener))
 249        {
 50            // The listener was never published; release its resources before reporting the collision.
 251            listener.Dispose();
 252            throw new IceRpcException(IceRpcError.AddressInUse);
 53        }
 54254        return listener;
 55
 56        void OnDispose(ColocListener disposedListener) =>
 54457            _listeners.TryRemove(new KeyValuePair<(string, ushort), ColocListener>(key, disposedListener));
 54258    }
 59
 53660    internal ColocServerTransport(
 53661        ConcurrentDictionary<(string Host, ushort Port), ColocListener> listeners,
 53662        ColocTransportOptions options)
 53663    {
 53664        _listeners = listeners;
 53665        _options = options;
 53666    }
 67}