static async ValueTask WaitForWriteTaskAsync(ValueTask <SocketError> t) { SocketError socErr = await t.ConfigureAwait(false); if (socErr == SocketError.Success) { return; } throw socErr.ToException(); }
/// <exception cref="SocketException"/> /// <exception cref="ObjectDisposedException"/> public ValueTask WriteAsync(ReadOnlyMemory <byte> buffer, CancellationToken cancellationToken) { ValueTask <SocketError> t = SendAsync(buffer, cancellationToken); if (t.IsCompletedSuccessfully) { SocketError socErr = t.Result; return(socErr == SocketError.Success ? default : new ValueTask(Task.FromException(socErr.ToException()))); } else { return(WaitForWriteTaskAsync(t)); }