Exemplo n.º 1
0
        //
        //
        //
        private static void ReadCallback(IAsyncResult transportResult)
        {
            GlobalLog.Assert(transportResult.AsyncState is FixedSizeReader, "ReadCallback|State type is wrong, expected FixedSizeReader.");
            if (transportResult.CompletedSynchronously)
            {
                return;
            }

            FixedSizeReader      reader  = (FixedSizeReader)transportResult.AsyncState;
            AsyncProtocolRequest request = reader._Request;

            // Async completion
            try
            {
                int bytes = reader._Transport.EndRead(transportResult);

                if (reader.CheckCompletionBeforeNextRead(bytes))
                {
                    return;
                }
                reader.StartReading();
            }
            catch (Exception e)
            {
                if (request.IsUserCompleted)
                {
                    throw;
                }
                request.CompleteWithError(e);
            }
        }
Exemplo n.º 2
0
 private static void ReadCallback(IAsyncResult transportResult)
 {
     if (!transportResult.CompletedSynchronously)
     {
         FixedSizeReader      asyncState = (FixedSizeReader)transportResult.AsyncState;
         AsyncProtocolRequest request    = asyncState._Request;
         try
         {
             int bytes = asyncState._Transport.EndRead(transportResult);
             if (!asyncState.CheckCompletionBeforeNextRead(bytes))
             {
                 asyncState.StartReading();
             }
         }
         catch (Exception exception)
         {
             if (request.IsUserCompleted)
             {
                 throw;
             }
             request.CompleteWithError(exception);
         }
     }
 }
 private static void ResumeAsyncWriteCallback(AsyncProtocolRequest asyncRequest)
 {
     try
     {
         SplitWriteAsyncProtocolRequest request = asyncRequest as SplitWriteAsyncProtocolRequest;
         if (request != null)
         {
             ((_SslStream) asyncRequest.AsyncObject).StartWriting(request.SplitWritesState, request);
         }
         else
         {
             ((_SslStream) asyncRequest.AsyncObject).StartWriting(asyncRequest.Buffer, asyncRequest.Offset, asyncRequest.Count, asyncRequest);
         }
     }
     catch (Exception exception)
     {
         if (asyncRequest.IsUserCompleted)
         {
             throw;
         }
         ((_SslStream) asyncRequest.AsyncObject)._SslState.FinishWrite();
         asyncRequest.CompleteWithError(exception);
     }
 }
 private static void ResumeAsyncReadCallback(AsyncProtocolRequest request)
 {
     try
     {
         ((_SslStream) request.AsyncObject).StartReading(request.Buffer, request.Offset, request.Count, request);
     }
     catch (Exception exception)
     {
         if (request.IsUserCompleted)
         {
             throw;
         }
         ((_SslStream) request.AsyncObject)._SslState.FinishRead(null);
         request.CompleteWithError(exception);
     }
 }
 private static void ReadHeaderCallback(AsyncProtocolRequest asyncRequest)
 {
     try
     {
         _SslStream asyncObject = (_SslStream) asyncRequest.AsyncObject;
         BufferAsyncResult userAsyncResult = (BufferAsyncResult) asyncRequest.UserAsyncResult;
         if (-1 == asyncObject.StartFrameBody(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);
     }
 }
 private void FinishHandshake(Exception e, AsyncProtocolRequest asyncRequest)
 {
     try
     {
         lock (this)
         {
             if (e != null)
             {
                 this.SetException(e);
             }
             this.FinishHandshakeRead(0);
             if (Interlocked.CompareExchange(ref this._LockWriteState, 0, 2) == 3)
             {
                 this._LockWriteState = 1;
                 object state = this._QueuedWriteStateRequest;
                 if (state != null)
                 {
                     this._QueuedWriteStateRequest = null;
                     if (state is LazyAsyncResult)
                     {
                         ((LazyAsyncResult) state).InvokeCallback();
                     }
                     else
                     {
                         ThreadPool.QueueUserWorkItem(new WaitCallback(this.CompleteRequestWaitCallback), state);
                     }
                 }
             }
         }
     }
     finally
     {
         if (asyncRequest != null)
         {
             if (e != null)
             {
                 asyncRequest.CompleteWithError(e);
             }
             else
             {
                 asyncRequest.CompleteUser();
             }
         }
     }
 }