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


C# PooledSocket.ReceiveAsync方法代码示例

本文整理汇总了C#中PooledSocket.ReceiveAsync方法的典型用法代码示例。如果您正苦于以下问题:C# PooledSocket.ReceiveAsync方法的具体用法?C# PooledSocket.ReceiveAsync怎么用?C# PooledSocket.ReceiveAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PooledSocket的用法示例。


在下文中一共展示了PooledSocket.ReceiveAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadAsync

        /// <summary>
        /// Reads the response from the socket asynchronously.
        /// </summary>
        /// <param name="socket">The socket to read from.</param>
        /// <param name="next">The delegate whihc will continue processing the response. This is only called if the read completes asynchronoulsy.</param>
        /// <param name="ioPending">Set totrue if the read is still pending when ReadASync returns. In this case 'next' will be called when the read is finished.</param>
        /// <returns>
        /// If the socket is already dead, ReadAsync returns false, next is not called, ioPending = false
        /// If the read completes synchronously (e.g. data is received from the buffer), it returns true/false depending on the StatusCode, and ioPending is set to true, 'next' will not be called.
        /// It returns true if it has to read from the socket, so the operation will complate asynchronously at a later time. ioPending will be true, and 'next' will be called to handle the data
        /// </returns>
        public bool ReadAsync(PooledSocket socket, Action<bool> next, out bool ioPending)
        {
            this.StatusCode = -1;
            this.currentSocket = socket;
            this.next = next;

            var asyncEvent = new AsyncIOArgs();

            asyncEvent.Count = HeaderLength;
            asyncEvent.Next = this.DoDecodeHeaderAsync;

            this.shouldCallNext = true;

            if (socket.ReceiveAsync(asyncEvent))
            {
                ioPending = true;
                return true;
            }

            ioPending = false;
            this.shouldCallNext = false;

            return asyncEvent.Fail
                    ? false
                    : this.DoDecodeHeader(asyncEvent, out ioPending);
        }
开发者ID:yorkart,项目名称:CachingClient,代码行数:37,代码来源:BinaryResponse.cs


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