< Summary

Information
Class: Ice.Internal.TcpAcceptor
Assembly: Ice
File(s): /_/csharp/src/Ice/Internal/TcpAcceptor.cs
Tag: 91_21789722663
Line coverage
75%
Covered lines: 45
Uncovered lines: 15
Coverable lines: 60
Total lines: 127
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)

/_/csharp/src/Ice/Internal/TcpAcceptor.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Net;
 4using System.Net.Sockets;
 5
 6namespace Ice.Internal;
 7
 8internal class TcpAcceptor : Acceptor
 9{
 10    public virtual void close()
 11    {
 112        if (_acceptFd != null)
 13        {
 014            Network.closeSocketNoThrow(_acceptFd);
 015            _acceptFd = null;
 16        }
 117        if (_fd != null)
 18        {
 119            Network.closeSocketNoThrow(_fd);
 120            _fd = null;
 21        }
 122    }
 23
 24    public virtual EndpointI listen()
 25    {
 26        try
 27        {
 128            _addr = Network.doBind(_fd, _addr);
 129            Network.doListen(_fd, _backlog);
 130        }
 031        catch (SystemException)
 32        {
 033            _fd = null;
 034            throw;
 35        }
 136        _endpoint = _endpoint.endpoint(this);
 137        return _endpoint;
 38    }
 39
 40    public virtual bool startAccept(AsyncCallback callback, object state)
 41    {
 42        try
 43        {
 144            _result = _fd.BeginAccept(
 145                (IAsyncResult result) =>
 146                {
 147                    if (!result.CompletedSynchronously)
 148                    {
 149                        callback(result.AsyncState);
 150                    }
 151                },
 152                state);
 153        }
 054        catch (System.Exception ex)
 55        {
 056            throw new Ice.SocketException(ex);
 57        }
 158        return _result.CompletedSynchronously;
 59    }
 60
 61    public virtual void finishAccept()
 62    {
 163        if (_fd != null)
 64        {
 165            _acceptFd = null;
 66            try
 67            {
 168                _acceptFd = _fd.EndAccept(_result);
 169            }
 070            catch (System.Exception ex)
 71            {
 072                _acceptError = new Ice.SocketException(ex);
 073            }
 74        }
 175    }
 76
 77    public virtual Transceiver accept()
 78    {
 179        if (_acceptFd == null)
 80        {
 081            throw _acceptError;
 82        }
 83
 184        Socket acceptFd = _acceptFd;
 185        _acceptFd = null;
 186        _acceptError = null;
 187        return new TcpTransceiver(_instance, new StreamSocket(_instance, acceptFd));
 88    }
 89
 090    public string protocol() => _instance.protocol();
 91
 192    public override string ToString() => Network.addrToString(_addr);
 93
 194    public string toDetailedString() => $"local address = {this}";
 95
 196    internal int effectivePort() => _addr.Port;
 97
 198    internal TcpAcceptor(TcpEndpointI endpoint, ProtocolInstance instance, string host, int port)
 99    {
 1100        _endpoint = endpoint;
 1101        _instance = instance;
 1102        _backlog = instance.properties().getIcePropertyAsInt("Ice.TCP.Backlog");
 103
 104        try
 105        {
 1106            int protocol = _instance.protocolSupport();
 1107            _addr = (IPEndPoint)Network.getAddressForServer(host, port, protocol, _instance.preferIPv6());
 1108            _fd = Network.createServerSocket(false, _addr.AddressFamily, protocol);
 1109            Network.setBlock(_fd, false);
 1110            Network.setTcpBufSize(_fd, _instance);
 1111        }
 0112        catch (System.Exception)
 113        {
 0114            _fd = null;
 0115            throw;
 116        }
 1117    }
 118
 119    private TcpEndpointI _endpoint;
 120    private readonly ProtocolInstance _instance;
 121    private Socket _fd;
 122    private Socket _acceptFd;
 123    private Ice.SocketException _acceptError;
 124    private readonly int _backlog;
 125    private IPEndPoint _addr;
 126    private IAsyncResult _result;
 127}