aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorAdam Frisby2008-10-12 00:56:54 +0000
committerAdam Frisby2008-10-12 00:56:54 +0000
commitdcdfde834fc1bfdcf46357e4106be96e63209c71 (patch)
treed0cb35f669244df729f166b3546b6c3a8cb0f3f0 /OpenSim/Framework
parent* Fixed two major unhandled exceptions discovered during the Pub Quiz on friday. (diff)
downloadopensim-SC_OLD-dcdfde834fc1bfdcf46357e4106be96e63209c71.zip
opensim-SC_OLD-dcdfde834fc1bfdcf46357e4106be96e63209c71.tar.gz
opensim-SC_OLD-dcdfde834fc1bfdcf46357e4106be96e63209c71.tar.bz2
opensim-SC_OLD-dcdfde834fc1bfdcf46357e4106be96e63209c71.tar.xz
LLUDP Client View
* Experimenting with the PacketPool mechanism. * It's still disabled in the code, however there's now a flag to enable it. * Converted to use Generic Collections vs Hashtables, also now uses a list of 'OK to pool' packets, starting with the high volume PacketAck packet.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/PacketPool.cs54
1 files changed, 32 insertions, 22 deletions
diff --git a/OpenSim/Framework/PacketPool.cs b/OpenSim/Framework/PacketPool.cs
index e6c519e..597375c 100644
--- a/OpenSim/Framework/PacketPool.cs
+++ b/OpenSim/Framework/PacketPool.cs
@@ -26,8 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections.Generic;
30using System.Net;
31using OpenMetaverse; 30using OpenMetaverse;
32using OpenMetaverse.Packets; 31using OpenMetaverse.Packets;
33 32
@@ -37,7 +36,9 @@ namespace OpenSim.Framework
37 { 36 {
38 private static readonly PacketPool instance = new PacketPool(); 37 private static readonly PacketPool instance = new PacketPool();
39 38
40 private Hashtable pool = new Hashtable(); 39 private const bool packetPoolEnabled = false;
40
41 private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>();
41 42
42 static PacketPool() 43 static PacketPool()
43 { 44 {
@@ -54,7 +55,7 @@ namespace OpenSim.Framework
54 55
55 lock (pool) 56 lock (pool)
56 { 57 {
57 if (pool[type] == null || ((Stack) pool[type]).Count == 0) 58 if (pool[type] == null || (pool[type]).Count == 0)
58 { 59 {
59 // Creating a new packet if we cannot reuse an old package 60 // Creating a new packet if we cannot reuse an old package
60 packet = Packet.BuildPacket(type); 61 packet = Packet.BuildPacket(type);
@@ -62,7 +63,7 @@ namespace OpenSim.Framework
62 else 63 else
63 { 64 {
64 // Recycle old packages 65 // Recycle old packages
65 packet = (Packet) ((Stack) pool[type]).Pop(); 66 packet = (pool[type]).Pop();
66 } 67 }
67 } 68 }
68 69
@@ -94,13 +95,13 @@ namespace OpenSim.Framework
94 } 95 }
95 else 96 else
96 { 97 {
97 id = (ushort) decoded_header[7]; 98 id = decoded_header[7];
98 freq = PacketFrequency.Medium; 99 freq = PacketFrequency.Medium;
99 } 100 }
100 } 101 }
101 else 102 else
102 { 103 {
103 id = (ushort) decoded_header[6]; 104 id = decoded_header[6];
104 freq = PacketFrequency.High; 105 freq = PacketFrequency.High;
105 } 106 }
106 107
@@ -113,7 +114,7 @@ namespace OpenSim.Framework
113 114
114 int z; 115 int z;
115 for (z = 0 ; z < zeroBuffer.Length ; z++) 116 for (z = 0 ; z < zeroBuffer.Length ; z++)
116 zeroBuffer[z] = (byte)0; 117 zeroBuffer[z] = 0;
117 118
118 int i = 0; 119 int i = 0;
119 Packet packet = GetPacket(type); 120 Packet packet = GetPacket(type);
@@ -127,23 +128,32 @@ namespace OpenSim.Framework
127 /// <param name="packet"></param> 128 /// <param name="packet"></param>
128 public void ReturnPacket(Packet packet) 129 public void ReturnPacket(Packet packet)
129 { 130 {
130 return; // packet pool disabled 131 if(!packetPoolEnabled)
132 return;
131 133
132 /* // Commented out to remove a compiler warning. :) 134 switch(packet.Type)
133 lock (pool)
134 { 135 {
135 PacketType type=packet.Type; 136 // List pooling packets here
136 137 case PacketType.PacketAck:
137 if (pool[type] == null) 138 lock (pool)
138 { 139 {
139 pool[type] = new Stack(); 140 PacketType type = packet.Type;
140 } 141
141 if (((Stack)pool[type]).Count < 50) 142 if (pool[type] == null)
142 { 143 {
143 ((Stack)pool[type]).Push(packet); 144 pool[type] = new Stack<Packet>();
144 } 145 }
146 if ((pool[type]).Count < 50)
147 {
148 (pool[type]).Push(packet);
149 }
150 }
151 break;
152
153 // Other packets wont pool
154 default:
155 return;
145 } 156 }
146 */
147 } 157 }
148 } 158 }
149} 159}