InvokeWriteAsyncNow() public static method

public static InvokeWriteAsyncNow ( IChannelHandlerContext ctx, object msg ) : System.Threading.Tasks.Task
ctx IChannelHandlerContext
msg object
return System.Threading.Tasks.Task
コード例 #1
0
        public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg)
        {
            Contract.Requires(msg != null);
            // todo: check for cancellation
            //if (!validatePromise(ctx, promise, false)) {
            //    // promise cancelled
            //    return;
            //}

            if (Executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(ctx, msg));
            }
            else
            {
                var promise = new TaskCompletionSource();
                this.SafeExecuteOutbound(WriteTask.NewInstance(ctx, msg, promise), promise, msg);
                return(promise.Task);
            }
        }
コード例 #2
0
        public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg)
        {
            Contract.Requires(msg != null);
            // todo: check for cancellation
            //if (!validatePromise(ctx, promise, false)) {
            //    // promise cancelled
            //    return;
            //}

            if (Executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(ctx, msg));
            }
            var channel = (AbstractChannel)ctx.Channel;
            var promise = new TaskCompletionSource(ctx);

            try
            {
                var size = channel.EstimatorHandle.Size(msg);
                if (size > 0)
                {
                    var buffer = channel.Unsafe.OutboundBuffer;
                    // Check for null as it may be set to null if the channel is closed already
                    if (buffer != null)
                    {
                        buffer.IncrementPendingOutboundBytes(size);
                    }
                }

                Executor.Execute(InvokeWriteAsyncAction, promise, msg);
            }
            catch (Exception cause)
            {
                ReferenceCountUtil.Release(msg);
                promise.TrySetException(cause);
            }
            return(promise.Task);
        }
コード例 #3
0
            public void Run()
            {
                try
                {
                    ChannelOutboundBuffer buffer = this.ctx.Channel.Unsafe.OutboundBuffer;
                    // Check for null as it may be set to null if the channel is closed already
                    if (EstimateTaskSizeOnSubmit)
                    {
                        buffer?.DecrementPendingOutboundBytes(this.size);
                    }
                    ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(this.ctx, this.msg).LinkOutcome(this.promise);
                }
                finally
                {
                    // Set to null so the GC can collect them directly
                    this.ctx     = null;
                    this.msg     = null;
                    this.promise = null;

                    // recycle
                    _handle.Free(this);
                }
            }