System.Net.FixedSizeReader.CheckCompletionBeforeNextRead C# (CSharp) Method

CheckCompletionBeforeNextRead() private method

private CheckCompletionBeforeNextRead ( int bytes ) : bool
bytes int
return bool
        private bool CheckCompletionBeforeNextRead(int bytes)
        {
            if (bytes == 0)
            {
                // 0 bytes was requested or EOF in the beginning of a frame, the caller should decide whether it's OK.
                if (_totalRead == 0)
                {
                    _request.CompleteRequest(0);
                    return true;
                }

                // EOF in the middle of a frame.
                throw new IOException(SR.net_io_eof);
            }

            if (_totalRead + bytes > _request.Count)
            {
                NetEventSource.Fail(this, $"State got out of range. Total:{_totalRead + bytes} Count:{_request.Count}");
            }

            if ((_totalRead += bytes) == _request.Count)
            {
                _request.CompleteRequest(_request.Count);
                return true;
            }

            return false;
        }

Usage Example

Esempio n. 1
0
        //
        //
        //
        private static void ReadCallback(IAsyncResult transportResult)
        {
            GlobalLog.Assert(transportResult.AsyncState is FixedSizeReader, "ReadCallback|State type is wrong, expected FixedSizeReader.");
            if (transportResult.CompletedSynchronously)
            {
                return;
            }

            FixedSizeReader      reader  = (FixedSizeReader)transportResult.AsyncState;
            AsyncProtocolRequest request = reader._Request;

            // Async completion
            try
            {
                int bytes = reader._Transport.EndRead(transportResult);

                if (reader.CheckCompletionBeforeNextRead(bytes))
                {
                    return;
                }
                reader.StartReading();
            }
            catch (Exception e)
            {
                if (request.IsUserCompleted)
                {
                    throw;
                }
                request.CompleteWithError(e);
            }
        }
All Usage Examples Of System.Net.FixedSizeReader::CheckCompletionBeforeNextRead