< Summary

Information
Class: Ice.TCPConnectionInfo
Assembly: Ice
File(s): /_/csharp/src/Ice/Connection.cs
Tag: 91_21789722663
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 348
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 2
Total methods: 2
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%

File(s)

/_/csharp/src/Ice/Connection.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3#nullable enable
 4
 5namespace Ice;
 6
 7/// <summary>
 8/// Represents batch compression options for flushing queued batch requests.
 9/// </summary>
 10public enum CompressBatch
 11{
 12    /// <summary>
 13    /// Compress the batch requests.
 14    /// </summary>
 15    Yes,
 16
 17    /// <summary>
 18    /// Don't compress the batch requests.
 19    /// </summary>
 20    No,
 21
 22    /// <summary>
 23    /// Compress the batch requests if at least one request was made on a compressed proxy.
 24    /// </summary>
 25    BasedOnProxy
 26}
 27
 28/// <summary>
 29/// An application can use this delegate to receive notifications when a connection closes.
 30/// </summary>
 31public delegate void CloseCallback(Connection con);
 32
 33/// <summary>
 34/// Represents a connection that uses the Ice protocol.
 35/// </summary>
 36public interface Connection
 37{
 38    /// <summary>
 39    /// Aborts this connection.
 40    /// </summary>
 41    void abort();
 42
 43    /// <summary>
 44    /// Closes the connection gracefully after waiting for all outstanding invocations to complete.
 45    /// </summary>
 46    /// <returns>A task that completes when the connection is closed.</returns>
 47    /// <remarks>If closing the connection takes longer than the configured close timeout, the connection is aborted
 48    /// with a <see cref="CloseTimeoutException"/>.</remarks>
 49    Task closeAsync();
 50
 51    /// <summary>
 52    /// Creates a special proxy (a "fixed proxy") that always uses this connection.
 53    /// </summary>
 54    /// <param name="id">The identity of the target object.</param>
 55    /// <returns>A fixed proxy with the provided identity.</returns>
 56    ObjectPrx createProxy(Identity id);
 57
 58    /// <summary>
 59    /// Associates an object adapter with this connection. When a connection receives a request, it dispatches this
 60    /// request using its associated object adapter. If the associated object adapter is null, the connection
 61    /// rejects any incoming request with an <see cref="ObjectNotExistException" />.
 62    /// The default object adapter of an incoming connection is the object adapter that created this connection;
 63    /// the default object adapter of an outgoing connection is the communicator's default object adapter.
 64    /// </summary>
 65    /// <param name="adapter">The object adapter to associate with this connection.</param>
 66    /// <seealso cref="Communicator.getDefaultObjectAdapter"/>
 67    /// <seealso cref="getAdapter"/>
 68    void setAdapter(ObjectAdapter? adapter);
 69
 70    /// <summary>
 71    /// Gets the object adapter associated with this connection.
 72    /// </summary>
 73    /// <returns>The object adapter associated with this connection.</returns>
 74    /// <seealso cref="setAdapter"/>
 75    ObjectAdapter? getAdapter();
 76
 77    /// <summary>
 78    /// Gets the endpoint from which the connection was created.
 79    /// </summary>
 80    /// <returns>The endpoint from which the connection was created.</returns>
 81    Endpoint getEndpoint();
 82
 83    /// <summary>
 84    /// Flushes any pending batch requests for this connection.
 85    /// This means all batch requests invoked on fixed proxies associated with the connection.
 86    /// </summary>
 87    /// <param name="compress">Specifies whether or not the queued batch requests should be compressed before being sent
 88    /// over the wire.</param>
 89    void flushBatchRequests(CompressBatch compress);
 90
 91    /// <summary>
 92    /// Flushes any pending batch requests for this connection.
 93    /// This means all batch requests invoked on fixed proxies associated with the connection.
 94    /// </summary>
 95    /// <param name="compress">Specifies whether or not the queued batch requests should be compressed before being sent
 96    /// over the wire.</param>
 97    /// <param name="progress">Sent progress provider.</param>
 98    /// <param name="cancel">A cancellation token that receives the cancellation requests.</param>
 99    /// <returns>A task that completes when the flush completes.</returns>
 100    System.Threading.Tasks.Task flushBatchRequestsAsync(
 101        CompressBatch compress,
 102        System.IProgress<bool>? progress = null,
 103        System.Threading.CancellationToken cancel = default);
 104
 105    /// <summary>
 106    /// Sets a close callback on the connection. The callback is called by the connection when it's closed.
 107    /// The callback is called from the Ice thread pool associated with the connection.
 108    /// </summary>
 109    /// <param name="callback">The close callback object.</param>
 110    void setCloseCallback(CloseCallback callback);
 111
 112    /// <summary>
 113    /// Disables the inactivity check on this connection.
 114    /// </summary>
 115    void disableInactivityCheck();
 116
 117    /// <summary>
 118    /// Returns the connection type. This corresponds to the endpoint type, such as "tcp", "udp", etc.
 119    /// </summary>
 120    /// <returns>The type of the connection.</returns>
 121    string type();
 122
 123    /// <summary>
 124    /// Returns the connection information.
 125    /// </summary>
 126    /// <returns>The connection information.</returns>
 127    ConnectionInfo getInfo();
 128
 129    /// <summary>
 130    /// Sets the size of the receive and send buffers.
 131    /// </summary>
 132    /// <param name="rcvSize">The size of the receive buffer.</param>
 133    /// <param name="sndSize">The size of the send buffer.</param>
 134    void setBufferSize(int rcvSize, int sndSize);
 135
 136    /// <summary>
 137    /// Throws an exception that provides the reason for the closure of this connection. For example,
 138    /// this method throws <see cref="CloseConnectionException"/> when the connection was closed gracefully by the peer;
 139    /// It throws <see cref="ConnectionAbortedException"/> or <see cref="ConnectionClosedException"/>
 140    /// when the connection is aborted. This method does nothing if the connection is not yet closed.
 141    /// </summary>
 142    void throwException();
 143}
 144
 145/// <summary>
 146/// Base class for all connection info classes.
 147/// </summary>
 148public class ConnectionInfo
 149{
 150    /// <summary>
 151    /// The information of the underlying transport or null if there's no underlying transport.
 152    /// </summary>
 153    public readonly ConnectionInfo? underlying;
 154
 155    /// <summary>
 156    /// <see langword="true"/> if this is an incoming connection, <see langword="false"/> otherwise.
 157    /// </summary>
 158    public readonly bool incoming;
 159
 160    /// <summary>
 161    /// The name of the adapter associated with the connection.
 162    /// </summary>
 163    public readonly string adapterName;
 164
 165    /// <summary>
 166    /// The connection ID.
 167    /// </summary>
 168    public readonly string connectionId;
 169
 170    protected ConnectionInfo(ConnectionInfo underlying)
 171    {
 172        this.underlying = underlying;
 173        incoming = underlying.incoming;
 174        adapterName = underlying.adapterName;
 175        connectionId = underlying.connectionId;
 176    }
 177
 178    protected ConnectionInfo(bool incoming, string adapterName, string connectionId)
 179    {
 180        this.incoming = incoming;
 181        this.adapterName = adapterName;
 182        this.connectionId = connectionId;
 183    }
 184}
 185
 186/// <summary>
 187/// Provides access to the connection details of an IP connection.
 188/// </summary>
 189public class IPConnectionInfo : ConnectionInfo
 190{
 191    /// <summary>
 192    /// The local address.
 193    /// </summary>
 194    public readonly string localAddress;
 195
 196    /// <summary>
 197    /// The local port.
 198    /// </summary>
 199    public readonly int localPort;
 200
 201    /// <summary>
 202    /// The remote address.
 203    /// </summary>
 204    public readonly string remoteAddress;
 205
 206    /// <summary>
 207    /// The remote port.
 208    /// </summary>
 209    public readonly int remotePort;
 210
 211    protected IPConnectionInfo(
 212        bool incoming,
 213        string adapterName,
 214        string connectionId,
 215        string localAddress,
 216        int localPort,
 217        string remoteAddress,
 218        int remotePort)
 219        : base(incoming, adapterName, connectionId)
 220    {
 221        this.localAddress = localAddress;
 222        this.localPort = localPort;
 223        this.remoteAddress = remoteAddress;
 224        this.remotePort = remotePort;
 225    }
 226}
 227
 228/// <summary>
 229/// Provides access to the connection details of a TCP connection.
 230/// </summary>
 231public sealed class TCPConnectionInfo : IPConnectionInfo
 232{
 233    /// <summary>
 234    /// The size of the receive buffer.
 235    /// </summary>
 236    public readonly int rcvSize;
 237
 238    /// <summary>
 239    /// The size of the send buffer.
 240    /// </summary>
 241    public readonly int sndSize;
 242
 243    internal TCPConnectionInfo(
 244        bool incoming,
 245        string adapterName,
 246        string connectionId,
 247        string localAddress,
 248        int localPort,
 249        string remoteAddress,
 250        int remotePort,
 251        int rcvSize,
 252        int sndSize)
 1253        : base(incoming, adapterName, connectionId, localAddress, localPort, remoteAddress, remotePort)
 254    {
 1255        this.rcvSize = rcvSize;
 1256        this.sndSize = sndSize;
 1257    }
 258
 259    internal TCPConnectionInfo(bool incoming, string adapterName, string connectionId)
 1260        : this(
 1261            incoming,
 1262            adapterName,
 1263            connectionId,
 1264            localAddress: "",
 1265            localPort: -1,
 1266            remoteAddress: "",
 1267            remotePort: -1,
 1268            rcvSize: 0,
 1269            sndSize: 0)
 270    {
 1271    }
 272}
 273
 274/// <summary>
 275/// Provides access to the connection details of a UDP connection.
 276/// </summary>
 277public sealed class UDPConnectionInfo : IPConnectionInfo
 278{
 279    /// <summary>
 280    /// The multicast address.
 281    /// </summary>
 282    public readonly string mcastAddress;
 283
 284    /// <summary>
 285    /// The multicast port.
 286    /// </summary>
 287    public readonly int mcastPort;
 288
 289    /// <summary>
 290    /// The size of the receive buffer.
 291    /// </summary>
 292    public readonly int rcvSize;
 293
 294    /// <summary>
 295    /// The size of the send buffer.
 296    /// </summary>
 297    public readonly int sndSize;
 298
 299    internal UDPConnectionInfo(
 300        bool incoming,
 301        string adapterName,
 302        string connectionId,
 303        string localAddress,
 304        int localPort,
 305        string remoteAddress,
 306        int remotePort,
 307        string mcastAddress,
 308        int mcastPort,
 309        int rcvSize,
 310        int sndSize)
 311        : base(incoming, adapterName, connectionId, localAddress, localPort, remoteAddress, remotePort)
 312    {
 313        this.mcastAddress = mcastAddress;
 314        this.mcastPort = mcastPort;
 315        this.rcvSize = rcvSize;
 316        this.sndSize = sndSize;
 317    }
 318
 319    internal UDPConnectionInfo(bool incoming, string adapterName, string connectionId)
 320        : this(
 321            incoming,
 322            adapterName,
 323            connectionId,
 324            localAddress: "",
 325            localPort: -1,
 326            remoteAddress: "",
 327            remotePort: -1,
 328            mcastAddress: "",
 329            mcastPort: -1,
 330            rcvSize: 0,
 331            sndSize: 0)
 332    {
 333    }
 334}
 335
 336/// <summary>
 337/// Provides access to the connection details of a WebSocket connection.
 338/// </summary>
 339public sealed class WSConnectionInfo : ConnectionInfo
 340{
 341    /// <summary>
 342    /// The headers from the HTTP upgrade request.
 343    /// </summary>
 344    public readonly Dictionary<string, string> headers;
 345
 346    internal WSConnectionInfo(ConnectionInfo underlying, Dictionary<string, string> headers)
 347        : base(underlying) => this.headers = headers;
 348}