Example #1
0
            static async ValueTask WaitForWriteTaskAsync(ValueTask <SocketError> t)
            {
                SocketError socErr = await t.ConfigureAwait(false);

                if (socErr == SocketError.Success)
                {
                    return;
                }

                throw socErr.ToException();
            }
Example #2
0
        /// <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));
            }