| | | 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 | | |
| | | 4 | | using System.Diagnostics.CodeAnalysis; |
| | | 5 | | using System.Diagnostics.Tracing; |
| | | 6 | | |
| | | 7 | | namespace 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 | | |
| | 0 | 22 | | internal SocketsHttpConnectionEvictionContext( |
| | 0 | 23 | | DnsEndPoint dnsEndPoint, |
| | 0 | 24 | | IPEndPoint? remoteEndPoint, |
| | 0 | 25 | | long connectionId, |
| | 0 | 26 | | Version httpVersion, |
| | 0 | 27 | | long creationTickCount) |
| | 0 | 28 | | { |
| | 0 | 29 | | DnsEndPoint = dnsEndPoint; |
| | 0 | 30 | | RemoteEndPoint = remoteEndPoint; |
| | 0 | 31 | | ConnectionId = connectionId; |
| | 0 | 32 | | HttpVersion = httpVersion; |
| | 0 | 33 | | _creationTickCount = creationTickCount; |
| | 0 | 34 | | } |
| | | 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> |
| | 0 | 44 | | 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> |
| | 0 | 53 | | 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> |
| | 0 | 70 | | 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> |
| | 0 | 75 | | public Version HttpVersion { get; } |
| | | 76 | | |
| | | 77 | | /// <summary> |
| | | 78 | | /// Gets the amount of time that has elapsed since the connection was established. |
| | | 79 | | /// </summary> |
| | 0 | 80 | | public TimeSpan Age => TimeSpan.FromMilliseconds(Environment.TickCount64 - _creationTickCount); |
| | | 81 | | } |
| | | 82 | | } |
| | | 83 | | |