Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        private void IncrementReadableBytes(int increment)
        {
            int nextReadableBytes = _readableBytes + increment;

            if (nextReadableBytes < _readableBytes)
            {
                _ = ThrowHelper.ThrowInvalidOperationException_BufferQueueLengthOverflow(_readableBytes, increment);
            }
            _readableBytes = nextReadableBytes;
            if (_tracker is object)
            {
                _tracker.IncrementPendingOutboundBytes(increment);
            }
        }