コード例 #1
0
ファイル: LLAgent.cs プロジェクト: jhurliman/simian
        public bool EnqueueOutgoing(OutgoingPacket packet)
        {
            int category = (int)packet.Category;

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

                if (bucket.RemoveTokens(packet.Buffer.DataLength))
                {
                    // Enough tokens were removed from the bucket, the packet will not be queued
                    return(false);
                }
                else
                {
                    // Not enough tokens in the bucket, queue this packet
                    queue.Enqueue(packet);
                    return(true);
                }
            }
            else
            {
                // We don't have a token bucket for this category, so it will not be queued
                return(false);
            }
        }
コード例 #2
0
ファイル: WSAgent.cs プロジェクト: jhurliman/simian
        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);
            }
        }
コード例 #3
0
 /// <summary>
 /// Marks a packet as no longer needing acknowledgement without a received acknowledgement.
 /// This method is called when a packet expires and we no longer need an acknowledgement.
 /// When some reliable packet types expire, they are handled in a way other than simply
 /// resending them. The only effect of removal this way is to update unacked byte count.
 /// </summary>
 /// <param name="sequenceNumber">Sequence number of the packet to
 /// acknowledge</param>
 /// <remarks>The does not immediately remove the packet, it only queues the removal
 /// so it can be handled in a thread safe way later</remarks>
 public void Remove(uint sequenceNumber)
 {
     m_pendingRemoves.Enqueue(sequenceNumber);
 }
コード例 #4
0
 /// <summary>
 /// Marks a packet as acknowledged
 /// This method is used when an acknowledgement is received from the network for a previously
 /// sent packet. Effects of removal this way are to update unacked byte count, adjust RTT
 /// and increase throttle to the coresponding client.
 /// </summary>
 /// <param name="sequenceNumber">Sequence number of the packet to
 /// acknowledge</param>
 /// <param name="currentTime">Current value of Environment.TickCount</param>
 /// <remarks>This does not immediately acknowledge the packet, it only
 /// queues the ack so it can be handled in a thread-safe way later</remarks>
 public void Acknowledge(uint sequenceNumber, int currentTime, bool fromResend)
 {
     m_pendingAcknowledgements.Enqueue(new PendingAck(sequenceNumber, currentTime, fromResend));
 }
コード例 #5
0
 /// <summary>
 /// Add an unacked packet to the collection
 /// </summary>
 /// <param name="packet">Packet that is awaiting acknowledgement</param>
 /// <returns>True if the packet was successfully added, false if the
 /// packet already existed in the collection</returns>
 /// <remarks>This does not immediately add the ACK to the collection,
 /// it only queues it so it can be added in a thread-safe way later</remarks>
 public void Add(OutgoingPacket packet)
 {
     m_pendingAdds.Enqueue(packet);
     Interlocked.Add(ref packet.Client.UnackedBytes, packet.Buffer.DataLength);
 }
コード例 #6
0
 /// <summary>
 /// Marks a packet as acknowledged
 /// </summary>
 /// <param name="sequenceNumber">Sequence number of the packet to
 /// acknowledge</param>
 /// <param name="currentTime">Current value of Environment.TickCount</param>
 /// <remarks>This does not immediately acknowledge the packet, it only
 /// queues the ack so it can be handled in a thread-safe way later</remarks>
 public void Remove(uint sequenceNumber, int currentTime, bool fromResend)
 {
     m_pendingRemoves.Enqueue(new PendingAck(sequenceNumber, currentTime, fromResend));
 }
コード例 #7
0
 /// <summary>
 /// Add an unacked packet to the collection
 /// </summary>
 /// <param name="packet">Packet that is awaiting acknowledgement</param>
 /// <returns>True if the packet was successfully added, false if the
 /// packet already existed in the collection</returns>
 /// <remarks>This does not immediately add the ACK to the collection,
 /// it only queues it so it can be added in a thread-safe way later</remarks>
 public void Add(OutgoingPacket packet)
 {
     m_pendingAdds.Enqueue(packet);
 }