/// <summary> /// Adds the given message to this <see cref="PendingWriteQueue"/>. /// </summary> /// <param name="msg">The message to add to the <see cref="PendingWriteQueue"/>.</param> /// <param name="promise"></param> public void Add(object msg, IPromise promise) { Debug.Assert(_ctx.Executor.InEventLoop); if (msg is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.msg); } if (promise is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.promise); } // It is possible for writes to be triggered from removeAndFailAll(). To preserve ordering, // we should add them to the queue and let removeAndFailAll() fail them later. int messageSize = GetSize(msg); PendingWrite write = PendingWrite.NewInstance(msg, messageSize, promise); PendingWrite currentTail = _tail; if (currentTail is null) { _tail = _head = write; } else { currentTail.Next = write; _tail = write; } _size++; _bytes += messageSize; _tracker.IncrementPendingOutboundBytes(write.Size); }
/** * Add the given {@code msg} and {@link ChannelPromise}. */ public Task Add(object msg) { Contract.Assert(this.ctx.Executor.InEventLoop); Contract.Requires(msg != null); int messageSize = this.estimatorHandle.Size(msg); if (messageSize < 0) { // Size may be unknow so just use 0 messageSize = 0; } var promise = new TaskCompletionSource(); PendingWrite write = PendingWrite.NewInstance(msg, messageSize, promise); PendingWrite currentTail = this.tail; if (currentTail == null) { this.tail = this.head = write; } else { currentTail.Next = write; this.tail = write; } this.size++; // We need to guard against null as channel.Unsafe.OutboundBuffer may returned null // if the channel was already closed when constructing the PendingWriteQueue. // See https://github.com/netty/netty/issues/3967 this.buffer?.IncrementPendingOutboundBytes(write.Size); return(promise.Task); }
/// <summary>Add the given <c>msg</c> and returns <see cref="Task" /> for completion of processing <c>msg</c>.</summary> public void Add(object msg, IPromise promise) { Debug.Assert(_ctx.Executor.InEventLoop); if (msg is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.msg); } int messageSize = _estimatorHandle.Size(msg); if (messageSize < 0) { // Size may be unknow so just use 0 messageSize = 0; } PendingWrite currentTail = _tail; if (currentTail is object) { bool canBundle = CanBatch(msg, messageSize, currentTail.Size); if (canBundle) { currentTail.Add(msg, messageSize); if (!promise.IsVoid) { currentTail.Promise.Task.LinkOutcome(promise); } return; } } PendingWrite write; if (promise.IsVoid || promise is SimplePromiseAggregator) { var headPromise = _ctx.NewPromise(); headPromise.Task.LinkOutcome(promise); write = PendingWrite.NewInstance(msg, messageSize, headPromise); } else { write = PendingWrite.NewInstance(msg, messageSize, promise); } if (currentTail is null) { _tail = _head = write; } else { currentTail.Next = write; _tail = write; } _size++; // We need to guard against null as channel.Unsafe.OutboundBuffer may returned null // if the channel was already closed when constructing the PendingWriteQueue. // See https://github.com/netty/netty/issues/3967 _buffer?.IncrementPendingOutboundBytes(messageSize); }