Esempio n. 1
0
        //
        // Assuming InnerStream type == typeof(NetworkStream)
        //
        private static void MulitpleWriteCallback(IAsyncResult transportResult)
        {
            if (transportResult.CompletedSynchronously)
            {
                return;
            }

            GlobalLog.Assert(transportResult.AsyncState is AsyncProtocolRequest, "SslStream::MulitpleWriteCallback|State type is wrong, expected AsyncProtocolRequest.");

            SplitWriteAsyncProtocolRequest asyncRequest = (SplitWriteAsyncProtocolRequest)transportResult.AsyncState;

            _SslStream sslStream = (_SslStream)asyncRequest.AsyncObject;

            try {
                ((NetworkStream)(sslStream._SslState.InnerStream)).EndMultipleWrite(transportResult);
                sslStream._SslState.FinishWrite();
                sslStream.StartWriting(asyncRequest.SplitWritesState, asyncRequest);
            }
            catch (Exception e) {
                if (asyncRequest.IsUserCompleted)
                {
                    // This will throw on a worker thread.
                    throw;
                }
                sslStream._SslState.FinishWrite();
                asyncRequest.CompleteWithError(e);
            }
        }
Esempio n. 2
0
        //
        //
        //
        private static void WriteCallback(IAsyncResult transportResult)
        {
            if (transportResult.CompletedSynchronously)
            {
                return;
            }

            GlobalLog.Assert(transportResult.AsyncState is AsyncProtocolRequest, "SslStream::WriteCallback|State type is wrong, expected AsyncProtocolRequest.");
            AsyncProtocolRequest asyncRequest = (AsyncProtocolRequest)transportResult.AsyncState;

            _SslStream sslStream = (_SslStream)asyncRequest.AsyncObject;

            try {
                sslStream._SslState.InnerStream.EndWrite(transportResult);
                sslStream._SslState.FinishWrite();

                if (asyncRequest.Count == 0)
                {
                    // this was the last chunk
                    asyncRequest.Count = -1;
                }
                sslStream.StartWriting(asyncRequest.Buffer, asyncRequest.Offset, asyncRequest.Count, asyncRequest);
            }
            catch (Exception e) {
                if (asyncRequest.IsUserCompleted)
                {
                    // This will throw on a worker thread.
                    throw;
                }
                sslStream._SslState.FinishWrite();
                asyncRequest.CompleteWithError(e);
            }
        }
Esempio n. 3
0
 private static void WriteCallback(IAsyncResult transportResult)
 {
     if (!transportResult.CompletedSynchronously)
     {
         AsyncProtocolRequest asyncState  = (AsyncProtocolRequest)transportResult.AsyncState;
         _SslStream           asyncObject = (_SslStream)asyncState.AsyncObject;
         try
         {
             asyncObject._SslState.InnerStream.EndWrite(transportResult);
             asyncObject._SslState.FinishWrite();
             if (asyncState.Count == 0)
             {
                 asyncState.Count = -1;
             }
             asyncObject.StartWriting(asyncState.Buffer, asyncState.Offset, asyncState.Count, asyncState);
         }
         catch (Exception exception)
         {
             if (asyncState.IsUserCompleted)
             {
                 throw;
             }
             asyncObject._SslState.FinishWrite();
             asyncState.CompleteWithError(exception);
         }
     }
 }
Esempio n. 4
0
 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);
     }
 }
Esempio n. 5
0
 //
 //
 private static void ReadFrameCallback(AsyncProtocolRequest asyncRequest)
 {
     // Async ONLY completion
     try
     {
         _SslStream        sslStream    = (_SslStream)asyncRequest.AsyncObject;
         BufferAsyncResult bufferResult = (BufferAsyncResult)asyncRequest.UserAsyncResult;
         if (-1 == sslStream.ProcessFrameBody(asyncRequest.Result, bufferResult.Buffer, bufferResult.Offset, bufferResult.Count, asyncRequest))
         {
             // in case we decrypted 0 bytes start another reading.
             sslStream.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);
     }
 }
Esempio n. 6
0
 private static void MulitpleWriteCallback(IAsyncResult transportResult)
 {
     if (!transportResult.CompletedSynchronously)
     {
         SplitWriteAsyncProtocolRequest asyncState = (SplitWriteAsyncProtocolRequest)transportResult.AsyncState;
         _SslStream asyncObject = (_SslStream)asyncState.AsyncObject;
         try
         {
             ((NetworkStream)asyncObject._SslState.InnerStream).EndMultipleWrite(transportResult);
             asyncObject._SslState.FinishWrite();
             asyncObject.StartWriting(asyncState.SplitWritesState, asyncState);
         }
         catch (Exception exception)
         {
             if (asyncState.IsUserCompleted)
             {
                 throw;
             }
             asyncObject._SslState.FinishWrite();
             asyncState.CompleteWithError(exception);
         }
     }
 }