Skip to content

Commit c115fc8

Browse files
committed
Update
1 parent 443b5eb commit c115fc8

File tree

5 files changed

+60
-36
lines changed

5 files changed

+60
-36
lines changed

src/Servers/Connections.Abstractions/src/Features/IStreamAbortFeature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace Microsoft.AspNetCore.Connections.Features
55
{
66
/// <summary>
7-
/// Supports aborting one side of a connection stream.
7+
/// Supports aborting individual sides of a connection stream.
88
/// </summary>
99
public interface IStreamAbortFeature
1010
{

src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.FeatureCollection.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal
99
{
10-
internal sealed partial class QuicStreamContext : IPersistentStateFeature, IStreamDirectionFeature, IProtocolErrorCodeFeature, IStreamIdFeature
10+
internal sealed partial class QuicStreamContext : IPersistentStateFeature, IStreamDirectionFeature, IProtocolErrorCodeFeature, IStreamIdFeature, IStreamAbortFeature
1111
{
1212
private IDictionary<object, object?>? _persistentState;
1313

@@ -27,12 +27,47 @@ internal sealed partial class QuicStreamContext : IPersistentStateFeature, IStre
2727
}
2828
}
2929

30+
public void AbortRead(long errorCode, ConnectionAbortedException abortReason)
31+
{
32+
lock (_shutdownLock)
33+
{
34+
if (_stream.CanRead)
35+
{
36+
_shutdownReadReason = abortReason;
37+
_log.StreamAbortRead(this, abortReason.Message);
38+
_stream.AbortRead(errorCode);
39+
}
40+
else
41+
{
42+
throw new InvalidOperationException("Unable to abort reading from a stream that doesn't support reading.");
43+
}
44+
}
45+
}
46+
47+
public void AbortWrite(long errorCode, ConnectionAbortedException abortReason)
48+
{
49+
lock (_shutdownLock)
50+
{
51+
if (_stream.CanWrite)
52+
{
53+
_shutdownWriteReason = abortReason;
54+
_log.StreamAbortWrite(this, abortReason.Message);
55+
_stream.AbortWrite(errorCode);
56+
}
57+
else
58+
{
59+
throw new InvalidOperationException("Unable to abort writing to a stream that doesn't support writing.");
60+
}
61+
}
62+
}
63+
3064
private void InitializeFeatures()
3165
{
3266
_currentIPersistentStateFeature = this;
3367
_currentIStreamDirectionFeature = this;
3468
_currentIProtocolErrorCodeFeature = this;
3569
_currentIStreamIdFeature = this;
70+
_currentIStreamAbortFeature = this;
3671
_currentITlsConnectionFeature = _connection._currentITlsConnectionFeature;
3772
}
3873
}

src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -379,40 +379,6 @@ public override void Abort(ConnectionAbortedException abortReason)
379379
Output.CancelPendingRead();
380380
}
381381

382-
public void AbortRead(long errorCode, ConnectionAbortedException abortReason)
383-
{
384-
lock (_shutdownLock)
385-
{
386-
if (_stream.CanRead)
387-
{
388-
_shutdownReadReason = abortReason;
389-
_log.StreamAbortRead(this, abortReason.Message);
390-
_stream.AbortRead(errorCode);
391-
}
392-
else
393-
{
394-
throw new InvalidOperationException("Unable to abort reading from a stream that doesn't support reading.");
395-
}
396-
}
397-
}
398-
399-
public void AbortWrite(long errorCode, ConnectionAbortedException abortReason)
400-
{
401-
lock (_shutdownLock)
402-
{
403-
if (_stream.CanWrite)
404-
{
405-
_shutdownWriteReason = abortReason;
406-
_log.StreamAbortWrite(this, abortReason.Message);
407-
_stream.AbortWrite(errorCode);
408-
}
409-
else
410-
{
411-
throw new InvalidOperationException("Unable to abort writing to a stream that doesn't support writing.");
412-
}
413-
}
414-
}
415-
416382
private async ValueTask ShutdownWrite(Exception? shutdownReason)
417383
{
418384
try

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal partial class TransportConnection : IFeatureCollection,
3333
internal protected IProtocolErrorCodeFeature? _currentIProtocolErrorCodeFeature;
3434
internal protected IStreamDirectionFeature? _currentIStreamDirectionFeature;
3535
internal protected IStreamIdFeature? _currentIStreamIdFeature;
36+
internal protected IStreamAbortFeature? _currentIStreamAbortFeature;
3637
internal protected ITlsConnectionFeature? _currentITlsConnectionFeature;
3738

3839
private int _featureRevision;
@@ -52,6 +53,7 @@ private void FastReset()
5253
_currentIProtocolErrorCodeFeature = null;
5354
_currentIStreamDirectionFeature = null;
5455
_currentIStreamIdFeature = null;
56+
_currentIStreamAbortFeature = null;
5557
_currentITlsConnectionFeature = null;
5658
}
5759

