< Summary

Information
Class: Ice.IPConnectionInfo
Assembly: Ice
File(s): /_/csharp/src/Ice/Connection.cs
Tag: 125_37167941578
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 358
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 1
Fully covered methods: 1
Total methods: 1
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.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    /// <exception cref="CommunicatorDestroyedException">Thrown when the communicator has been destroyed.</exception>
 57    ObjectPrx createProxy(Identity id);
 58
 59    /// <summary>
 60    /// Associates an object adapter with this connection. When a connection receives a request, it dispatches this
 61    /// request using its associated object adapter. If the associated object adapter is null, the connection
 62    /// rejects any incoming request with an <see cref="ObjectNotExistException" />.
 63    /// The default object adapter of an incoming connection is the object adapter that created this connection;
 64    /// the default object adapter of an outgoing connection is the communicator's default object adapter.
 65    /// </summary>
 66    /// <param name="adapter">The object adapter to associate with this connection.</param>
 67    /// <exception cref="InvalidOperationException">Thrown when this connection is an incoming connection: you can
 68    /// only call this method on outgoing (client) connections.</exception>
 69    /// <seealso cref="Communicator.getDefaultObjectAdapter"/>
 70    /// <seealso cref="getAdapter"/>
 71    void setAdapter(ObjectAdapter? adapter);
 72
 73    /// <summary>
 74    /// Gets the object adapter associated with this connection.
 75    /// </summary>
 76    /// <returns>The object adapter associated with this connection.</returns>
 77    /// <seealso cref="setAdapter"/>
 78    ObjectAdapter? getAdapter();
 79
 80    /// <summary>
 81    /// Gets the endpoint from which the connection was created.
 82    /// </summary>
 83    /// <returns>The endpoint from which the connection was created.</returns>
 84    Endpoint getEndpoint();
 85
 86    /// <summary>
 87    /// Flushes any pending batch requests for this connection.
 88    /// This means all batch requests invoked on fixed proxies associated with the connection.
 89    /// </summary>
 90    /// <param name="compress">Specifies whether or not the queued batch requests should be compressed before being sent
 91    /// over the wire.</param>
 92    /// <exception cref="LocalException">Thrown when the flush fails. For example, this method throws
 93    /// <see cref="CommunicatorDestroyedException" /> when the communicator has been destroyed.</exception>
 94    void flushBatchRequests(CompressBatch compress);
 95
 96    /// <summary>
 97    /// Flushes any pending batch requests for this connection.
 98    /// This means all batch requests invoked on fixed proxies associated with the connection.
 99    /// </summary>
 100    /// <param name="compress">Specifies whether or not the queued batch requests should be compressed before being sent
 101    /// over the wire.</param>
 102    /// <param name="progress">Sent progress provider.</param>
 103    /// <param name="cancel">A cancellation token that receives the cancellation requests.</param>
 104    /// <returns>A task that completes when the flush completes.</returns>
 105    /// <exception cref="CommunicatorDestroyedException">Thrown synchronously when the communicator has been
 106    /// destroyed.</exception>
 107    System.Threading.Tasks.Task flushBatchRequestsAsync(
 108        CompressBatch compress,
 109        System.IProgress<bool>? progress = null,
 110        System.Threading.CancellationToken cancel = default);
 111
 112    /// <summary>
 113    /// Sets a close callback on the connection. The callback is called by the connection when it's closed.
 114    /// The callback is called from the Ice thread pool associated with the connection.
 115    /// </summary>
 116    /// <param name="callback">The close callback object.</param>
 117    void setCloseCallback(CloseCallback callback);
 118
 119    /// <summary>
 120    /// Disables the inactivity check on this connection.
 121    /// </summary>
 122    void disableInactivityCheck();
 123
 124    /// <summary>
 125    /// Returns the connection type. This corresponds to the endpoint type, such as "tcp", "udp", etc.
 126    /// </summary>
 127    /// <returns>The type of the connection.</returns>
 128    string type();
 129
 130    /// <summary>
 131    /// Returns the connection information.
 132    /// </summary>
 133    /// <returns>The connection information.</returns>
 134    ConnectionInfo getInfo();
 135
 136    /// <summary>
 137    /// Sets the size of the receive and send buffers.
 138    /// </summary>
 139    /// <param name="rcvSize">The size of the receive buffer.</param>
 140    /// <param name="sndSize">The size of the send buffer.</param>
 141    void setBufferSize(int rcvSize, int sndSize);
 142
 143    /// <summary>
 144    /// Throws the exception that provides the reason for the closure of this connection. Does nothing if the
 145    /// connection is not yet closing or closed.
 146    /// </summary>
 147    /// <exception cref="CloseConnectionException">Thrown when the connection was closed gracefully by the
 148    /// peer.</exception>
 149    /// <exception cref="ConnectionAbortedException">Thrown when the connection is aborted with <see cref="abort"/>.
 150    /// </exception>
 151    void throwException();
 152}
 153
 154/// <summary>
 155/// Base class for all connection info classes.
 156/// </summary>
 157public class ConnectionInfo
 158{
 159    /// <summary>
 160    /// The information of the underlying transport or null if there's no underlying transport.
 161    /// </summary>
 162    public readonly ConnectionInfo? underlying;
 163
 164    /// <summary>
 165    /// <see langword="true"/> if this is an incoming connection; otherwise, <see langword="false"/>.
 166    /// </summary>
 167    public readonly bool incoming;
 168
 169    /// <summary>
 170    /// The name of the adapter associated with the connection.
 171    /// </summary>
 172    public readonly string adapterName;
 173
 174    /// <summary>
 175    /// The connection ID.
 176    /// </summary>
 177    public readonly string connectionId;
 178
 179    protected ConnectionInfo(ConnectionInfo underlying)
 180    {
 181        this.underlying = underlying;
 182        incoming = underlying.incoming;
 183        adapterName = underlying.adapterName;
 184        connectionId = underlying.connectionId;
 185    }
 186
 187    protected ConnectionInfo(bool incoming, string adapterName, string connectionId)
 188    {
 189        this.incoming = incoming;
 190        this.adapterName = adapterName;
 191        this.connectionId = connectionId;
 192    }
 193}
 194
 195/// <summary>
 196/// Provides access to the connection details of an IP connection.
 197/// </summary>
 198public class IPConnectionInfo : ConnectionInfo
 199{
 200    /// <summary>
 201    /// The local address.
 202    /// </summary>
 203    public readonly string localAddress;
 204
 205    /// <summary>
 206    /// The local port.
 207    /// </summary>
 208    public readonly int localPort;
 209
 210    /// <summary>
 211    /// The remote address.
 212    /// </summary>
 213    public readonly string remoteAddress;
 214
 215    /// <summary>
 216    /// The remote port.
 217    /// </summary>
 218    public readonly int remotePort;
 219
 220    protected IPConnectionInfo(
 221        bool incoming,
 222        string adapterName,
 223        string connectionId,
 224        string localAddress,
 225        int localPort,
 226        string remoteAddress,
 227        int remotePort)
 1228        : base(incoming, adapterName, connectionId)
 229    {
 1230        this.localAddress = localAddress;
 1231        this.localPort = localPort;
 1232        this.remoteAddress = remoteAddress;
 1233        this.remotePort = remotePort;
 1234    }
 235}
 236
 237/// <summary>
 238/// Provides access to the connection details of a TCP connection.
 239/// </summary>
 240public sealed class TCPConnectionInfo : IPConnectionInfo
 241{
 242    /// <summary>
 243    /// The size of the receive buffer.
 244    /// </summary>
 245    public readonly int rcvSize;
 246
 247    /// <summary>
 248    /// The size of the send buffer.
 249    /// </summary>
 250    public readonly int sndSize;
 251
 252    internal TCPConnectionInfo(
 253        bool incoming,
 254        string adapterName,
 255        string connectionId,
 256        string localAddress,
 257        int localPort,
 258        string remoteAddress,
 259        int remotePort,
 260        int rcvSize,
 261        int sndSize)
 262        : base(incoming, adapterName, connectionId, localAddress, localPort, remoteAddress, remotePort)
 263    {
 264        this.rcvSize = rcvSize;
 265        this.sndSize = sndSize;
 266    }
 267
 268    internal TCPConnectionInfo(bool incoming, string adapterName, string connectionId)
 269        : this(
 270            incoming,
 271            adapterName,
 272            connectionId,
 273            localAddress: "",
 274            localPort: -1,
 275            remoteAddress: "",
 276            remotePort: -1,
 277            rcvSize: 0,
 278            sndSize: 0)
 279    {
 280    }
 281}
 282
 283/// <summary>
 284/// Provides access to the connection details of a UDP connection.
 285/// </summary>
 286public sealed class UDPConnectionInfo : IPConnectionInfo
 287{
 288    /// <summary>
 289    /// The multicast address.
 290    /// </summary>
 291    public readonly string mcastAddress;
 292
 293    /// <summary>
 294    /// The multicast port.
 295    /// </summary>
 296    public readonly int mcastPort;
 297
 298    /// <summary>
 299    /// The size of the receive buffer.
 300    /// </summary>
 301    public readonly int rcvSize;
 302
 303    /// <summary>
 304    /// The size of the send buffer.
 305    /// </summary>
 306    public readonly int sndSize;
 307
 308    internal UDPConnectionInfo(
 309        bool incoming,
 310        string adapterName,
 311        string connectionId,
 312        string localAddress,
 313        int localPort,
 314        string remoteAddress,
 315        int remotePort,
 316        string mcastAddress,
 317        int mcastPort,
 318        int rcvSize,
 319        int sndSize)
 320        : base(incoming, adapterName, connectionId, localAddress, localPort, remoteAddress, remotePort)
 321    {
 322        this.mcastAddress = mcastAddress;
 323        this.mcastPort = mcastPort;
 324        this.rcvSize = rcvSize;
 325        this.sndSize = sndSize;
 326    }
 327
 328    internal UDPConnectionInfo(bool incoming, string adapterName, string connectionId)
 329        : this(
 330            incoming,
 331            adapterName,
 332            connectionId,
 333            localAddress: "",
 334            localPort: -1,
 335            remoteAddress: "",
 336            remotePort: -1,
 337            mcastAddress: "",
 338            mcastPort: -1,
 339            rcvSize: 0,
 340            sndSize: 0)
 341    {
 342    }
 343}
 344
 345/// <summary>
 346/// Provides access to the connection details of a WebSocket connection.
 347/// </summary>
 348public sealed class WSConnectionInfo : ConnectionInfo
 349{
 350    /// <summary>
 351    /// The HTTP headers from the WebSocket upgrade handshake: the request headers for an incoming connection, and
 352    /// the response headers for an outgoing connection.
 353    /// </summary>
 354    public readonly Dictionary<string, string> headers;
 355
 356    internal WSConnectionInfo(ConnectionInfo underlying, Dictionary<string, string> headers)
 357        : base(underlying) => this.headers = headers;
 358}