Esempio n. 1
0
        public bool EnqueueOutgoing(OutgoingMessage message)
        {
            int category = (int)message.Category;

            if (category >= 0 && category < m_messageOutboxes.Length)
            {
                LocklessQueue<OutgoingMessage> queue = m_messageOutboxes[category];
                TokenBucket bucket = m_throttleCategories[category];

                if (bucket.RemoveTokens(message.Data.Length))
                {
                    // Enough tokens were removed from the bucket, the message will not be queued
                    return false;
                }
                else
                {
                    // Not enough tokens in the bucket, queue this message
                    queue.Enqueue(message);
                    return true;
                }
            }
            else
            {
                // We don't have a token bucket for this category, so it will not be queued
                return false;
            }
        }