diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs | 115 |
1 files changed, 90 insertions, 25 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs index 621e0fd..e52ac37 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs | |||
@@ -92,7 +92,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
92 | /// <summary>Packets we have sent that need to be ACKed by the client</summary> | 92 | /// <summary>Packets we have sent that need to be ACKed by the client</summary> |
93 | public readonly UnackedPacketCollection NeedAcks = new UnackedPacketCollection(); | 93 | public readonly UnackedPacketCollection NeedAcks = new UnackedPacketCollection(); |
94 | /// <summary>ACKs that are queued up, waiting to be sent to the client</summary> | 94 | /// <summary>ACKs that are queued up, waiting to be sent to the client</summary> |
95 | public readonly OpenSim.Framework.LocklessQueue<uint> PendingAcks = new OpenSim.Framework.LocklessQueue<uint>(); | 95 | public readonly DoubleLocklessQueue<uint> PendingAcks = new DoubleLocklessQueue<uint>(); |
96 | 96 | ||
97 | /// <summary>Current packet sequence number</summary> | 97 | /// <summary>Current packet sequence number</summary> |
98 | public int CurrentSequence; | 98 | public int CurrentSequence; |
@@ -146,7 +146,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
146 | /// <summary>Throttle buckets for each packet category</summary> | 146 | /// <summary>Throttle buckets for each packet category</summary> |
147 | private readonly TokenBucket[] m_throttleCategories; | 147 | private readonly TokenBucket[] m_throttleCategories; |
148 | /// <summary>Outgoing queues for throttled packets</summary> | 148 | /// <summary>Outgoing queues for throttled packets</summary> |
149 | private readonly OpenSim.Framework.LocklessQueue<OutgoingPacket>[] m_packetOutboxes = new OpenSim.Framework.LocklessQueue<OutgoingPacket>[THROTTLE_CATEGORY_COUNT]; | 149 | private readonly DoubleLocklessQueue<OutgoingPacket>[] m_packetOutboxes = new DoubleLocklessQueue<OutgoingPacket>[THROTTLE_CATEGORY_COUNT]; |
150 | /// <summary>A container that can hold one packet for each outbox, used to store | 150 | /// <summary>A container that can hold one packet for each outbox, used to store |
151 | /// dequeued packets that are being held for throttling</summary> | 151 | /// dequeued packets that are being held for throttling</summary> |
152 | private readonly OutgoingPacket[] m_nextPackets = new OutgoingPacket[THROTTLE_CATEGORY_COUNT]; | 152 | private readonly OutgoingPacket[] m_nextPackets = new OutgoingPacket[THROTTLE_CATEGORY_COUNT]; |
@@ -158,6 +158,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
158 | 158 | ||
159 | private int m_defaultRTO = 1000; // 1sec is the recommendation in the RFC | 159 | private int m_defaultRTO = 1000; // 1sec is the recommendation in the RFC |
160 | private int m_maxRTO = 60000; | 160 | private int m_maxRTO = 60000; |
161 | public bool m_deliverPackets = true; | ||
161 | 162 | ||
162 | /// <summary> | 163 | /// <summary> |
163 | /// Default constructor | 164 | /// Default constructor |
@@ -201,7 +202,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
201 | ThrottleOutPacketType type = (ThrottleOutPacketType)i; | 202 | ThrottleOutPacketType type = (ThrottleOutPacketType)i; |
202 | 203 | ||
203 | // Initialize the packet outboxes, where packets sit while they are waiting for tokens | 204 | // Initialize the packet outboxes, where packets sit while they are waiting for tokens |
204 | m_packetOutboxes[i] = new OpenSim.Framework.LocklessQueue<OutgoingPacket>(); | 205 | m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>(); |
205 | // Initialize the token buckets that control the throttling for each category | 206 | // Initialize the token buckets that control the throttling for each category |
206 | m_throttleCategories[i] = new TokenBucket(m_throttleCategory, rates.GetRate(type)); | 207 | m_throttleCategories[i] = new TokenBucket(m_throttleCategory, rates.GetRate(type)); |
207 | } | 208 | } |
@@ -429,11 +430,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
429 | /// </returns> | 430 | /// </returns> |
430 | public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue) | 431 | public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue) |
431 | { | 432 | { |
433 | return EnqueueOutgoing(packet, forceQueue, false); | ||
434 | } | ||
435 | |||
436 | public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue, bool highPriority) | ||
437 | { | ||
432 | int category = (int)packet.Category; | 438 | int category = (int)packet.Category; |
433 | 439 | ||
434 | if (category >= 0 && category < m_packetOutboxes.Length) | 440 | if (category >= 0 && category < m_packetOutboxes.Length) |
435 | { | 441 | { |
436 | OpenSim.Framework.LocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category]; | 442 | DoubleLocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category]; |
443 | |||
444 | if (m_deliverPackets == false) | ||
445 | { | ||
446 | queue.Enqueue(packet, highPriority); | ||
447 | return true; | ||
448 | } | ||
449 | |||
437 | TokenBucket bucket = m_throttleCategories[category]; | 450 | TokenBucket bucket = m_throttleCategories[category]; |
438 | 451 | ||
439 | // Don't send this packet if there is already a packet waiting in the queue | 452 | // Don't send this packet if there is already a packet waiting in the queue |
@@ -441,7 +454,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
441 | // queued packets | 454 | // queued packets |
442 | if (queue.Count > 0) | 455 | if (queue.Count > 0) |
443 | { | 456 | { |
444 | queue.Enqueue(packet); | 457 | queue.Enqueue(packet, highPriority); |
445 | return true; | 458 | return true; |
446 | } | 459 | } |
447 | 460 | ||
@@ -454,7 +467,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
454 | else | 467 | else |
455 | { | 468 | { |
456 | // Force queue specified or not enough tokens in the bucket, queue this packet | 469 | // Force queue specified or not enough tokens in the bucket, queue this packet |
457 | queue.Enqueue(packet); | 470 | queue.Enqueue(packet, highPriority); |
458 | return true; | 471 | return true; |
459 | } | 472 | } |
460 | } | 473 | } |
@@ -483,8 +496,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
483 | /// <returns>True if any packets were sent, otherwise false</returns> | 496 | /// <returns>True if any packets were sent, otherwise false</returns> |
484 | public bool DequeueOutgoing() | 497 | public bool DequeueOutgoing() |
485 | { | 498 | { |
486 | OutgoingPacket packet; | 499 | if (m_deliverPackets == false) return false; |
487 | OpenSim.Framework.LocklessQueue<OutgoingPacket> queue; | 500 | |
501 | OutgoingPacket packet = null; | ||
502 | DoubleLocklessQueue<OutgoingPacket> queue; | ||
488 | TokenBucket bucket; | 503 | TokenBucket bucket; |
489 | bool packetSent = false; | 504 | bool packetSent = false; |
490 | ThrottleOutPacketTypeFlags emptyCategories = 0; | 505 | ThrottleOutPacketTypeFlags emptyCategories = 0; |
@@ -515,32 +530,49 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
515 | // No dequeued packet waiting to be sent, try to pull one off | 530 | // No dequeued packet waiting to be sent, try to pull one off |
516 | // this queue | 531 | // this queue |
517 | queue = m_packetOutboxes[i]; | 532 | queue = m_packetOutboxes[i]; |
518 | if (queue.Dequeue(out packet)) | 533 | if (queue != null) |
519 | { | 534 | { |
520 | // A packet was pulled off the queue. See if we have | 535 | bool success = false; |
521 | // enough tokens in the bucket to send it out | 536 | try |
522 | if (bucket.RemoveTokens(packet.Buffer.DataLength)) | ||
523 | { | 537 | { |
524 | // Send the packet | 538 | success = queue.Dequeue(out packet); |
525 | m_udpServer.SendPacketFinal(packet); | ||
526 | packetSent = true; | ||
527 | } | 539 | } |
528 | else | 540 | catch |
529 | { | 541 | { |
530 | // Save the dequeued packet for the next iteration | 542 | m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>(); |
531 | m_nextPackets[i] = packet; | ||
532 | } | 543 | } |
533 | 544 | if (success) | |
534 | // If the queue is empty after this dequeue, fire the queue | 545 | { |
535 | // empty callback now so it has a chance to fill before we | 546 | // A packet was pulled off the queue. See if we have |
536 | // get back here | 547 | // enough tokens in the bucket to send it out |
537 | if (queue.Count == 0) | 548 | if (bucket.RemoveTokens(packet.Buffer.DataLength)) |
549 | { | ||
550 | // Send the packet | ||
551 | m_udpServer.SendPacketFinal(packet); | ||
552 | packetSent = true; | ||
553 | } | ||
554 | else | ||
555 | { | ||
556 | // Save the dequeued packet for the next iteration | ||
557 | m_nextPackets[i] = packet; | ||
558 | } | ||
559 | |||
560 | // If the queue is empty after this dequeue, fire the queue | ||
561 | // empty callback now so it has a chance to fill before we | ||
562 | // get back here | ||
563 | if (queue.Count == 0) | ||
564 | emptyCategories |= CategoryToFlag(i); | ||
565 | } | ||
566 | else | ||
567 | { | ||
568 | // No packets in this queue. Fire the queue empty callback | ||
569 | // if it has not been called recently | ||
538 | emptyCategories |= CategoryToFlag(i); | 570 | emptyCategories |= CategoryToFlag(i); |
571 | } | ||
539 | } | 572 | } |
540 | else | 573 | else |
541 | { | 574 | { |
542 | // No packets in this queue. Fire the queue empty callback | 575 | m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>(); |
543 | // if it has not been called recently | ||
544 | emptyCategories |= CategoryToFlag(i); | 576 | emptyCategories |= CategoryToFlag(i); |
545 | } | 577 | } |
546 | } | 578 | } |
@@ -649,6 +681,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
649 | if (m_nextOnQueueEmpty == 0) | 681 | if (m_nextOnQueueEmpty == 0) |
650 | m_nextOnQueueEmpty = 1; | 682 | m_nextOnQueueEmpty = 1; |
651 | } | 683 | } |
684 | internal void ForceThrottleSetting(int throttle, int setting) | ||
685 | { | ||
686 | m_throttleCategories[throttle].RequestedDripRate = Math.Max(setting, LLUDPServer.MTU); ; | ||
687 | } | ||
652 | 688 | ||
653 | /// <summary> | 689 | /// <summary> |
654 | /// Converts a <seealso cref="ThrottleOutPacketType"/> integer to a | 690 | /// Converts a <seealso cref="ThrottleOutPacketType"/> integer to a |
@@ -693,4 +729,33 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
693 | } | 729 | } |
694 | } | 730 | } |
695 | } | 731 | } |
732 | |||
733 | public class DoubleLocklessQueue<T> : OpenSim.Framework.LocklessQueue<T> | ||
734 | { | ||
735 | OpenSim.Framework.LocklessQueue<T> highQueue = new OpenSim.Framework.LocklessQueue<T>(); | ||
736 | |||
737 | public override int Count | ||
738 | { | ||
739 | get | ||
740 | { | ||
741 | return base.Count + highQueue.Count; | ||
742 | } | ||
743 | } | ||
744 | |||
745 | public override bool Dequeue(out T item) | ||
746 | { | ||
747 | if (highQueue.Dequeue(out item)) | ||
748 | return true; | ||
749 | |||
750 | return base.Dequeue(out item); | ||
751 | } | ||
752 | |||
753 | public void Enqueue(T item, bool highPriority) | ||
754 | { | ||
755 | if (highPriority) | ||
756 | highQueue.Enqueue(item); | ||
757 | else | ||
758 | Enqueue(item); | ||
759 | } | ||
760 | } | ||
696 | } | 761 | } |