public static WriteTask NewInstance(AbstractChannelHandlerContext ctx, object msg, TaskCompletionSource promise)
            {
                WriteTask task = Recycler.Take();

                Init(task, ctx, msg, promise);
                return(task);
            }
예제 #2
0
            public static WriteTask NewInstance(
                IChannelHandlerContext ctx, object msg, TaskCompletionSource promise)
            {
                WriteTask task = Recycler.Take();

                task.ctx     = ctx;
                task.msg     = msg;
                task.promise = promise;

                if (EstimateTaskSizeOnSubmit)
                {
                    ChannelOutboundBuffer buffer = ctx.Channel.Unsafe.OutboundBuffer;

                    // Check for null as it may be set to null if the channel is closed already
                    if (buffer != null)
                    {
                        task.size = ((AbstractChannel)ctx.Channel).EstimatorHandle.Size(msg) + WriteTaskOverhead;
                        buffer.IncrementPendingOutboundBytes(task.size);
                    }
                    else
                    {
                        task.size = 0;
                    }
                }
                else
                {
                    task.size = 0;
                }

                return(task);
            }
예제 #3
0
        public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg)
        {
            Contract.Requires(msg != null);

            // todo: cancellation support
            //try
            //{
            //    if (!validatePromise(ctx, promise, true))
            //    {
            //        ReferenceCountUtil.release(msg);
            //        return;
            //    }
            //}
            //catch (RuntimeException e)
            //{
            //    ReferenceCountUtil.release(msg);
            //    throw e;
            //}

            if (this.executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeWriteNowAsync(ctx, msg));
            }
            else
            {
                var promise = new TaskCompletionSource();
                this.SafeExecuteOutbound(WriteTask.NewInstance(ctx, msg, promise), promise, msg);
                return(promise.Task);
            }
        }
예제 #4
0
            public static WriteTask NewInstance(AbstractChannelHandlerContext ctx, object msg, IPromise promise, bool flush)
            {
                WriteTask task = Recycler.Take();

                Init(task, ctx, msg, promise, flush);
                return(task);
            }
예제 #5
0
            private int _size; // sign bit controls flush

            private static void Init(WriteTask task, AbstractChannelHandlerContext ctx, object msg, IPromise promise, bool flush)
            {
                task._ctx     = ctx;
                task._msg     = msg;
                task._promise = promise;

                if (EstimateTaskSizeOnSubmit)
                {
                    task._size = ctx._pipeline.EstimatorHandle.Size(msg) + WriteTaskOverhead;
                    ctx._pipeline.IncrementPendingOutboundBytes(task._size);
                }
                else
                {
                    task._size = 0;
                }
                if (flush)
                {
                    task._size |= int.MinValue;
                }
            }
        Task WriteAsync(object msg, bool flush)
        {
            AbstractChannelHandlerContext next = this.FindContextOutbound();
            object         m            = this.pipeline.Touch(msg, next);
            IEventExecutor nextExecutor = next.Executor;

            if (nextExecutor.InEventLoop)
            {
                return(flush
                    ? next.InvokeWriteAndFlushAsync(m)
                    : next.InvokeWriteAsync(m));
            }
            else
            {
                var promise            = new TaskCompletionSource();
                AbstractWriteTask task = flush
                    ? WriteAndFlushTask.NewInstance(next, m, promise)
                    : (AbstractWriteTask)WriteTask.NewInstance(next, m, promise);
                SafeExecuteOutbound(nextExecutor, task, promise, msg);
                return(promise.Task);
            }
        }