protected static void Init(AbstractWriteTask task, AbstractChannelHandlerContext ctx, object msg, TaskCompletionSource promise) { 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 = ctx.pipeline.EstimatorHandle.Size(msg) + WriteTaskOverhead; buffer.IncrementPendingOutboundBytes(task.size); } else { task.size = 0; } } else { task.size = 0; } }
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); } }