本文整理汇总了C#中AsyncProtocolRequest.CompleteUserWithError方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncProtocolRequest.CompleteUserWithError方法的具体用法?C# AsyncProtocolRequest.CompleteUserWithError怎么用?C# AsyncProtocolRequest.CompleteUserWithError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncProtocolRequest
的用法示例。
在下文中一共展示了AsyncProtocolRequest.CompleteUserWithError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FinishHandshake
private void FinishHandshake(Exception e, AsyncProtocolRequest asyncRequest)
{
try
{
lock (this)
{
if (e != null)
{
SetException(e);
}
// Release read if any.
FinishHandshakeRead(LockNone);
// If there is a pending write we want to keep it's lock state.
int lockState = Interlocked.CompareExchange(ref _lockWriteState, LockNone, LockHandshake);
if (lockState != LockPendingWrite)
{
return;
}
_lockWriteState = LockWrite;
object obj = _queuedWriteStateRequest;
if (obj == null)
{
// We finished before Write has grabbed the lock.
return;
}
_queuedWriteStateRequest = null;
if (obj is LazyAsyncResult)
{
// Sync write is waiting on other thread.
((LazyAsyncResult)obj).InvokeCallback();
}
else
{
// Async write is pending, start it on other thread.
// Consider: we could start it in on this thread but that will delay THIS handshake completion
ThreadPool.QueueUserWorkItem(new WaitCallback(CompleteRequestWaitCallback), obj);
}
}
}
finally
{
if (asyncRequest != null)
{
if (e != null)
{
asyncRequest.CompleteUserWithError(e);
}
else
{
asyncRequest.CompleteUser();
}
}
}
}
示例2: ReadCallback
private static void ReadCallback(AsyncProtocolRequest asyncRequest)
{
// Async ONLY completion.
try
{
NegotiateStream negoStream = (NegotiateStream)asyncRequest.AsyncObject;
BufferAsyncResult bufferResult = (BufferAsyncResult)asyncRequest.UserAsyncResult;
// This is an 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.CompleteUserWithError(e);
}
}
示例3: ResumeAsyncWriteCallback
//
// This is used in a rare situation when async Write is resumed from completed handshake.
//
private static void ResumeAsyncWriteCallback(AsyncProtocolRequest asyncRequest)
{
try
{
((SslStreamInternal)asyncRequest.AsyncObject).StartWriting(asyncRequest.Buffer, asyncRequest.Offset, asyncRequest.Count, asyncRequest);
}
catch (Exception e)
{
if (asyncRequest.IsUserCompleted)
{
// This will throw on a worker thread.
throw;
}
((SslStreamInternal)asyncRequest.AsyncObject)._sslState.FinishWrite();
asyncRequest.CompleteUserWithError(e);
}
}
示例4: ReadFrameCallback
private static void ReadFrameCallback(AsyncProtocolRequest asyncRequest)
{
try
{
SslStreamInternal sslStream = (SslStreamInternal)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.CompleteUserWithError(e);
}
}
示例5: ResumeAsyncReadCallback
//
// This is used in a rare situation when async Read is resumed from completed handshake.
//
private static void ResumeAsyncReadCallback(AsyncProtocolRequest request)
{
try
{
((SslStreamInternal)request.AsyncObject).StartReading(request.Buffer, request.Offset, request.Count, request);
}
catch (Exception e)
{
if (request.IsUserCompleted)
{
// This will throw on a worker thread.
throw;
}
((SslStreamInternal)request.AsyncObject)._sslState.FinishRead(null);
request.CompleteUserWithError(e);
}
}