Writes which are not immediate always return completed tasks

They must always be followed with Writes which are immediate, and
returning an incomplete task put them in a state where the callback
might not have been initiated.
This commit is contained in:
Louis DeJardin 2015-09-21 14:31:03 -07:00
parent 5e678fdbaa
commit 789d5b3595
1 changed files with 13 additions and 1 deletions

View File

@ -216,6 +216,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
Task ISocketOutput.WriteAsync(ArraySegment<byte> buffer, bool immediate, CancellationToken cancellationToken)
{
if (!immediate)
{
// immediate==false calls always return complete tasks, because there is guaranteed
// to be a subsequent immediate==true call which will go down the following code-path
Write(
buffer,
(error, state) => { },
null,
immediate: false);
return TaskUtilities.CompletedTask;
}
// TODO: Optimize task being used, and remove callback model from the underlying Write
var tcs = new TaskCompletionSource<int>();
@ -233,7 +245,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
},
tcs,
immediate: immediate);
immediate: true);
return tcs.Task;
}