Skip to content

Commit 91df2ac

Browse files
committed
HTTP/3: ValueTask pooling
1 parent 7bf1904 commit 91df2ac

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

‎src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,9 @@ private bool TryValidatePseudoHeaders()
963963
}
964964

965965
// CONNECT - :scheme and :path must be excluded=
966-
if (Method == Http.HttpMethod.Connect && HttpRequestHeaders.HeaderProtocol.Count == 0)
966+
if (Method == HttpMethod.Connect && HttpRequestHeaders.HeaderProtocol.Count == 0)
967967
{
968-
if (!string.IsNullOrEmpty(RequestHeaders[PseudoHeaderNames.Scheme]) || !string.IsNullOrEmpty(RequestHeaders[PseudoHeaderNames.Path]))
968+
if (!string.IsNullOrEmpty(HttpRequestHeaders.HeaderScheme) || !string.IsNullOrEmpty(HttpRequestHeaders.HeaderPath))
969969
{
970970
Abort(new ConnectionAbortedException(CoreStrings.Http3ErrorConnectMustNotSendSchemeOrPath), Http3ErrorCode.ProtocolError);
971971
return false;
@@ -1006,7 +1006,7 @@ private bool TryValidatePseudoHeaders()
10061006
// OPTIONS request for an "http" or "https" URI that does not include
10071007
// a path component; these MUST include a ":path" pseudo-header field
10081008
// with a value of '*'.
1009-
if (Method == Http.HttpMethod.Options && path.Length == 1 && path[0] == '*')
1009+
if (Method == HttpMethod.Options && path.Length == 1 && path[0] == '*')
10101010
{
10111011
// * is stored in RawTarget only since HttpRequest expects Path to be empty or start with a /.
10121012
Path = string.Empty;
@@ -1036,13 +1036,13 @@ private bool TryValidateMethod()
10361036
_methodText = HttpRequestHeaders.HeaderMethod.ToString();
10371037
Method = HttpUtilities.GetKnownMethod(_methodText);
10381038

1039-
if (Method == Http.HttpMethod.None)
1039+
if (Method == HttpMethod.None)
10401040
{
10411041
Abort(new ConnectionAbortedException(CoreStrings.FormatHttp3ErrorMethodInvalid(_methodText)), Http3ErrorCode.ProtocolError);
10421042
return false;
10431043
}
10441044

1045-
if (Method == Http.HttpMethod.Custom)
1045+
if (Method == HttpMethod.Custom)
10461046
{
10471047
if (HttpCharacters.IndexOfInvalidTokenChar(_methodText) >= 0)
10481048
{

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using System.IO.Pipelines;
77
using System.Net.Quic;
8+
using System.Runtime.CompilerServices;
89
using System.Runtime.ExceptionServices;
910
using Microsoft.AspNetCore.Connections;
1011
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
@@ -145,17 +146,17 @@ private async Task StartAsync()
145146
{
146147
// Spawn send and receive logic
147148
// Streams may or may not have reading/writing, so only start tasks accordingly
148-
var receiveTask = Task.CompletedTask;
149-
var sendTask = Task.CompletedTask;
149+
var receiveTask = ValueTask.CompletedTask;
150+
var sendTask = ValueTask.CompletedTask;
150151

151152
if (_stream.CanRead)
152153
{
153-
receiveTask = DoReceive();
154+
receiveTask = DoReceiveAsync();
154155
}
155156

156157
if (_stream.CanWrite)
157158
{
158-
sendTask = DoSend();
159+
sendTask = DoSendAsync();
159160
}
160161

161162
// Now wait for both to complete
@@ -189,7 +190,8 @@ private async Task WaitForWritesCompleted()
189190
}
190191
}
191192

192-
private async Task DoReceive()
193+
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
194+
private async ValueTask DoReceiveAsync()
193195
{
194196
Debug.Assert(_stream != null);
195197

@@ -345,7 +347,8 @@ private void CancelConnectionClosedToken()
345347
}
346348
}
347349

348-
private async Task DoSend()
350+
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
351+
private async ValueTask DoSendAsync()
349352
{
350353
Debug.Assert(_stream != null);
351354

@@ -514,6 +517,7 @@ private void ShutdownWrite(Exception? shutdownReason)
514517
}
515518
}
516519

520+
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
517521
public override async ValueTask DisposeAsync()
518522
{
519523
if (_stream == null)

0 commit comments

Comments
 (0)