本文整理汇总了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);
}