/// <summary> /// Begins an asynchronous to accept an incoming connection attempt using await. /// </summary> /// <param name="socket">The connected <see cref="Socket"/> object to use.</param> /// <param name="awaitable">The <see cref="SocketAwaitable"/> to await on.</param> /// <returns>A <see cref="SocketAwaitable"/> object ready to be reused.</returns> public static SocketAwaitable AcceptAsync(this Socket socket, SocketAwaitable awaitable) { awaitable.Reset(); if (!socket.AcceptAsync(awaitable.EventArgs)) { awaitable.IsCompleted = true; } return(awaitable); }
/// <summary> /// Begins an asynchronous request to receive data from a connected <see cref="Socket"/> object using await. /// </summary> /// <param name="awaitable">The <see cref="SocketAwaitable"/> to await on.</param> /// <returns>A <see cref="SocketAwaitable"/> object ready to be reused.</returns> public static SocketAwaitable ReceiveAsync(this SocketAwaitable awaitable) { awaitable.Reset(); var socket = awaitable.EventArgs.AcceptSocket; if (!socket.ReceiveAsync(awaitable.EventArgs)) { awaitable.IsCompleted = true; } return(awaitable); }