< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 83
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpConnectionEvictionContext.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics.CodeAnalysis;
 5using System.Diagnostics.Tracing;
 6
 7namespace System.Net.Http
 8{
 9    /// <summary>
 10    /// Represents the context passed to <see cref="SocketsHttpHandler.ShouldEvictConnection"/> when a pooled
 11    /// connection is being considered for eviction.
 12    /// </summary>
 13    /// <remarks>
 14    /// The instance is only valid for the duration of the callback invocation; it must not be cached or used after
 15    /// the callback returns. <see cref="Age"/> reflects the elapsed time at the moment it is read.
 16    /// </remarks>
 17    [Experimental(Experimentals.SocketsHttpHandlerExperimentalDiagId, UrlFormat = Experimentals.SharedUrlFormat)]
 18    public sealed class SocketsHttpConnectionEvictionContext
 19    {
 20        private readonly long _creationTickCount; // milliseconds from Environment.TickCount64, not TimeSpan ticks
 21
 022        internal SocketsHttpConnectionEvictionContext(
 023            DnsEndPoint dnsEndPoint,
 024            IPEndPoint? remoteEndPoint,
 025            long connectionId,
 026            Version httpVersion,
 027            long creationTickCount)
 028        {
 029            DnsEndPoint = dnsEndPoint;
 030            RemoteEndPoint = remoteEndPoint;
 031            ConnectionId = connectionId;
 032            HttpVersion = httpVersion;
 033            _creationTickCount = creationTickCount;
 034        }
 35
 36        /// <summary>
 37        /// Gets the <see cref="Net.DnsEndPoint"/> identifying the origin (host and port) the connection targets.
 38        /// </summary>
 39        /// <remarks>
 40        /// This is the logical destination the connection was created for, not necessarily the host the
 41        /// transport is physically connected to (for example, when a proxy is in use). Use it together with
 42        /// <see cref="RemoteEndPoint"/> to decide whether the connection still points at a desired address.
 43        /// </remarks>
 044        public DnsEndPoint DnsEndPoint { get; }
 45
 46        /// <summary>
 47        /// Gets the remote <see cref="IPEndPoint"/> the connection's transport is connected to, when available.
 48        /// </summary>
 49        /// <remarks>
 50        /// This is <see langword="null"/> when the remote endpoint is not known, for example when a custom
 51        /// <see cref="SocketsHttpHandler.ConnectCallback"/> returned a stream that is not backed by a socket.
 52        /// </remarks>
 053        public IPEndPoint? RemoteEndPoint { get; }
 54
 55        /// <summary>
 56        /// Gets the identifier assigned to the connection. This matches the connection id reported through
 57        /// <see cref="EventSource"/> telemetry and the <see cref="HttpRequestMessage.ConnectionId"/> stamped on
 58        /// requests sent over the connection. It also matches the
 59        /// <see cref="SocketsHttpConnectionContext.ConnectionId"/> seen by a custom
 60        /// <see cref="SocketsHttpHandler.ConnectCallback"/>. It allows the eviction decision to be correlated
 61        /// with the requests the connection served.
 62        /// </summary>
 63        /// <remarks>
 64        /// For an HTTP CONNECT proxy tunnel the id seen by a custom <see cref="SocketsHttpHandler.ConnectCallback"/>
 65        /// differs from this one: the callback observes the underlying transport connection to the proxy while this id
 66        /// identifies the tunneled connection that served the requests. Both ids remain observable through a
 67        /// <see cref="SocketsHttpHandler.PlaintextStreamFilter"/>, which runs on each hop and reports the transport
 68        /// id for the CONNECT hop and this id for the tunneled hop.
 69        /// </remarks>
 070        public long ConnectionId { get; }
 71
 72        /// <summary>
 73        /// Gets the HTTP version negotiated for the connection (for example, 1.1, 2.0, or 3.0).
 74        /// </summary>
 075        public Version HttpVersion { get; }
 76
 77        /// <summary>
 78        /// Gets the amount of time that has elapsed since the connection was established.
 79        /// </summary>
 080        public TimeSpan Age => TimeSpan.FromMilliseconds(Environment.TickCount64 - _creationTickCount);
 81    }
 82}
 83