private void GetResult(ref ReadResult result) { if (_writerCompletion.IsCompletedOrThrow()) { result.ResultFlags |= ResultFlags.Completed; } var isCancelled = _readerAwaitable.ObserveCancelation(); if (isCancelled) { result.ResultFlags |= ResultFlags.Cancelled; } // No need to read end if there is no head var head = _readHead; if (head != null) { // Reading commit head shared with writer result.ResultBuffer = new ReadableBuffer(head, head.Start, _commitHead, _commitHeadIndex); } if (isCancelled) { _readingState.BeginTentative(ExceptionResource.AlreadyReading); } else { _readingState.Begin(ExceptionResource.AlreadyReading); } }
private void GetResult(ref ReadResult result) { if (_writerCompletion.IsCompletedOrThrow()) { result._resultFlags |= ResultFlags.Completed; } bool isCanceled = _readerAwaitable.ObserveCancelation(); if (isCanceled) { result._resultFlags |= ResultFlags.Canceled; } // No need to read end if there is no head BufferSegment head = _readHead; if (head != null) { // Reading commit head shared with writer result._resultBuffer = new ReadOnlySequence <byte>(head, _readHeadIndex, _commitHead, _commitHeadIndex - _commitHead.Start); } if (isCanceled) { _readingState.BeginTentative(); } else { _readingState.Begin(); } }
private void GetResult(ref ReadResult result) { if (_writerCompletion.IsCompletedOrThrow()) { result.ResultFlags |= ResultFlags.Completed; } if (_readerAwaitable.ObserveCancelation()) { result.ResultFlags |= ResultFlags.Cancelled; } // No need to read end if there is no head var head = _readHead; if (head != null) { // Reading commit head shared with writer result.ResultBuffer.BufferEnd.Segment = _commitHead; result.ResultBuffer.BufferEnd.Index = _commitHeadIndex; result.ResultBuffer.BufferLength = ReadCursor.GetLength(head, head.Start, _commitHead, _commitHeadIndex); result.ResultBuffer.BufferStart.Segment = head; result.ResultBuffer.BufferStart.Index = head.Start; } _readingState.Begin(ExceptionResource.AlreadyReading); }
FlushResult IWritableBufferAwaiter.GetResult() { var result = new FlushResult(); lock (_sync) { if (!_writerAwaitable.IsCompleted) { PipelinesThrowHelper.ThrowInvalidOperationException(ExceptionResource.GetResultNotCompleted); } // Change the state from to be cancelled -> observed if (_writerAwaitable.ObserveCancelation()) { result.ResultFlags |= ResultFlags.Cancelled; } if (_readerCompletion.IsCompletedOrThrow()) { result.ResultFlags |= ResultFlags.Completed; } } return(result); }
internal FlushResult GetFlushAsyncResult() { var result = new FlushResult(); lock (_sync) { if (!_writerAwaitable.IsCompleted) { ThrowHelper.ThrowInvalidOperationException_GetResultNotCompleted(); } // Change the state from to be canceled -> observed if (_writerAwaitable.ObserveCancelation()) { result._resultFlags |= ResultFlags.Canceled; } if (_readerCompletion.IsCompletedOrThrow()) { result._resultFlags |= ResultFlags.Completed; } } return(result); }