< Summary

Information
Class: Ice.Internal.TcpAcceptor
Assembly: Ice
File(s): /home/runner/work/ice/ice/csharp/src/Ice/Internal/TcpAcceptor.cs
Tag: 71_18251537082
Line coverage
75%
Covered lines: 45
Uncovered lines: 15
Coverable lines: 60
Total lines: 128
Line coverage: 75%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage
90%
Covered methods: 9
Total methods: 10
Method coverage: 90%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
close()75%4.37471.43%
listen()100%1.05162.5%
startAccept(...)100%1.01180%
finishAccept()100%2.21262.5%
accept()50%2.02283.33%
protocol()100%210%
ToString()100%11100%
toDetailedString()100%11100%
effectivePort()100%11100%
.ctor(...)100%1.01178.57%

File(s)

/home/runner/work/ice/ice/csharp/src/Ice/Internal/TcpAcceptor.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Net;
 4using System.Net.Sockets;
 5using System.Text;
 6
 7namespace Ice.Internal;
 8
 9internal class TcpAcceptor : Acceptor
 10{
 11    public virtual void close()
 12    {
 113        if (_acceptFd != null)
 14        {
 015            Network.closeSocketNoThrow(_acceptFd);
 016            _acceptFd = null;
 17        }
 118        if (_fd != null)
 19        {
 120            Network.closeSocketNoThrow(_fd);
 121            _fd = null;
 22        }
 123    }
 24
 25    public virtual EndpointI listen()
 26    {
 27        try
 28        {
 129            _addr = Network.doBind(_fd, _addr);
 130            Network.doListen(_fd, _backlog);
 131        }
 032        catch (SystemException)
 33        {
 034            _fd = null;
 035            throw;
 36        }
 137        _endpoint = _endpoint.endpoint(this);
 138        return _endpoint;
 39    }
 40
 41    public virtual bool startAccept(AsyncCallback callback, object state)
 42    {
 43        try
 44        {
 145            _result = _fd.BeginAccept(
 146                (IAsyncResult result) =>
 147                {
 148                    if (!result.CompletedSynchronously)
 149                    {
 150                        callback(result.AsyncState);
 151                    }
 152                },
 153                state);
 154        }
 055        catch (System.Exception ex)
 56        {
 057            throw new Ice.SocketException(ex);
 58        }
 159        return _result.CompletedSynchronously;
 60    }
 61
 62    public virtual void finishAccept()
 63    {
 164        if (_fd != null)
 65        {
 166            _acceptFd = null;
 67            try
 68            {
 169                _acceptFd = _fd.EndAccept(_result);
 170            }
 071            catch (System.Exception ex)
 72            {
 073                _acceptError = new Ice.SocketException(ex);
 074            }
 75        }
 176    }
 77
 78    public virtual Transceiver accept()
 79    {
 180        if (_acceptFd == null)
 81        {
 082            throw _acceptError;
 83        }
 84
 185        Socket acceptFd = _acceptFd;
 186        _acceptFd = null;
 187        _acceptError = null;
 188        return new TcpTransceiver(_instance, new StreamSocket(_instance, acceptFd));
 89    }
 90
 091    public string protocol() => _instance.protocol();
 92
 193    public override string ToString() => Network.addrToString(_addr);
 94
 195    public string toDetailedString() => $"local address = {this}";
 96
 197    internal int effectivePort() => _addr.Port;
 98
 199    internal TcpAcceptor(TcpEndpointI endpoint, ProtocolInstance instance, string host, int port)
 100    {
 1101        _endpoint = endpoint;
 1102        _instance = instance;
 1103        _backlog = instance.properties().getIcePropertyAsInt("Ice.TCP.Backlog");
 104
 105        try
 106        {
 1107            int protocol = _instance.protocolSupport();
 1108            _addr = (IPEndPoint)Network.getAddressForServer(host, port, protocol, _instance.preferIPv6());
 1109            _fd = Network.createServerSocket(false, _addr.AddressFamily, protocol);
 1110            Network.setBlock(_fd, false);
 1111            Network.setTcpBufSize(_fd, _instance);
 1112        }
 0113        catch (System.Exception)
 114        {
 0115            _fd = null;
 0116            throw;
 117        }
 1118    }
 119
 120    private TcpEndpointI _endpoint;
 121    private readonly ProtocolInstance _instance;
 122    private Socket _fd;
 123    private Socket _acceptFd;
 124    private Ice.SocketException _acceptError;
 125    private readonly int _backlog;
 126    private IPEndPoint _addr;
 127    private IAsyncResult _result;
 128}