@@ -164,6 +166,10 @@ private void ExtraFeatureSet(Type key, object? value)
164166
{
165167
feature = _currentIStreamIdFeature;
166168
}
169+
else if (key == typeof(IStreamAbortFeature))
170+
{
171+
feature = _currentIStreamAbortFeature;
172+
}
167173
else if (key == typeof(ITlsConnectionFeature))
168174
{
169175
feature = _currentITlsConnectionFeature;
@@ -220,6 +226,10 @@ private void ExtraFeatureSet(Type key, object? value)
220226
{
221227
_currentIStreamIdFeature = (IStreamIdFeature?)value;
222228
}
229+
else if (key == typeof(IStreamAbortFeature))
230+
{
231+
_currentIStreamAbortFeature = (IStreamAbortFeature?)value;
232+
}
223233
else if (key == typeof(ITlsConnectionFeature))
224234
{
225235
_currentITlsConnectionFeature = (ITlsConnectionFeature?)value;
@@ -278,6 +288,10 @@ private void ExtraFeatureSet(Type key, object? value)
278288
{
279289
feature = Unsafe.As<IStreamIdFeature?, TFeature?>(ref _currentIStreamIdFeature);
280290
}
291+
else if (typeof(TFeature) == typeof(IStreamAbortFeature))
292+
{
293+
feature = Unsafe.As<IStreamAbortFeature?, TFeature?>(ref _currentIStreamAbortFeature);
294+
}
281295
else if (typeof(TFeature) == typeof(ITlsConnectionFeature))
282296
{
283297
feature = Unsafe.As<ITlsConnectionFeature?, TFeature?>(ref _currentITlsConnectionFeature);
@@ -337,6 +351,10 @@ private void ExtraFeatureSet(Type key, object? value)
337351
{
338352
_currentIStreamIdFeature = Unsafe.As<TFeature?, IStreamIdFeature?>(ref feature);
339353
}
354+
else if (typeof(TFeature) == typeof(IStreamAbortFeature))
355+
{
356+
_currentIStreamAbortFeature = Unsafe.As<TFeature?, IStreamAbortFeature?>(ref feature);
357+
}
340358
else if (typeof(TFeature) == typeof(ITlsConnectionFeature))
341359
{
342360
_currentITlsConnectionFeature = Unsafe.As<TFeature?, ITlsConnectionFeature?>(ref feature);
@@ -389,6 +407,10 @@ private IEnumerable<KeyValuePair<Type, object>> FastEnumerable()
389407
{
390408
yield return new KeyValuePair<Type, object>(typeof(IStreamIdFeature), _currentIStreamIdFeature);
391409
}
410+
if (_currentIStreamAbortFeature != null)
411+
{
412+
yield return new KeyValuePair<Type, object>(typeof(IStreamAbortFeature), _currentIStreamAbortFeature);
413+
}
392414
if (_currentITlsConnectionFeature != null)
393415
{
394416
yield return new KeyValuePair<Type, object>(typeof(ITlsConnectionFeature), _currentITlsConnectionFeature);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static string GenerateFile()
2424
"IProtocolErrorCodeFeature",
2525
"IStreamDirectionFeature",
2626
"IStreamIdFeature",
27+
"IStreamAbortFeature",
2728
"ITlsConnectionFeature"
2829
};
2930

0 commit comments

Comments
 (0)