Skip to content

Commit 55b9034

Browse files
Implement IConnectionEndPointFeature in TransportConnection
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
1 parent 04cf3eb commit 55b9034

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/Servers/Kestrel/shared/TransportConnection.FeatureCollection.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Buffers;
55
using System.IO.Pipelines;
6+
using System.Net;
67
using Microsoft.AspNetCore.Connections.Features;
78

89
#nullable enable
@@ -37,4 +38,16 @@ CancellationToken IConnectionLifetimeFeature.ConnectionClosed
3738
}
3839

3940
void IConnectionLifetimeFeature.Abort() => Abort(new ConnectionAbortedException("The connection was aborted by the application via IConnectionLifetimeFeature.Abort()."));
41+
42+
EndPoint? IConnectionEndPointFeature.LocalEndPoint
43+
{
44+
get => LocalEndPoint;
45+
set => LocalEndPoint = value;
46+
}
47+
48+
EndPoint? IConnectionEndPointFeature.RemoteEndPoint
49+
{
50+
get => RemoteEndPoint;
51+
set => RemoteEndPoint = value;
52+
}
4053
}

src/Servers/Kestrel/shared/TransportConnection.Generated.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ internal partial class TransportConnection : IFeatureCollection,
1818
IConnectionTransportFeature,
1919
IConnectionItemsFeature,
2020
IMemoryPoolFeature,
21-
IConnectionLifetimeFeature
21+
IConnectionLifetimeFeature,
22+
IConnectionEndPointFeature
2223
{
2324
// Implemented features
2425
internal protected IConnectionIdFeature? _currentIConnectionIdFeature;
2526
internal protected IConnectionTransportFeature? _currentIConnectionTransportFeature;
2627
internal protected IConnectionItemsFeature? _currentIConnectionItemsFeature;
2728
internal protected IMemoryPoolFeature? _currentIMemoryPoolFeature;
2829
internal protected IConnectionLifetimeFeature? _currentIConnectionLifetimeFeature;
30+
internal protected IConnectionEndPointFeature? _currentIConnectionEndPointFeature;
2931

3032
// Other reserved feature slots
3133
internal protected IPersistentStateFeature? _currentIPersistentStateFeature;
@@ -48,6 +50,7 @@ private void FastReset()
4850
_currentIConnectionItemsFeature = this;
4951
_currentIMemoryPoolFeature = this;
5052
_currentIConnectionLifetimeFeature = this;
53+
_currentIConnectionEndPointFeature = this;
5154

5255
_currentIPersistentStateFeature = null;
5356
_currentIConnectionSocketFeature = null;
@@ -180,6 +183,10 @@ private void ExtraFeatureSet(Type key, object? value)
180183
{
181184
feature = _currentIConnectionMetricsTagsFeature;
182185
}
186+
else if (key == typeof(IConnectionEndPointFeature))
187+
{
188+
feature = _currentIConnectionEndPointFeature;
189+
}
183190
else if (MaybeExtra != null)
184191
{
185192
feature = ExtraFeatureGet(key);
@@ -244,6 +251,10 @@ private void ExtraFeatureSet(Type key, object? value)
244251
{
245252
_currentIConnectionMetricsTagsFeature = (IConnectionMetricsTagsFeature?)value;
246253
}
254+
else if (key == typeof(IConnectionEndPointFeature))
255+
{
256+
_currentIConnectionEndPointFeature = (IConnectionEndPointFeature?)value;
257+
}
247258
else
248259
{
249260
ExtraFeatureSet(key, value);
@@ -310,6 +321,10 @@ private void ExtraFeatureSet(Type key, object? value)
310321
{
311322
feature = Unsafe.As<IConnectionMetricsTagsFeature?, TFeature?>(ref _currentIConnectionMetricsTagsFeature);
312323
}
324+
else if (typeof(TFeature) == typeof(IConnectionEndPointFeature))
325+
{
326+
feature = Unsafe.As<IConnectionEndPointFeature?, TFeature?>(ref _currentIConnectionEndPointFeature);
327+
}
313328
else if (MaybeExtra != null)
314329
{
315330
feature = (TFeature?)(ExtraFeatureGet(typeof(TFeature)));
@@ -382,6 +397,10 @@ private void ExtraFeatureSet(Type key, object? value)
382397
{
383398
_currentIConnectionMetricsTagsFeature = Unsafe.As<TFeature?, IConnectionMetricsTagsFeature?>(ref feature);
384399
}
400+
else if (typeof(TFeature) == typeof(IConnectionEndPointFeature))
401+
{
402+
_currentIConnectionEndPointFeature = Unsafe.As<TFeature?, IConnectionEndPointFeature?>(ref feature);
403+
}
385404
else
386405
{
387406
ExtraFeatureSet(typeof(TFeature), feature);
@@ -442,6 +461,10 @@ private IEnumerable<KeyValuePair<Type, object>> FastEnumerable()
442461
{
443462
yield return new KeyValuePair<Type, object>(typeof(IConnectionMetricsTagsFeature), _currentIConnectionMetricsTagsFeature);
444463
}
464+
if (_currentIConnectionEndPointFeature != null)
465+
{
466+
yield return new KeyValuePair<Type, object>(typeof(IConnectionEndPointFeature), _currentIConnectionEndPointFeature);
467+
}
445468

446469
if (MaybeExtra != null)
447470
{

src/Servers/Kestrel/tools/CodeGenerator/TransportConnectionFeatureCollection.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public static string GenerateFile()
2424
"IStreamIdFeature",
2525
"IStreamAbortFeature",
2626
"IStreamClosedFeature",
27-
"IConnectionMetricsTagsFeature"
27+
"IConnectionMetricsTagsFeature",
28+
"IConnectionEndPointFeature"
2829
};
2930

3031
var implementedFeatures = new[]
@@ -33,7 +34,8 @@ public static string GenerateFile()
3334
"IConnectionTransportFeature",
3435
"IConnectionItemsFeature",
3536
"IMemoryPoolFeature",
36-
"IConnectionLifetimeFeature"
37+
"IConnectionLifetimeFeature",
38+
"IConnectionEndPointFeature"
3739
};
3840

3941
var usings = $@"

0 commit comments

Comments
 (0)