diff options
author | Justin Clarke Casey | 2008-10-17 17:57:18 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-10-17 17:57:18 +0000 |
commit | 7891f821e213639a0f15f2978ee68188f93a12f6 (patch) | |
tree | 0154d40469c97f86dd410124c82f33d292331848 /OpenSim/Region | |
parent | * reverse part of a change that accidentally crept in with the last revision (diff) | |
download | opensim-SC_OLD-7891f821e213639a0f15f2978ee68188f93a12f6.zip opensim-SC_OLD-7891f821e213639a0f15f2978ee68188f93a12f6.tar.gz opensim-SC_OLD-7891f821e213639a0f15f2978ee68188f93a12f6.tar.bz2 opensim-SC_OLD-7891f821e213639a0f15f2978ee68188f93a12f6.tar.xz |
* Instead of creating a new IPEndPoint on every udp packet receive, reuse the existing one
* This requires copying details into a new endpoint when it needs to be stored in client/circuit code hashes
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 20452e0..2a907cc 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | |||
@@ -60,10 +60,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
60 | /// <value> | 60 | /// <value> |
61 | /// The endpoint of a sender of a particular packet. The port is changed by the various socket receive methods | 61 | /// The endpoint of a sender of a particular packet. The port is changed by the various socket receive methods |
62 | /// </value> | 62 | /// </value> |
63 | protected EndPoint epSender; | 63 | protected EndPoint reusedEpSender = new IPEndPoint(IPAddress.Any, 0); |
64 | 64 | protected EndPoint reusedEpProxy; | |
65 | protected EndPoint epProxy; | ||
66 | protected int proxyPortOffset; | 65 | protected int proxyPortOffset; |
66 | |||
67 | protected AsyncCallback ReceivedData; | 67 | protected AsyncCallback ReceivedData; |
68 | protected LLPacketServer m_packetServer; | 68 | protected LLPacketServer m_packetServer; |
69 | protected Location m_location; | 69 | protected Location m_location; |
@@ -175,7 +175,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
175 | /// <param name="result"></param> | 175 | /// <param name="result"></param> |
176 | protected virtual void OnReceivedData(IAsyncResult result) | 176 | protected virtual void OnReceivedData(IAsyncResult result) |
177 | { | 177 | { |
178 | epSender = new IPEndPoint(listenIP, 0); | ||
179 | Packet packet = null; | 178 | Packet packet = null; |
180 | 179 | ||
181 | int numBytes = 1; | 180 | int numBytes = 1; |
@@ -184,7 +183,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
184 | 183 | ||
185 | try | 184 | try |
186 | { | 185 | { |
187 | numBytes = m_socket.EndReceiveFrom(result, ref epSender); | 186 | numBytes = m_socket.EndReceiveFrom(result, ref reusedEpSender); |
188 | ok = true; | 187 | ok = true; |
189 | } | 188 | } |
190 | catch (SocketException e) | 189 | catch (SocketException e) |
@@ -220,10 +219,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
220 | for (z = numBytes ; z < RecvBuffer.Length ; z++) | 219 | for (z = numBytes ; z < RecvBuffer.Length ; z++) |
221 | RecvBuffer[z] = 0; | 220 | RecvBuffer[z] = 0; |
222 | 221 | ||
223 | epProxy = epSender; | 222 | reusedEpProxy = reusedEpSender; |
224 | if (proxyPortOffset != 0) | 223 | if (proxyPortOffset != 0) |
225 | { | 224 | { |
226 | epSender = ProxyCodec.DecodeProxyMessage(RecvBuffer, ref numBytes); | 225 | reusedEpSender = ProxyCodec.DecodeProxyMessage(RecvBuffer, ref numBytes); |
227 | } | 226 | } |
228 | 227 | ||
229 | int packetEnd = numBytes - 1; | 228 | int packetEnd = numBytes - 1; |
@@ -267,7 +266,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
267 | bool ret; | 266 | bool ret; |
268 | lock (clientCircuits) | 267 | lock (clientCircuits) |
269 | { | 268 | { |
270 | ret = clientCircuits.TryGetValue(epSender, out circuit); | 269 | ret = clientCircuits.TryGetValue(reusedEpSender, out circuit); |
271 | } | 270 | } |
272 | 271 | ||
273 | if (ret) | 272 | if (ret) |
@@ -303,7 +302,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
303 | { | 302 | { |
304 | try | 303 | try |
305 | { | 304 | { |
306 | m_socket.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | 305 | m_socket.BeginReceiveFrom( |
306 | RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref reusedEpSender, ReceivedData, null); | ||
307 | } | 307 | } |
308 | catch (SocketException e) | 308 | catch (SocketException e) |
309 | { | 309 | { |
@@ -316,7 +316,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
316 | { | 316 | { |
317 | try | 317 | try |
318 | { | 318 | { |
319 | CloseEndPoint(epSender); | 319 | CloseEndPoint(reusedEpSender); |
320 | } | 320 | } |
321 | catch (Exception a) | 321 | catch (Exception a) |
322 | { | 322 | { |
@@ -324,10 +324,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
324 | } | 324 | } |
325 | 325 | ||
326 | try | 326 | try |
327 | { | 327 | { |
328 | 328 | m_socket.BeginReceiveFrom( | |
329 | m_socket.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, | 329 | RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref reusedEpSender, ReceivedData, null); |
330 | ReceivedData, null); | ||
331 | 330 | ||
332 | // Ter: For some stupid reason ConnectionReset basically kills our async event structure.. | 331 | // Ter: For some stupid reason ConnectionReset basically kills our async event structure.. |
333 | // so therefore.. we've got to tell the server to BeginReceiveFrom again. | 332 | // so therefore.. we've got to tell the server to BeginReceiveFrom again. |
@@ -363,29 +362,48 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
363 | //Slave regions don't accept new clients | 362 | //Slave regions don't accept new clients |
364 | if (m_localScene.Region_Status != RegionStatus.SlaveScene) | 363 | if (m_localScene.Region_Status != RegionStatus.SlaveScene) |
365 | { | 364 | { |
366 | m_log.DebugFormat("[CLIENT]: Adding new circuit for agent {0}, circuit code {1}", useCircuit.CircuitCode.ID, useCircuit.CircuitCode.Code); | 365 | m_log.DebugFormat( |
366 | "[CLIENT]: Adding new circuit for agent {0}, circuit code {1}", | ||
367 | useCircuit.CircuitCode.ID, useCircuit.CircuitCode.Code); | ||
368 | |||
369 | // Copy the current reusedEpSender and reusedEpProxy to store in the maps and hashes, | ||
370 | // since the reused ones will change on the next packet receipt. | ||
371 | IPEndPoint reusedIpEpSender = (IPEndPoint)reusedEpSender; | ||
372 | EndPoint epSender = new IPEndPoint(reusedIpEpSender.Address, reusedIpEpSender.Port); | ||
373 | |||
374 | IPEndPoint reusedIpEpPorxy = (IPEndPoint)reusedEpProxy; | ||
375 | EndPoint epProxy = new IPEndPoint(reusedIpEpPorxy.Address, reusedIpEpPorxy.Port); | ||
367 | 376 | ||
368 | lock (clientCircuits) | 377 | lock (clientCircuits) |
369 | { | 378 | { |
370 | if (!clientCircuits.ContainsKey(epSender)) | 379 | if (!clientCircuits.ContainsKey(epSender)) |
380 | { | ||
371 | clientCircuits.Add(epSender, useCircuit.CircuitCode.Code); | 381 | clientCircuits.Add(epSender, useCircuit.CircuitCode.Code); |
382 | } | ||
372 | else | 383 | else |
373 | m_log.Error("[CLIENT]: clientCircuits already contains entry for user " + useCircuit.CircuitCode.Code + ". NOT adding."); | 384 | { |
385 | m_log.Error( | ||
386 | "[CLIENT]: clientCircuits already contains entry for user " | ||
387 | + useCircuit.CircuitCode.Code + ". NOT adding."); | ||
388 | } | ||
374 | } | 389 | } |
375 | 390 | ||
376 | // This doesn't need locking as it's synchronized data | 391 | // This doesn't need locking as it's synchronized data |
377 | if (!clientCircuits_reverse.ContainsKey(useCircuit.CircuitCode.Code)) | 392 | if (!clientCircuits_reverse.ContainsKey(useCircuit.CircuitCode.Code)) |
378 | clientCircuits_reverse.Add(useCircuit.CircuitCode.Code, epSender); | 393 | clientCircuits_reverse.Add(useCircuit.CircuitCode.Code, epSender); |
379 | else | 394 | else |
380 | m_log.Error("[CLIENT]: clientCurcuits_reverse already contains entry for user " + useCircuit.CircuitCode.Code + ". NOT adding."); | 395 | m_log.Error( |
381 | 396 | "[CLIENT]: clientCurcuits_reverse already contains entry for user " | |
397 | + useCircuit.CircuitCode.Code + ". NOT adding."); | ||
382 | 398 | ||
383 | lock (proxyCircuits) | 399 | lock (proxyCircuits) |
384 | { | 400 | { |
385 | if (!proxyCircuits.ContainsKey(useCircuit.CircuitCode.Code)) | 401 | if (!proxyCircuits.ContainsKey(useCircuit.CircuitCode.Code)) |
386 | proxyCircuits.Add(useCircuit.CircuitCode.Code, epProxy); | 402 | proxyCircuits.Add(useCircuit.CircuitCode.Code, epProxy); |
387 | else | 403 | else |
388 | m_log.Error("[CLIENT]: proxyCircuits already contains entry for user " + useCircuit.CircuitCode.Code + ". NOT adding."); | 404 | m_log.Error( |
405 | "[CLIENT]: proxyCircuits already contains entry for user " | ||
406 | + useCircuit.CircuitCode.Code + ". NOT adding."); | ||
389 | } | 407 | } |
390 | 408 | ||
391 | if (!PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_circuitManager, epProxy)) | 409 | if (!PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_circuitManager, epProxy)) |
@@ -416,9 +434,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
416 | 434 | ||
417 | m_log.Info("[UDPSERVER]: UDP socket bound, getting ready to listen"); | 435 | m_log.Info("[UDPSERVER]: UDP socket bound, getting ready to listen"); |
418 | 436 | ||
419 | epSender = new IPEndPoint(listenIP, 0); | ||
420 | ReceivedData = OnReceivedData; | 437 | ReceivedData = OnReceivedData; |
421 | m_socket.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | 438 | m_socket.BeginReceiveFrom( |
439 | RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref reusedEpSender, ReceivedData, null); | ||
422 | 440 | ||
423 | m_log.Info("[UDPSERVER]: Listening on port " + newPort); | 441 | m_log.Info("[UDPSERVER]: Listening on port " + newPort); |
424 | } | 442 | } |