< Summary

Information
Class: Ice.Internal.TcpAcceptor
Assembly: Ice
File(s): /_/csharp/src/Ice/Internal/TcpAcceptor.cs
Tag: 125_37167941578
Line coverage
75%
Covered lines: 46
Uncovered lines: 15
Coverable lines: 61
Total lines: 129
Line coverage: 75.4%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage
90%
Covered methods: 9
Fully covered methods: 3
Total methods: 10
Method coverage: 90%
Full method coverage: 30%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
close()75%4471.43%
listen()100%1162.5%
startAccept(...)100%1180%
finishAccept()100%2262.5%
accept()50%2283.33%
protocol()100%210%
ToString()100%11100%
toDetailedString()100%11100%
effectivePort()100%11100%
.ctor(...)100%1180%

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, _bufSize));
 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");
 1103        _bufSize = new TcpBufSize(instance.properties());
 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, _bufSize.rcvSize, _bufSize.sndSize, _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 readonly TcpBufSize _bufSize;
 127    private IPEndPoint _addr;
 128    private IAsyncResult _result;
 129}