aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/UDPServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/UDPServer.cs')
-rw-r--r--OpenSim/Region/ClientStack/UDPServer.cs87
1 files changed, 41 insertions, 46 deletions
diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs
index 47e0b3c..10435bf 100644
--- a/OpenSim/Region/ClientStack/UDPServer.cs
+++ b/OpenSim/Region/ClientStack/UDPServer.cs
@@ -30,6 +30,7 @@ using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Net; 31using System.Net;
32using System.Net.Sockets; 32using System.Net.Sockets;
33using libsecondlife;
33using libsecondlife.Packets; 34using libsecondlife.Packets;
34using OpenSim.Framework; 35using OpenSim.Framework;
35using OpenSim.Framework.Communications.Cache; 36using OpenSim.Framework.Communications.Cache;
@@ -44,24 +45,22 @@ namespace OpenSim.Region.ClientStack
44 { 45 {
45 } 46 }
46 47
47 static readonly PacketPool instance = new PacketPool(); 48 private static readonly PacketPool instance = new PacketPool();
48 49
49 public static PacketPool Instance 50 public static PacketPool Instance
50 { 51 {
51 get 52 get { return instance; }
52 {
53 return instance;
54 }
55 } 53 }
56 54
57 private Hashtable pool = new Hashtable(); 55 private Hashtable pool = new Hashtable();
58 56
59 public Packet GetPacket(PacketType type) { 57 public Packet GetPacket(PacketType type)
58 {
60 Packet packet = null; 59 Packet packet = null;
61 60
62 lock(pool) 61 lock (pool)
63 { 62 {
64 if(pool[type] == null || ((Stack) pool[type]).Count == 0) 63 if (pool[type] == null || ((Stack) pool[type]).Count == 0)
65 { 64 {
66 // Creating a new packet if we cannot reuse an old package 65 // Creating a new packet if we cannot reuse an old package
67 packet = Packet.BuildPacket(type); 66 packet = Packet.BuildPacket(type);
@@ -69,30 +68,33 @@ namespace OpenSim.Region.ClientStack
69 else 68 else
70 { 69 {
71 // Recycle old packages 70 // Recycle old packages
72 packet=(Packet) ((Stack) pool[type]).Pop(); 71 packet = (Packet) ((Stack) pool[type]).Pop();
73 } 72 }
74 } 73 }
75 74
76 return packet; 75 return packet;
77 } 76 }
78 77
79 public Packet GetPacket(byte[] bytes, ref int packetEnd, byte[] zeroBuffer) { 78 public Packet GetPacket(byte[] bytes, ref int packetEnd, byte[] zeroBuffer)
79 {
80 Packet packet = GetPacket(GetType(bytes, packetEnd, zeroBuffer)); 80 Packet packet = GetPacket(GetType(bytes, packetEnd, zeroBuffer));
81 81
82 int i = 0; 82 int i = 0;
83 packet.FromBytes(bytes, ref i, ref packetEnd, zeroBuffer); 83 packet.FromBytes(bytes, ref i, ref packetEnd, zeroBuffer);
84 return packet; 84 return packet;
85 } 85 }
86
86 public PacketType GetType(byte[] bytes, int packetEnd, byte[] zeroBuffer) 87 public PacketType GetType(byte[] bytes, int packetEnd, byte[] zeroBuffer)
87 { 88 {
88 //Function removed from LibSL revision 1540 89 //Function removed from LibSL revision 1540
89 // We're using it.. so Built it into UDP server for now.. 90 // We're using it.. so Built it into UDP server for now..
90 ushort id; libsecondlife.PacketFrequency freq; 91 ushort id;
92 PacketFrequency freq;
91 int i = 0, end = packetEnd; 93 int i = 0, end = packetEnd;
92 Header header = Header.BuildHeader(bytes, ref i, ref end); 94 Header header = Header.BuildHeader(bytes, ref i, ref end);
93 if (header.Zerocoded) 95 if (header.Zerocoded)
94 { 96 {
95 end = libsecondlife.Helpers.ZeroDecode(bytes, end + 1, zeroBuffer) - 1; 97 end = Helpers.ZeroDecode(bytes, end + 1, zeroBuffer) - 1;
96 bytes = zeroBuffer; 98 bytes = zeroBuffer;
97 } 99 }
98 100
@@ -100,25 +102,30 @@ namespace OpenSim.Region.ClientStack
100 { 102 {
101 if (bytes[7] == 0xFF) 103 if (bytes[7] == 0xFF)
102 { 104 {
103 id = (ushort)((bytes[8] << 8) + bytes[9]); freq = libsecondlife.PacketFrequency.Low; 105 id = (ushort) ((bytes[8] << 8) + bytes[9]);
106 freq = PacketFrequency.Low;
104 } 107 }
105 else 108 else
106 { 109 {
107 id = (ushort)bytes[7]; freq = libsecondlife.PacketFrequency.Medium; 110 id = (ushort) bytes[7];
111 freq = PacketFrequency.Medium;
108 } 112 }
109 } 113 }
110 else 114 else
111 { 115 {
112 id = (ushort)bytes[6]; freq = libsecondlife.PacketFrequency.High; 116 id = (ushort) bytes[6];
117 freq = PacketFrequency.High;
113 } 118 }
114 return Packet.GetType(id, freq); 119 return Packet.GetType(id, freq);
115 } 120 }
116 public void ReturnPacket(Packet packet) { 121
117 lock(pool) 122 public void ReturnPacket(Packet packet)
123 {
124 lock (pool)
118 { 125 {
119 PacketType type=packet.Type; 126 PacketType type = packet.Type;
120 127
121 if(pool[type] == null) 128 if (pool[type] == null)
122 { 129 {
123 pool[type] = new Stack(); 130 pool[type] = new Stack();
124 } 131 }
@@ -162,15 +169,11 @@ namespace OpenSim.Region.ClientStack
162 m_packetServer.LocalScene = m_localScene; 169 m_packetServer.LocalScene = m_localScene;
163 m_regionHandle = m_localScene.RegionInfo.RegionHandle; 170 m_regionHandle = m_localScene.RegionInfo.RegionHandle;
164 } 171 }
165
166 } 172 }
167 173
168 public ulong RegionHandle 174 public ulong RegionHandle
169 { 175 {
170 get 176 get { return m_regionHandle; }
171 {
172 return m_regionHandle;
173 }
174 } 177 }
175 178
176 public UDPServer() 179 public UDPServer()
@@ -212,30 +215,29 @@ namespace OpenSim.Region.ClientStack
212 case SocketError.AlreadyInProgress: 215 case SocketError.AlreadyInProgress:
213 case SocketError.NetworkReset: 216 case SocketError.NetworkReset:
214 case SocketError.ConnectionReset: 217 case SocketError.ConnectionReset:
215 218
216 try 219 try
217 { 220 {
218 CloseEndPoint(epSender); 221 CloseEndPoint(epSender);
219 } 222 }
220 catch (System.Exception a) 223 catch (Exception a)
221 { 224 {
222 MainLog.Instance.Verbose("UDPSERVER", a.ToString()); 225 MainLog.Instance.Verbose("UDPSERVER", a.ToString());
223 } 226 }
224 try 227 try
225 { 228 {
226 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); 229 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender,
227 230 ReceivedData, null);
231
228 // Ter: For some stupid reason ConnectionReset basically kills our async event structure.. 232 // Ter: For some stupid reason ConnectionReset basically kills our async event structure..
229 // so therefore.. we've got to tell the server to BeginReceiveFrom again. 233 // so therefore.. we've got to tell the server to BeginReceiveFrom again.
230 // This will happen over and over until we've gone through all packets 234 // This will happen over and over until we've gone through all packets
231 // sent to and from this particular user. 235 // sent to and from this particular user.
232 // Stupid I know.. 236 // Stupid I know..
233 // but Flusing the buffer would be even more stupid... so, we're stuck with this ugly method. 237 // but Flusing the buffer would be even more stupid... so, we're stuck with this ugly method.
234
235 } 238 }
236 catch (SocketException) 239 catch (SocketException)
237 { 240 {
238
239 } 241 }
240 break; 242 break;
241 default: 243 default:
@@ -243,13 +245,14 @@ namespace OpenSim.Region.ClientStack
243 { 245 {
244 CloseEndPoint(epSender); 246 CloseEndPoint(epSender);
245 } 247 }
246 catch (System.Exception) 248 catch (Exception)
247 { 249 {
248 //MainLog.Instance.Verbose("UDPSERVER", a.ToString()); 250 //MainLog.Instance.Verbose("UDPSERVER", a.ToString());
249 } 251 }
250 try 252 try
251 { 253 {
252 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); 254 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender,
255 ReceivedData, null);
253 256
254 // Ter: For some stupid reason ConnectionReset basically kills our async event structure.. 257 // Ter: For some stupid reason ConnectionReset basically kills our async event structure..
255 // so therefore.. we've got to tell the server to BeginReceiveFrom again. 258 // so therefore.. we've got to tell the server to BeginReceiveFrom again.
@@ -257,17 +260,15 @@ namespace OpenSim.Region.ClientStack
257 // sent to and from this particular user. 260 // sent to and from this particular user.
258 // Stupid I know.. 261 // Stupid I know..
259 // but Flusing the buffer would be even more stupid... so, we're stuck with this ugly method. 262 // but Flusing the buffer would be even more stupid... so, we're stuck with this ugly method.
260
261 } 263 }
262 catch (SocketException) 264 catch (SocketException)
263 { 265 {
264
265 } 266 }
266 267
267 // Here's some reference code! :D 268 // Here's some reference code! :D
268 // Shutdown and restart the UDP listener! hehe 269 // Shutdown and restart the UDP listener! hehe
269 // Shiny 270 // Shiny
270 271
271 //Server.Shutdown(SocketShutdown.Both); 272 //Server.Shutdown(SocketShutdown.Both);
272 //CloseEndPoint(epSender); 273 //CloseEndPoint(epSender);
273 //ServerListener(); 274 //ServerListener();
@@ -276,7 +277,7 @@ namespace OpenSim.Region.ClientStack
276 277
277 return; 278 return;
278 } 279 }
279 catch (System.ObjectDisposedException) 280 catch (ObjectDisposedException)
280 { 281 {
281 //MainLog.Instance.Debug("UDPSERVER", e.ToString()); 282 //MainLog.Instance.Debug("UDPSERVER", e.ToString());
282 return; 283 return;
@@ -288,7 +289,7 @@ namespace OpenSim.Region.ClientStack
288 { 289 {
289 packet = PacketPool.Instance.GetPacket(RecvBuffer, ref packetEnd, ZeroBuffer); 290 packet = PacketPool.Instance.GetPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
290 } 291 }
291 catch(Exception) 292 catch (Exception)
292 { 293 {
293 //MainLog.Instance.Debug("UDPSERVER", e.ToString()); 294 //MainLog.Instance.Debug("UDPSERVER", e.ToString());
294 } 295 }
@@ -311,7 +312,6 @@ namespace OpenSim.Region.ClientStack
311 } 312 }
312 else 313 else
313 { 314 {
314
315 // invalid client 315 // invalid client
316 //CFK: This message seems to have served its usefullness as of 12-15 so I am commenting it out for now 316 //CFK: This message seems to have served its usefullness as of 12-15 so I am commenting it out for now
317 //m_log.Warn("client", "Got a packet from an invalid client - " + epSender.ToString()); 317 //m_log.Warn("client", "Got a packet from an invalid client - " + epSender.ToString());
@@ -326,9 +326,7 @@ namespace OpenSim.Region.ClientStack
326 uint circuit; 326 uint circuit;
327 if (clientCircuits.TryGetValue(sender, out circuit)) 327 if (clientCircuits.TryGetValue(sender, out circuit))
328 { 328 {
329
330 m_packetServer.CloseCircuit(circuit); 329 m_packetServer.CloseCircuit(circuit);
331
332 } 330 }
333 } 331 }
334 332
@@ -381,14 +379,11 @@ namespace OpenSim.Region.ClientStack
381 EndPoint sendto = null; 379 EndPoint sendto = null;
382 if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto)) 380 if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto))
383 { 381 {
384
385 clientCircuits.Remove(sendto); 382 clientCircuits.Remove(sendto);
386
387 383
388 384
389 clientCircuits_reverse.Remove(circuitcode); 385 clientCircuits_reverse.Remove(circuitcode);
390
391 } 386 }
392 } 387 }
393 } 388 }
394} 389} \ No newline at end of file