aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/PacketPool.cs
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-02 13:16:41 +0000
committerMelanie Thielker2009-05-02 13:16:41 +0000
commit62bcf0e69405ee1443f66eecd1f3fbd684f0c2a5 (patch)
tree24a887f787545c95fcc721cf41ac8c9b17d1ef85 /OpenSim/Framework/PacketPool.cs
parentAlso add these packet to the list of packets to be recycled. No enabled (diff)
downloadopensim-SC_OLD-62bcf0e69405ee1443f66eecd1f3fbd684f0c2a5.zip
opensim-SC_OLD-62bcf0e69405ee1443f66eecd1f3fbd684f0c2a5.tar.gz
opensim-SC_OLD-62bcf0e69405ee1443f66eecd1f3fbd684f0c2a5.tar.bz2
opensim-SC_OLD-62bcf0e69405ee1443f66eecd1f3fbd684f0c2a5.tar.xz
Numerous packet improvements.
Don't allow packets to be resent before they have actually been sent for the first time. Switch from serializing a packet to get it's length to the LibOMV provided Length property. Fix resend timing. Fix the use of dangling references to Acked packets. Fix the packet handler to play nice with the packet pool. Fix the packet pool. Add data block recycling to the packet pool. Packet pool is now ENABLED by default. Add config option to disable packet and data block reuse. Add ObjectUpdate and ImprovedTerseObjectUpdate to the packets being recycled.
Diffstat (limited to 'OpenSim/Framework/PacketPool.cs')
-rw-r--r--OpenSim/Framework/PacketPool.cs104
1 files changed, 60 insertions, 44 deletions
diff --git a/OpenSim/Framework/PacketPool.cs b/OpenSim/Framework/PacketPool.cs
index f17d654..37924d7 100644
--- a/OpenSim/Framework/PacketPool.cs
+++ b/OpenSim/Framework/PacketPool.cs
@@ -41,7 +41,8 @@ namespace OpenSim.Framework
41 41
42 private static readonly PacketPool instance = new PacketPool(); 42 private static readonly PacketPool instance = new PacketPool();
43 43
44 private bool packetPoolEnabled = false; 44 private bool packetPoolEnabled = true;
45 private bool dataBlockPoolEnabled = true;
45 46
46 private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>(); 47 private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>();
47 48
@@ -57,6 +58,18 @@ namespace OpenSim.Framework
57 get { return instance; } 58 get { return instance; }
58 } 59 }
59 60
61 public bool RecyclePackets
62 {
63 set { packetPoolEnabled = value; }
64 get { return packetPoolEnabled; }
65 }
66
67 public bool RecycleDataBlocks
68 {
69 set { dataBlockPoolEnabled = value; }
70 get { return dataBlockPoolEnabled; }
71 }
72
60 public Packet GetPacket(PacketType type) 73 public Packet GetPacket(PacketType type)
61 { 74 {
62 Packet packet; 75 Packet packet;
@@ -140,55 +153,58 @@ namespace OpenSim.Framework
140 /// <param name="packet"></param> 153 /// <param name="packet"></param>
141 public void ReturnPacket(Packet packet) 154 public void ReturnPacket(Packet packet)
142 { 155 {
143 switch (packet.Type) 156 if (dataBlockPoolEnabled)
144 { 157 {
145 case PacketType.ObjectUpdate: 158 switch (packet.Type)
146 ObjectUpdatePacket oup = (ObjectUpdatePacket)packet; 159 {
147 160 case PacketType.ObjectUpdate:
148 foreach (ObjectUpdatePacket.ObjectDataBlock oupod in 161 ObjectUpdatePacket oup = (ObjectUpdatePacket)packet;
149 oup.ObjectData) 162
150 ReturnDataBlock<ObjectUpdatePacket.ObjectDataBlock>(oupod); 163 foreach (ObjectUpdatePacket.ObjectDataBlock oupod in
151 oup.ObjectData = null; 164 oup.ObjectData)
152 break; 165 ReturnDataBlock<ObjectUpdatePacket.ObjectDataBlock>(oupod);
153 166 oup.ObjectData = null;
154 case PacketType.ImprovedTerseObjectUpdate: 167 break;
155 ImprovedTerseObjectUpdatePacket itoup = 168
156 (ImprovedTerseObjectUpdatePacket)packet; 169 case PacketType.ImprovedTerseObjectUpdate:
157 170 ImprovedTerseObjectUpdatePacket itoup =
158 foreach (ImprovedTerseObjectUpdatePacket.ObjectDataBlock 171 (ImprovedTerseObjectUpdatePacket)packet;
159 itoupod in itoup.ObjectData) 172
160 ReturnDataBlock<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>(itoupod); 173 foreach (ImprovedTerseObjectUpdatePacket.ObjectDataBlock
161 itoup.ObjectData = null; 174 itoupod in itoup.ObjectData)
162 break; 175 ReturnDataBlock<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>(itoupod);
176 itoup.ObjectData = null;
177 break;
178 }
163 } 179 }
164 180
165 if (!packetPoolEnabled) 181 if (packetPoolEnabled)
166 return;
167
168 switch (packet.Type)
169 { 182 {
170 // List pooling packets here 183 switch (packet.Type)
171 case PacketType.PacketAck: 184 {
172 case PacketType.ObjectUpdate: 185 // List pooling packets here
173 case PacketType.ImprovedTerseObjectUpdate: 186 case PacketType.PacketAck:
174 lock (pool) 187 case PacketType.ObjectUpdate:
175 { 188 case PacketType.ImprovedTerseObjectUpdate:
176 PacketType type = packet.Type; 189 lock (pool)
177
178 if (!pool.ContainsKey(type))
179 {
180 pool[type] = new Stack<Packet>();
181 }
182 if ((pool[type]).Count < 50)
183 { 190 {
184 (pool[type]).Push(packet); 191 PacketType type = packet.Type;
192
193 if (!pool.ContainsKey(type))
194 {
195 pool[type] = new Stack<Packet>();
196 }
197 if ((pool[type]).Count < 50)
198 {
199 (pool[type]).Push(packet);
200 }
185 } 201 }
186 } 202 break;
187 break; 203
188 204 // Other packets wont pool
189 // Other packets wont pool 205 default:
190 default: 206 return;
191 return; 207 }
192 } 208 }
193 } 209 }
194 210