System.Net.ConnectStream.ReadChunkedSync C# (CSharp) Method

ReadChunkedSync() private method

private ReadChunkedSync ( byte buffer, int offset, int size ) : int
buffer byte
offset int
size int
return int
        private int ReadChunkedSync(byte[] buffer, int offset, int size) {
            GlobalLog.Print("ConnectStream#" + ValidationHelper.HashString(this) + "::ReadChunkedSync");

// ********** WARNING - updating logic below should also be updated in ReadChunkedCallback *****************

            if (!m_Draining && IsClosed) {
                // throw on shutdown only if we're not draining the socket.
                Exception exception =
                    new WebException(
                        NetRes.GetWebStatusString("net_requestaborted", WebExceptionStatus.ConnectionClosed),
                        WebExceptionStatus.ConnectionClosed);

                throw exception;
            }
            else if (m_ErrorException!=null) {
                // throw on IO error even if we're draining the socket.
                throw m_ErrorException;
            }
            if (m_ChunkedNeedCRLFRead) {
                ReadCRLF(m_TempBuffer);
                m_ChunkedNeedCRLFRead = false;
            }

            StreamChunkBytes ReadByteBuffer = new StreamChunkBytes(this);

            // We need to determine size of next chunk,
            // by carefully reading, byte by byte

            m_ChunkSize = ProcessReadChunkedSize(ReadByteBuffer);

            // If this isn't a zero length chunk, read it.
            if (m_ChunkSize != 0) {
                m_ChunkedNeedCRLFRead = true;
                return InternalRead(buffer, offset, Math.Min(size, m_ChunkSize));
            }
            else {
                // We've found the terminating 0 length chunk. We may be very well looking
                // at an extension footer or the very final CRLF.

                ReadCRLF(m_TempBuffer);
                RemoveTrailers(ReadByteBuffer);

                // Remember that we've found this, so we don't try and dechunk
                // more.

                m_ReadBytes = 0;
                m_ChunkEofRecvd = true;

                CallDone();

                // we're done reading, return 0 bytes
                return 0;
            }

 // ********** WARNING - updating logic above should also be updated in ReadChunkedAsync *****************
        }