ProcessFrameBody() private method

private ProcessFrameBody ( int readBytes, byte buffer, int offset, int count, AsyncProtocolRequest asyncRequest ) : int
readBytes int
buffer byte
offset int
count int
asyncRequest AsyncProtocolRequest
return int
Esempio n. 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);
            }
        }
 private static void ReadCallback(AsyncProtocolRequest asyncRequest)
 {
     try
     {
         NegotiateStream   asyncObject     = (NegotiateStream)asyncRequest.AsyncObject;
         BufferAsyncResult userAsyncResult = (BufferAsyncResult)asyncRequest.UserAsyncResult;
         if (asyncRequest.Buffer == asyncObject._ReadHeader)
         {
             asyncObject.StartFrameBody(asyncRequest.Result, userAsyncResult.Buffer, userAsyncResult.Offset, userAsyncResult.Count, asyncRequest);
         }
         else if (-1 == asyncObject.ProcessFrameBody(asyncRequest.Result, userAsyncResult.Buffer, userAsyncResult.Offset, userAsyncResult.Count, asyncRequest))
         {
             asyncObject.StartReading(userAsyncResult.Buffer, userAsyncResult.Offset, userAsyncResult.Count, asyncRequest);
         }
     }
     catch (Exception exception)
     {
         if (asyncRequest.IsUserCompleted)
         {
             throw;
         }
         asyncRequest.CompleteWithError(exception);
     }
 }