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

StartReading() private method

private StartReading ( byte buffer, int offset, int count, AsyncProtocolRequest asyncRequest ) : int
buffer byte
offset int
count int
asyncRequest AsyncProtocolRequest
return int
        private int StartReading(byte[] buffer, int offset, int count, AsyncProtocolRequest asyncRequest)
        {
            int result;
            // When we read -1 bytes means we have decrypted 0 bytes, need looping.
            while ((result = StartFrameHeader(buffer, offset, count, asyncRequest)) == -1);

            return result;
        }

Usage Example

示例#1
0
        //
        //
        private static void ReadCallback(AsyncProtocolRequest asyncRequest)
        {
            // Async ONLY completion
            try
            {
                NegotiateStream   negoStream   = (NegotiateStream)asyncRequest.AsyncObject;
                BufferAsyncResult bufferResult = (BufferAsyncResult)asyncRequest.UserAsyncResult;

                // This is not a hack, just optimization to avoid an additional callback.
                //
                if ((object)asyncRequest.Buffer == (object)negoStream._ReadHeader)
                {
                    negoStream.StartFrameBody(asyncRequest.Result, bufferResult.Buffer, bufferResult.Offset, bufferResult.Count, asyncRequest);
                }
                else
                {
                    if (-1 == negoStream.ProcessFrameBody(asyncRequest.Result, bufferResult.Buffer, bufferResult.Offset, bufferResult.Count, asyncRequest))
                    {
                        // in case we decrypted 0 bytes start another reading.
                        negoStream.StartReading(bufferResult.Buffer, bufferResult.Offset, bufferResult.Count, asyncRequest);
                    }
                }
            }
            catch (Exception e)
            {
                if (asyncRequest.IsUserCompleted)
                {
                    // This will throw on a worker thread.
                    throw;
                }
                asyncRequest.CompleteWithError(e);
            }
        }
All Usage Examples Of System.Net.Security.NegotiateStream::StartReading