From f089abd33727731434c4a2dab44fc5b4bc36391b Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 15 Nov 2015 21:33:31 +0000 Subject: [PATCH] Consume in single call --- .../Http/Frame.cs | 6 ++--- .../Http/MessageBody.cs | 26 ++++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index dac00934db..e8310aab06 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -232,10 +232,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http await ProduceEnd(); - while (await MessageBody.SkipAsync() != 0) - { - // Finish reading the request body in case the app did not. - } + // Finish reading the request body in case the app did not. + await MessageBody.Consume(); } terminated = !_keepAlive; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 5453256418..1604d0145d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -38,20 +38,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return result; } - public Task SkipAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task Consume(CancellationToken cancellationToken = default(CancellationToken)) { - Task result = null; - var send100Continue = 0; - result = SkipAsyncImplementation(cancellationToken); - if (!result.IsCompleted) + Task result; + do { - send100Continue = Interlocked.Exchange(ref _send100Continue, 0); - } - if (send100Continue == 1) - { - _context.FrameControl.ProduceContinue(); - } - return result; + var send100Continue = 0; + result = SkipAsyncImplementation(cancellationToken); + if (!result.IsCompleted) + { + send100Continue = Interlocked.Exchange(ref _send100Continue, 0); + } + if (send100Continue == 1) + { + _context.FrameControl.ProduceContinue(); + } + } while (await result != 0); } public abstract Task ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken);