Most of these to WaitAsync shouldn't actually matter, as the semaphores being used are there for corner cases or to protect erroneous usage, but if there's no contention, passing a token won't hurt, and if there is contention, passing the token makes it more robust.
Commit migrated from https://github.com/dotnet/corefx/commit/
14a7adb23569363b94d575d64b7cb1f38cda3e4a
private async Task SendFrameFallbackAsync(MessageOpcode opcode, bool endOfMessage, ReadOnlyMemory<byte> payloadBuffer, CancellationToken cancellationToken)
{
- await _sendFrameAsyncLock.WaitAsync().ConfigureAwait(false);
+ await _sendFrameAsyncLock.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
int sendBytes = WriteFrameToSendBuffer(opcode, endOfMessage, payloadBuffer.Span);
}
await SendFrameAsync(
- MessageOpcode.Pong, true,
- _receiveBuffer.Slice(_receiveBufferOffset, (int)header.PayloadLength), default).ConfigureAwait(false);
+ MessageOpcode.Pong,
+ endOfMessage: true,
+ _receiveBuffer.Slice(_receiveBufferOffset, (int)header.PayloadLength),
+ cancellationToken).ConfigureAwait(false);
}
// Regardless of whether it was a ping or pong, we no longer need the payload.
// is not related to our cancellation token.
if (cancellationToken.IsCancellationRequested && (e.CancellationToken == cancellationToken))
{
- tcs.TrySetCanceled();
+ tcs.TrySetCanceled(cancellationToken);
}
else
{
await CopyFromBufferAsync(destination, remaining, cancellationToken).ConfigureAwait(false);
_readLength = _readOffset = 0;
- await _stream.CopyToAsync(destination, bufferSize).ConfigureAwait(false);
+ await _stream.CopyToAsync(destination, bufferSize, cancellationToken).ConfigureAwait(false);
}
// Copy *exactly* [length] bytes into destination; throws on end of stream.
TransportContext transportContext = null;
// Serialize creation attempt
- await _http2ConnectionCreateLock.WaitAsync().ConfigureAwait(false);
+ await _http2ConnectionCreateLock.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
if (_http2Connection != null)
Debug.Assert(_stream != null);
SemaphoreSlim sem = LazyEnsureAsyncActiveSemaphoreInitialized();
- await sem.WaitAsync().ConfigureAwait(false);
+ await sem.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
if (_writePos > 0)
// Async IO Task accesses the buffer concurrently. If we fail to acquire the lock without waiting, make this
// an Async operation.
SemaphoreSlim sem = LazyEnsureAsyncActiveSemaphoreInitialized();
- Task semaphoreLockTask = sem.WaitAsync();
+ Task semaphoreLockTask = sem.WaitAsync(cancellationToken);
if (semaphoreLockTask.IsCompletedSuccessfully)
{
bool completeSynchronously = true;
int bytesFromBuffer = 0;
SemaphoreSlim sem = LazyEnsureAsyncActiveSemaphoreInitialized();
- Task semaphoreLockTask = sem.WaitAsync();
+ Task semaphoreLockTask = sem.WaitAsync(cancellationToken);
if (semaphoreLockTask.IsCompletedSuccessfully)
{
bool completeSynchronously = true;
// Try to satisfy the request from the buffer synchronously.
SemaphoreSlim sem = LazyEnsureAsyncActiveSemaphoreInitialized();
- Task semaphoreLockTask = sem.WaitAsync();
+ Task semaphoreLockTask = sem.WaitAsync(cancellationToken);
if (semaphoreLockTask.IsCompletedSuccessfully)
{
bool completeSynchronously = true;
Debug.Assert(_stream != null);
// Synchronize async operations as does Read/WriteAsync.
- await LazyEnsureAsyncActiveSemaphoreInitialized().WaitAsync().ConfigureAwait(false);
+ await LazyEnsureAsyncActiveSemaphoreInitialized().WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
int readBytes = _readLen - _readPos;
// thread if it does a second IO request until the first one completes.
SemaphoreSlim semaphore = AsyncActiveSemaphore;
- await semaphore.WaitAsync().ForceAsync();
+ await semaphore.WaitAsync(cancellationToken).ForceAsync();
try
{
return await ReadAsyncCore(buffer, offset, count, cancellationToken, useAsync: true).ConfigureAwait(false);
// thread if it does a second IO request until the first one completes.
SemaphoreSlim semaphore = AsyncActiveSemaphore;
- await semaphore.WaitAsync().ForceAsync();
+ await semaphore.WaitAsync(cancellationToken).ForceAsync();
try
{
await WriteAsyncCore(buffer, offset, count, cancellationToken, useAsync: true).ConfigureAwait(false);