当前位置: 首页>>代码示例>>C#>>正文


C# TransportAsyncCallbackArgs.CompletedCallback方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:33,代码来源:TcpTransport.cs

示例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);
            }
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:97,代码来源:TcpTransport.cs

示例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;
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:25,代码来源:AmqpTransportInitiator.cs


注:本文中的Microsoft.Azure.Amqp.Transport.TransportAsyncCallbackArgs.CompletedCallback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。