aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs49
1 files changed, 45 insertions, 4 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
index 16c0035..b7df84d 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
@@ -32,19 +32,34 @@ using OpenMetaverse;
32 32
33namespace OpenSim.Region.ClientStack.LindenUDP 33namespace OpenSim.Region.ClientStack.LindenUDP
34{ 34{
35 /// <summary>
36 /// Special collection that is optimized for tracking unacknowledged packets
37 /// </summary>
35 public sealed class UnackedPacketCollection 38 public sealed class UnackedPacketCollection
36 { 39 {
40 /// <summary>Synchronization primitive. A lock must be acquired on this
41 /// object before calling any of the unsafe methods</summary>
37 public object SyncRoot = new object(); 42 public object SyncRoot = new object();
38 43
39 SortedDictionary<uint, OutgoingPacket> packets; 44 /// <summary>Holds the actual unacked packet data, sorted by sequence number</summary>
45 private SortedDictionary<uint, OutgoingPacket> packets = new SortedDictionary<uint, OutgoingPacket>();
40 46
47 /// <summary>Gets the total number of unacked packets</summary>
41 public int Count { get { return packets.Count; } } 48 public int Count { get { return packets.Count; } }
42 49
50 /// <summary>
51 /// Default constructor
52 /// </summary>
43 public UnackedPacketCollection() 53 public UnackedPacketCollection()
44 { 54 {
45 packets = new SortedDictionary<uint, OutgoingPacket>();
46 } 55 }
47 56
57 /// <summary>
58 /// Add an unacked packet to the collection
59 /// </summary>
60 /// <param name="packet">Packet that is awaiting acknowledgement</param>
61 /// <returns>True if the packet was successfully added, false if the
62 /// packet already existed in the collection</returns>
48 public bool Add(OutgoingPacket packet) 63 public bool Add(OutgoingPacket packet)
49 { 64 {
50 lock (SyncRoot) 65 lock (SyncRoot)
@@ -58,11 +73,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
58 } 73 }
59 } 74 }
60 75
76 /// <summary>
77 /// Removes a packet from the collection without attempting to obtain a
78 /// lock first
79 /// </summary>
80 /// <param name="sequenceNumber">Sequence number of the packet to remove</param>
81 /// <returns>True if the packet was found and removed, otherwise false</returns>
61 public bool RemoveUnsafe(uint sequenceNumber) 82 public bool RemoveUnsafe(uint sequenceNumber)
62 { 83 {
63 return packets.Remove(sequenceNumber); 84 return packets.Remove(sequenceNumber);
64 } 85 }
65 86
87 /// <summary>
88 /// Removes a packet from the collection without attempting to obtain a
89 /// lock first
90 /// </summary>
91 /// <param name="sequenceNumber">Sequence number of the packet to remove</param>
92 /// <param name="packet">Returns the removed packet</param>
93 /// <returns>True if the packet was found and removed, otherwise false</returns>
66 public bool RemoveUnsafe(uint sequenceNumber, out OutgoingPacket packet) 94 public bool RemoveUnsafe(uint sequenceNumber, out OutgoingPacket packet)
67 { 95 {
68 if (packets.TryGetValue(sequenceNumber, out packet)) 96 if (packets.TryGetValue(sequenceNumber, out packet))
@@ -74,6 +102,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
74 return false; 102 return false;
75 } 103 }
76 104
105 /// <summary>
106 /// Gets the packet with the lowest sequence number
107 /// </summary>
108 /// <returns>The packet with the lowest sequence number, or null if the
109 /// collection is empty</returns>
77 public OutgoingPacket GetOldest() 110 public OutgoingPacket GetOldest()
78 { 111 {
79 lock (SyncRoot) 112 lock (SyncRoot)
@@ -83,7 +116,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
83 } 116 }
84 } 117 }
85 118
86 public List<OutgoingPacket> GetExpiredPackets(int timeout) 119 /// <summary>
120 /// Returns a list of all of the packets with a TickCount older than
121 /// the specified timeout
122 /// </summary>
123 /// <param name="timeoutMS">Number of ticks (milliseconds) before a
124 /// packet is considered expired</param>
125 /// <returns>A list of all expired packets according to the given
126 /// expiration timeout</returns>
127 public List<OutgoingPacket> GetExpiredPackets(int timeoutMS)
87 { 128 {
88 List<OutgoingPacket> expiredPackets = null; 129 List<OutgoingPacket> expiredPackets = null;
89 130
@@ -95,7 +136,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
95 if (packet.TickCount == 0) 136 if (packet.TickCount == 0)
96 continue; 137 continue;
97 138
98 if (now - packet.TickCount >= timeout) 139 if (now - packet.TickCount >= timeoutMS)
99 { 140 {
100 if (expiredPackets == null) 141 if (expiredPackets == null)
101 expiredPackets = new List<OutgoingPacket>(); 142 expiredPackets = new List<OutgoingPacket>();