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 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); } }