diff options
author | Johan Berntsson | 2008-03-04 05:31:54 +0000 |
---|---|---|
committer | Johan Berntsson | 2008-03-04 05:31:54 +0000 |
commit | 279e0061c515ee0a03036bef68eea9738273d785 (patch) | |
tree | 4502228eb7b87a760e0b0e67aded9d1d870d0bed /OpenSim/Framework/PacketPool.cs | |
parent | Added copyright heaaders. Minor cleanup. (diff) | |
download | opensim-SC-279e0061c515ee0a03036bef68eea9738273d785.zip opensim-SC-279e0061c515ee0a03036bef68eea9738273d785.tar.gz opensim-SC-279e0061c515ee0a03036bef68eea9738273d785.tar.bz2 opensim-SC-279e0061c515ee0a03036bef68eea9738273d785.tar.xz |
Merged 3Di code that provides scene and avatar serialization, and plugin support for region move/split/merge. See ThirdParty/3Di/README.txt. Unless the new modules are used there should be no noticeable changes when running OpenSim.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/PacketPool.cs | 104 |
1 files changed, 61 insertions, 43 deletions
diff --git a/OpenSim/Framework/PacketPool.cs b/OpenSim/Framework/PacketPool.cs index 30b6d6a..2c44ae3 100644 --- a/OpenSim/Framework/PacketPool.cs +++ b/OpenSim/Framework/PacketPool.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.Net; | ||
29 | using System.Collections; | 30 | using System.Collections; |
30 | using libsecondlife.Packets; | 31 | using libsecondlife.Packets; |
31 | 32 | ||
@@ -33,29 +34,68 @@ namespace OpenSim.Framework | |||
33 | { | 34 | { |
34 | public sealed class PacketPool | 35 | public sealed class PacketPool |
35 | { | 36 | { |
37 | static public void EncodeProxyMessage(byte[] bytes, ref int numBytes, EndPoint trueEP) | ||
38 | { | ||
39 | if( numBytes > 4090 ) // max UPD size = 4096 | ||
40 | { | ||
41 | throw new Exception("ERROR: No space to encode the proxy EP"); | ||
42 | } | ||
43 | |||
44 | ushort port = (ushort) ((IPEndPoint) trueEP).Port; | ||
45 | bytes[numBytes++] = (byte)(port % 256); | ||
46 | bytes[numBytes++] = (byte)(port / 256); | ||
47 | |||
48 | foreach (byte b in ((IPEndPoint)trueEP).Address.GetAddressBytes()) | ||
49 | { | ||
50 | bytes[numBytes++] = b; | ||
51 | } | ||
52 | |||
53 | int x = numBytes; | ||
54 | |||
55 | DecodeProxyMessage(bytes, ref numBytes); | ||
56 | |||
57 | numBytes = x; | ||
58 | } | ||
59 | |||
60 | static public EndPoint DecodeProxyMessage(byte[] bytes, ref int numBytes) | ||
61 | { | ||
62 | // IPv4 Only | ||
63 | byte[] addr = new byte[4]; | ||
64 | |||
65 | addr[3] = bytes[--numBytes]; | ||
66 | addr[2] = bytes[--numBytes]; | ||
67 | addr[1] = bytes[--numBytes]; | ||
68 | addr[0] = bytes[--numBytes]; | ||
69 | |||
70 | ushort port = (ushort)(bytes[--numBytes] * 256); | ||
71 | port += (ushort)bytes[--numBytes]; | ||
72 | |||
73 | return (EndPoint) new IPEndPoint(new IPAddress(addr), (int)port); | ||
74 | } | ||
75 | |||
36 | // Set up a thread-safe singleton pattern | 76 | // Set up a thread-safe singleton pattern |
37 | static PacketPool() | 77 | static PacketPool() |
38 | { | 78 | { |
39 | } | 79 | } |
40 | 80 | ||
41 | private static readonly PacketPool instance = new PacketPool(); | 81 | static readonly PacketPool instance = new PacketPool(); |
42 | 82 | ||
43 | public static PacketPool Instance | 83 | public static PacketPool Instance |
44 | { | 84 | { |
45 | get { return instance; } | 85 | get |
86 | { | ||
87 | return instance; | ||
88 | } | ||
46 | } | 89 | } |
47 | 90 | ||
48 | private Hashtable pool = new Hashtable(); | 91 | private Hashtable pool = new Hashtable(); |
49 | 92 | ||
50 | public Packet GetPacket(PacketType type) | 93 | public Packet GetPacket(PacketType type) { |
51 | { | ||
52 | return Packet.BuildPacket(type); | ||
53 | /* Skip until PacketPool performance problems have been resolved (mantis 281) | ||
54 | Packet packet = null; | 94 | Packet packet = null; |
55 | 95 | ||
56 | lock (pool) | 96 | lock(pool) |
57 | { | 97 | { |
58 | if (pool[type] == null || ((Stack) pool[type]).Count == 0) | 98 | if(pool[type] == null || ((Stack) pool[type]).Count == 0) |
59 | { | 99 | { |
60 | // Creating a new packet if we cannot reuse an old package | 100 | // Creating a new packet if we cannot reuse an old package |
61 | packet = Packet.BuildPacket(type); | 101 | packet = Packet.BuildPacket(type); |
@@ -63,39 +103,16 @@ namespace OpenSim.Framework | |||
63 | else | 103 | else |
64 | { | 104 | { |
65 | // Recycle old packages | 105 | // Recycle old packages |
66 | packet = (Packet) ((Stack) pool[type]).Pop(); | 106 | packet=(Packet) ((Stack) pool[type]).Pop(); |
67 | } | 107 | } |
68 | } | 108 | } |
69 | 109 | ||
70 | return packet; | 110 | return packet; |
71 | */ | ||
72 | } | ||
73 | |||
74 | // Copied from LibSL, and added a check to avoid overwriting the | ||
75 | // buffer | ||
76 | private void ZeroDecodeCommand(byte[] src, byte[] dest) | ||
77 | { | ||
78 | for (int srcPos = 6, destPos = 6; destPos < 10; ++srcPos) | ||
79 | { | ||
80 | if (src[srcPos] == 0x00) | ||
81 | { | ||
82 | for (byte j = 0; j < src[srcPos + 1] && destPos < 10; ++j) | ||
83 | { | ||
84 | dest[destPos++] = 0x00; | ||
85 | } | ||
86 | ++srcPos; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | dest[destPos++] = src[srcPos]; | ||
91 | } | ||
92 | } | ||
93 | } | 111 | } |
94 | 112 | ||
113 | private byte[] decoded_header = new byte[10]; | ||
95 | private PacketType GetType(byte[] bytes) | 114 | private PacketType GetType(byte[] bytes) |
96 | { | 115 | { |
97 | byte[] decoded_header = new byte[10]; | ||
98 | |||
99 | ushort id; | 116 | ushort id; |
100 | libsecondlife.PacketFrequency freq; | 117 | libsecondlife.PacketFrequency freq; |
101 | 118 | ||
@@ -103,7 +120,7 @@ namespace OpenSim.Framework | |||
103 | 120 | ||
104 | if((bytes[0] & libsecondlife.Helpers.MSG_ZEROCODED)!=0) | 121 | if((bytes[0] & libsecondlife.Helpers.MSG_ZEROCODED)!=0) |
105 | { | 122 | { |
106 | ZeroDecodeCommand(bytes, decoded_header); | 123 | libsecondlife.Helpers.ZeroDecodeCommand(bytes, decoded_header); |
107 | } | 124 | } |
108 | 125 | ||
109 | if (decoded_header[6] == 0xFF) | 126 | if (decoded_header[6] == 0xFF) |
@@ -138,21 +155,22 @@ namespace OpenSim.Framework | |||
138 | return packet; | 155 | return packet; |
139 | } | 156 | } |
140 | 157 | ||
141 | public void ReturnPacket(Packet packet) | 158 | public void ReturnPacket(Packet packet) { |
142 | { | 159 | return; // packet pool disabled |
143 | /* Skip until PacketPool performance problems have been resolved (mantis 281) | 160 | |
144 | lock (pool) | 161 | lock(pool) |
145 | { | 162 | { |
146 | PacketType type = packet.Type; | 163 | PacketType type=packet.Type; |
147 | 164 | ||
148 | if (pool[type] == null) | 165 | if(pool[type] == null) |
149 | { | 166 | { |
150 | pool[type] = new Stack(); | 167 | pool[type] = new Stack(); |
151 | } | 168 | } |
152 | 169 | if (((Stack)pool[type]).Count < 50) | |
153 | ((Stack) pool[type]).Push(packet); | 170 | { |
171 | ((Stack)pool[type]).Push(packet); | ||
172 | } | ||
154 | } | 173 | } |
155 | */ | ||
156 | } | 174 | } |
157 | } | 175 | } |
158 | } | 176 | } |