private async Task SendFrameFallbackAsync(MessageOpcode opcode, bool endOfMessage, ArraySegment<byte> payloadBuffer, CancellationToken cancellationToken)
{
await _sendFrameAsyncLock.WaitAsync().ConfigureAwait(false);
try
{
int sendBytes = WriteFrameToSendBuffer(opcode, endOfMessage, payloadBuffer);
using (cancellationToken.Register(s => ((ManagedWebSocket)s).Abort(), this))
{
await _stream.WriteAsync(_sendBuffer, 0, sendBytes, cancellationToken).ConfigureAwait(false);
}
}
catch (Exception exc)
{
throw _state == WebSocketState.Aborted ?
CreateOperationCanceledException(exc, cancellationToken) :
new WebSocketException(WebSocketError.ConnectionClosedPrematurely, exc);
}
finally
{
_sendFrameAsyncLock.Release();
}
}