System.Net.Security.NegotiateStream.EndRead C# (CSharp) Method

EndRead() public method

public EndRead ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult
return int
        public override int EndRead(IAsyncResult asyncResult)
        {
#if DEBUG
            using (DebugThreadTracking.SetThreadKind(ThreadKinds.User))
            {
#endif
                _negoState.CheckThrow(true);

                if (!_negoState.CanGetSecureStream)
                {
                    return InnerStream.EndRead(asyncResult);
                }


                if (asyncResult == null)
                {
                    throw new ArgumentNullException(nameof(asyncResult));
                }

                BufferAsyncResult bufferResult = asyncResult as BufferAsyncResult;
                if (bufferResult == null)
                {
                    throw new ArgumentException(SR.Format(SR.net_io_async_result, asyncResult.GetType().FullName), nameof(asyncResult));
                }

                if (Interlocked.Exchange(ref _NestedRead, 0) == 0)
                {
                    throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, "EndRead"));
                }

                // No "artificial" timeouts implemented so far, InnerStream controls timeout.
                bufferResult.InternalWaitForCompletion();

                if (bufferResult.Result is Exception)
                {
                    if (bufferResult.Result is IOException)
                    {
                        throw (Exception)bufferResult.Result;
                    }

                    throw new IOException(SR.net_io_read, (Exception)bufferResult.Result);
                }

                return bufferResult.Int32Result;
#if DEBUG
            }
#endif
        }
        //