Esempio n. 1
0
 /// <exception cref="ObjectDisposedException"/>
 public ValueTask <SocketReceiveResult> ReceiveAsync(Memory <byte> buffer, CancellationToken cancellationToken = default)
 {
     if (!IsDisposed)
     {
         if (!cancellationToken.IsCancellationRequested)
         {
             if (_receiveArgs.Reserve())
             {
                 return(_receiveArgs.ReceiveAsync(_socket, buffer));
             }
             else
             {
                 return(new ValueTask <SocketReceiveResult>(task: Task.FromException <SocketReceiveResult>(SimultaneouslyOperationException())));
             }
         }
         else
         {
             return(new ValueTask <SocketReceiveResult>(Task.FromCanceled <SocketReceiveResult>(cancellationToken)));
         }
     }
     else
     {
         return(DisposedValueTask <SocketReceiveResult>());
     }
 }