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

ReadCallback() private static method

private static ReadCallback ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult
return void
        private static void ReadCallback(IAsyncResult asyncResult) {
            GlobalLog.Enter("ConnectStream::ReadCallback", "asyncResult=#"+ValidationHelper.HashString(asyncResult));
            GlobalLog.ThreadContract(ThreadKinds.Unknown, "ConnectStream::ReadCallback");

            //
            // we called m_Connection.BeginRead() previously that call
            // completed and called our internal callback
            // we passed the NestedSingleAsyncResult (that we then returned to the user)
            // as the state of this call, so build it back:
            //
            NestedSingleAsyncResult castedAsyncResult = (NestedSingleAsyncResult)asyncResult.AsyncState;
            ConnectStream thisConnectStream = (ConnectStream)castedAsyncResult.AsyncObject;

            try {
                int bytesTransferred = thisConnectStream.m_Connection.EndRead(asyncResult);
                if(Logging.On)Logging.Dump(Logging.Web, thisConnectStream, "ReadCallback", castedAsyncResult.Buffer, castedAsyncResult.Offset, Math.Min(castedAsyncResult.Size, bytesTransferred));
                //
                // call the user's callback, with success
                //
                castedAsyncResult.InvokeCallback(bytesTransferred);
            }
            catch (Exception exception) {
                if (NclUtilities.IsFatal(exception)) throw;

                //
                // call the user's callback, with exception
                //
                castedAsyncResult.InvokeCallback(exception);
            }
            GlobalLog.Leave("ConnectStream::ReadCallback");
        }