本文整理汇总了C#中Microsoft.Azure.Amqp.Transport.TransportAsyncCallbackArgs.CompletedCallback方法的典型用法代码示例。如果您正苦于以下问题:C# TransportAsyncCallbackArgs.CompletedCallback方法的具体用法?C# TransportAsyncCallbackArgs.CompletedCallback怎么用?C# TransportAsyncCallbackArgs.CompletedCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Amqp.Transport.TransportAsyncCallbackArgs
的用法示例。
在下文中一共展示了TransportAsyncCallbackArgs.CompletedCallback方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleWriteComplete
void HandleWriteComplete(TransportAsyncCallbackArgs args, bool syncCompleted)
{
if (this.sendEventArgs.SocketError == SocketError.Success)
{
args.BytesTransfered = this.sendEventArgs.BytesTransferred;
args.Exception = null;
Fx.Assert(args.BytesTransfered == args.Count, "Cannot be partialy completed");
if (this.monitor != null)
{
this.sendEventArgs.ReportWrite(this.monitor);
}
}
else
{
args.Exception = new SocketException((int)this.sendEventArgs.SocketError);
}
args.CompletedSynchronously = syncCompleted;
try
{
this.sendEventArgs.Reset();
}
catch (ObjectDisposedException exception)
{
args.Exception = exception;
}
if (!syncCompleted)
{
args.CompletedCallback(args);
}
}
示例2: HandleReadComplete
void HandleReadComplete(TransportAsyncCallbackArgs args, bool fromCache, bool completedSynchronously)
{
ByteBuffer readBuffer = this.receiveEventArgs.UserToken as ByteBuffer;
try
{
if (this.receiveEventArgs.SocketError == SocketError.Success)
{
int bytesCopied = 0;
if (this.receiveEventArgs.IsSegment)
{
bytesCopied = this.receiveEventArgs.BytesTransferred;
Buffer.BlockCopy(this.receiveEventArgs.Buffer, this.receiveEventArgs.Offset,
args.Buffer, args.Offset, bytesCopied);
}
else
{
if (readBuffer != null)
{
int bytesTransferred;
if (fromCache)
{
bytesTransferred = readBuffer.Length;
}
else
{
bytesTransferred = this.receiveEventArgs.BytesTransferred;
readBuffer.Append(bytesTransferred);
if (this.monitor != null)
{
this.receiveEventArgs.ReportRead(this.monitor);
}
}
if (bytesTransferred > 0)
{
if (bytesTransferred <= args.Count)
{
bytesCopied = bytesTransferred;
Buffer.BlockCopy(readBuffer.Buffer, readBuffer.Offset, args.Buffer, args.Offset, bytesTransferred);
readBuffer.Reset();
}
else
{
bytesCopied = args.Count;
Buffer.BlockCopy(readBuffer.Buffer, readBuffer.Offset, args.Buffer, args.Offset, bytesCopied);
readBuffer.Complete(bytesCopied);
}
}
}
else
{
bytesCopied = this.receiveEventArgs.BytesTransferred;
}
}
args.BytesTransfered = bytesCopied;
args.Exception = null;
}
else
{
args.Exception = new SocketException((int)this.receiveEventArgs.SocketError);
}
}
catch (Exception exception)
{
if (Fx.IsFatal(exception))
{
throw;
}
args.Exception = exception;
}
finally
{
if (readBuffer != null)
{
// ref count was incremented when read starts
readBuffer.Dispose();
}
}
args.CompletedSynchronously = completedSynchronously;
try
{
this.receiveEventArgs.Reset();
}
catch (ObjectDisposedException exception)
{
args.Exception = exception;
}
if (!completedSynchronously)
{
args.CompletedCallback(args);
}
}
示例3: ConnectTaskAsync
public Task<TransportBase> ConnectTaskAsync(TimeSpan timeout)
{
var tcs = new TaskCompletionSource<TransportBase>();
var args = new TransportAsyncCallbackArgs
{
CompletedCallback = a =>
{
if (a.Exception != null)
{
tcs.SetException(a.Exception);
}
else
{
tcs.SetResult(a.Transport);
}
}
};
if (!this.ConnectAsync(timeout, args))
{
args.CompletedCallback(args);
}
return tcs.Task;
}