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

EndReadWithoutValidation() private method

private EndReadWithoutValidation ( int bytesTransferred, bool zeroLengthRead ) : int
bytesTransferred int
zeroLengthRead bool
return int
        private int EndReadWithoutValidation(int bytesTransferred, bool zeroLengthRead)
        {
            GlobalLog.Enter("ConnectStream#" + ValidationHelper.HashString(this) + "::EndReadWithoutValidation", bytesTransferred.ToString());

            int bytesAlreadyTransferred = m_BytesAlreadyTransferred;
            m_BytesAlreadyTransferred = 0;

            if (m_Chunked)
            {
                if (bytesTransferred < 0)
                {
                    IOError(null, false);
                    bytesTransferred = 0;
                }

                bytesTransferred += bytesAlreadyTransferred;
                m_ChunkSize -= bytesTransferred;
            }
            else {

                //
                // we're not chunking, a note about error
                //  checking here, in some cases due to 1.0
                //  servers we need to read until 0 bytes,
                //  or a server reset, therefore, we may need
                //  ignore sockets errors
                //

                bool doneReading = false;

                // if its finished without async, just use what was read already from the buffer,
                // otherwise we call the Connection's EndRead to find out
                if (bytesTransferred <= 0)
                {
                    //
                    // We read 0 bytes from the connection, or it had an error. This is OK if we're
                    // reading to end, it's an error otherwise.
                    //
                    if (m_ReadBytes != -1 && (bytesTransferred < 0 || !zeroLengthRead))
                    {
                        IOError(null, false);
                    }
                    else {
                        //
                        // We're reading to end, and we found the end, by reading 0 bytes
                        //
                        doneReading = true;
                        bytesTransferred = 0;
                    }
                }

                bytesTransferred += bytesAlreadyTransferred;

                //
                // Not chunking. Update our read bytes state and return what we've read.
                //
                if (m_ReadBytes != -1) {
                    m_ReadBytes -= bytesTransferred;

                    GlobalLog.Assert(m_ReadBytes >= 0, "ConnectStream: Attempting to read more bytes than available.|m_ReadBytes < 0");

                    GlobalLog.Print("m_ReadBytes = "+m_ReadBytes);
                }

                if (m_ReadBytes == 0 || doneReading) {
                    // We're all done reading, tell the connection that.
                    m_ReadBytes = 0;

                    //
                    // indicate to cache that read completed OK
                    //

                    CallDone();
                }
            }

            GlobalLog.Leave("ConnectStream#" + ValidationHelper.HashString(this) + "::EndRead", bytesTransferred);
            return bytesTransferred;
        }