/// <summary>
        /// Checks out an instance from the manager.
        /// </summary>
        /// <returns>A <see cref="DataSocketAsyncEventArgs" />.</returns>
        public static DataSocketAsyncEventArgs CheckOut()
        {
            DataSocketAsyncEventArgs result;

            if (!_pool.TryPop(out result))
            {
                result = new DataSocketAsyncEventArgs();
            }
            else
            {
                result._checkedIn = 0;
            }
            return(result);
        }
示例#2
0
 /// <summary>
 /// Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.
 /// </summary>
 /// <param name="buffer">The buffer to write data from.</param>
 /// <param name="offset">The zero-based byte offset in <paramref name="buffer" /> from which to begin copying bytes to the stream.</param>
 /// <param name="count">The maximum number of bytes to write.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" />.</param>
 /// <returns>
 /// A task that represents the asynchronous write operation.
 /// </returns>
 public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 {
     return(DataSocketAsyncEventArgs.CheckOut().WriteAsync(_socket, buffer, offset, count, cancellationToken));
 }
示例#3
0
 /// <summary>
 /// Sends data asynchronously to a connected <see cref="T:System.Net.Sockets.Socket" /> object.
 /// </summary>
 /// <param name="e">The <see cref="T:System.Net.Sockets.SocketAsyncEventArgs" /> object to use for this asynchronous socket operation.</param>
 /// <returns>
 /// Returns true if the I/O operation is pending. The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed" /> event on the <paramref name="e" /> parameter will be raised upon completion of the operation. Returns false if the I/O operation completed synchronously. In this case, The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed" /> event on the <paramref name="e" /> parameter will not be raised and the <paramref name="e" /> object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation.
 /// </returns>
 public bool SendAsync(DataSocketAsyncEventArgs e)
 {
     return(_socket.SendAsync(e));
 }
示例#4
0
 /// <summary>
 /// Begins an asynchronous request to receive data from a connected <see cref="T:System.Net.Sockets.Socket" /> object.
 /// </summary>
 /// <param name="e">The <see cref="T:System.Net.Sockets.SocketAsyncEventArgs" /> object to use for this asynchronous socket operation.</param>
 /// <returns>
 /// Returns true if the I/O operation is pending. The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed" /> event on the <paramref name="e" /> parameter will be raised upon completion of the operation. Returns false if the I/O operation completed synchronously. In this case, The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed" /> event on the <paramref name="e" /> parameter will not be raised and the <paramref name="e" /> object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation.
 /// </returns>
 public bool ReceiveAsync(DataSocketAsyncEventArgs e)
 {
     return(_socket.ReceiveAsync(e));
 }