System.Net.Connection.ReadCallback C# (CSharp) Method

ReadCallback() private method

private ReadCallback ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult
return void
        private void ReadCallback(IAsyncResult asyncResult)
        {
            GlobalLog.Enter("Connection#" + ValidationHelper.HashString(this) + "::ReadCallback", ValidationHelper.HashString(asyncResult));

            int bytesRead = -1;
            WebExceptionStatus errorStatus = WebExceptionStatus.ReceiveFailure;

            //
            // parameter validation
            //
            GlobalLog.Assert(asyncResult != null, "Connection#{0}::ReadCallback()|asyncResult == null", ValidationHelper.HashString(this));
            GlobalLog.Assert((asyncResult is OverlappedAsyncResult || asyncResult is LazyAsyncResult), "Connection#{0}::ReadCallback()|asyncResult is not OverlappedAsyncResult.", ValidationHelper.HashString(this));

            try {
                bytesRead = EndRead(asyncResult);
                if (bytesRead == 0)
                    bytesRead = -1; // 0 is reserved for re-entry on already buffered data

                errorStatus = WebExceptionStatus.Success;
            }
            catch (Exception exception) {

                if (m_InnerException == null)
                    m_InnerException = exception;

                if (exception.GetType() == typeof(ObjectDisposedException))
                    errorStatus = WebExceptionStatus.RequestCanceled;

                errorStatus = WebExceptionStatus.ReceiveFailure;
                GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::ReadCallback() EndRead() errorStatus:" + errorStatus.ToString() + " caught exception:" + exception);
            }

            ReadComplete(bytesRead, errorStatus);
            GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::ReadCallback");
        }