aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack
diff options
context:
space:
mode:
authorJeff Ames2007-12-20 05:43:02 +0000
committerJeff Ames2007-12-20 05:43:02 +0000
commitbe2ad79e52efb5eb543057e8e73fa601d0b91c87 (patch)
tree688a11b5737835b3cd46b2beaf01c6e9d23ace09 /OpenSim/Region/ClientStack
parent*Added event called after any movement is handled (OnClientMovement) - will b... (diff)
downloadopensim-SC_OLD-be2ad79e52efb5eb543057e8e73fa601d0b91c87.zip
opensim-SC_OLD-be2ad79e52efb5eb543057e8e73fa601d0b91c87.tar.gz
opensim-SC_OLD-be2ad79e52efb5eb543057e8e73fa601d0b91c87.tar.bz2
opensim-SC_OLD-be2ad79e52efb5eb543057e8e73fa601d0b91c87.tar.xz
Added patch from Johan. First attempt to solve the LibSL.Packet GC problem. Works with LibSL rev>1532
Diffstat (limited to 'OpenSim/Region/ClientStack')
-rw-r--r--OpenSim/Region/ClientStack/ClientView.cs37
-rw-r--r--OpenSim/Region/ClientStack/RegionApplicationBase.cs2
-rw-r--r--OpenSim/Region/ClientStack/UDPServer.cs65
3 files changed, 87 insertions, 17 deletions
diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs
index 75c4187..58cb9a2 100644
--- a/OpenSim/Region/ClientStack/ClientView.cs
+++ b/OpenSim/Region/ClientStack/ClientView.cs
@@ -535,7 +535,7 @@ namespace OpenSim.Region.ClientStack
535 /// <param name="regionInfo"></param> 535 /// <param name="regionInfo"></param>
536 public void SendRegionHandshake(RegionInfo regionInfo) 536 public void SendRegionHandshake(RegionInfo regionInfo)
537 { 537 {
538 RegionHandshakePacket handshake = new RegionHandshakePacket(); 538 RegionHandshakePacket handshake = (RegionHandshakePacket) PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
539 539
540 handshake.RegionInfo.BillableFactor = regionInfo.EstateSettings.billableFactor; 540 handshake.RegionInfo.BillableFactor = regionInfo.EstateSettings.billableFactor;
541 handshake.RegionInfo.IsEstateManager = false; 541 handshake.RegionInfo.IsEstateManager = false;
@@ -2187,17 +2187,22 @@ namespace OpenSim.Region.ClientStack
2187 // Actually make the byte array and send it 2187 // Actually make the byte array and send it
2188 try 2188 try
2189 { 2189 {
2190 byte[] sendbuffer = Pack.ToBytes(); 2190 byte[] sendbuffer = Pack.ToBytes();
2191 if (Pack.Header.Zerocoded) 2191 if (Pack is RegionHandshakePacket)
2192 { 2192 {
2193 byte[] ZeroOutBuffer = new byte[4096]; 2193 PacketPool.Instance.ReturnPacket(Pack);
2194 int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); 2194 }
2195 m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode); 2195
2196 } 2196 if (Pack.Header.Zerocoded)
2197 else 2197 {
2198 { 2198 byte[] ZeroOutBuffer = new byte[4096];
2199 m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode); 2199 int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
2200 } 2200 m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode);
2201 }
2202 else
2203 {
2204 m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode);
2205 }
2201 } 2206 }
2202 catch (Exception e) 2207 catch (Exception e)
2203 { 2208 {
@@ -2801,7 +2806,7 @@ namespace OpenSim.Region.ClientStack
2801 case PacketType.AssetUploadRequest: 2806 case PacketType.AssetUploadRequest:
2802 AssetUploadRequestPacket request = (AssetUploadRequestPacket) Pack; 2807 AssetUploadRequestPacket request = (AssetUploadRequestPacket) Pack;
2803 // Console.WriteLine("upload request " + Pack.ToString()); 2808 // Console.WriteLine("upload request " + Pack.ToString());
2804 // Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToStringHyphenated()); 2809 // Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
2805 if (OnAssetUploadRequest != null) 2810 if (OnAssetUploadRequest != null)
2806 { 2811 {
2807 LLUUID temp=libsecondlife.LLUUID.Combine(request.AssetBlock.TransactionID, SecureSessionId); 2812 LLUUID temp=libsecondlife.LLUUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
@@ -2928,7 +2933,7 @@ namespace OpenSim.Region.ClientStack
2928 AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionId)); 2933 AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionId));
2929 if (asset != null) 2934 if (asset != null)
2930 { 2935 {
2931 // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToStringHyphenated() + " already in cache"); 2936 // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToString() + " already in cache");
2932 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset); 2937 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
2933 } 2938 }
2934 else 2939 else
@@ -2936,7 +2941,7 @@ namespace OpenSim.Region.ClientStack
2936 asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID); 2941 asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID);
2937 if (asset != null) 2942 if (asset != null)
2938 { 2943 {
2939 //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToStringHyphenated() + " to cache"); 2944 //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToString() + " to cache");
2940 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset); 2945 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
2941 } 2946 }
2942 else 2947 else
@@ -3351,6 +3356,8 @@ namespace OpenSim.Region.ClientStack
3351 #endregion 3356 #endregion
3352 } 3357 }
3353 } 3358 }
3359
3360 PacketPool.Instance.ReturnPacket(Pack);
3354 } 3361 }
3355 3362
3356 private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket) 3363 private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
index 51155ac..f20b132 100644
--- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs
+++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
@@ -134,7 +134,7 @@ namespace OpenSim.Region.ClientStack
134 134
135 if (masterAvatar != null) 135 if (masterAvatar != null)
136 { 136 {
137 m_log.Verbose("PARCEL", "Found master avatar [" + masterAvatar.UUID.ToStringHyphenated() + "]"); 137 m_log.Verbose("PARCEL", "Found master avatar [" + masterAvatar.UUID.ToString() + "]");
138 scene.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.UUID; 138 scene.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.UUID;
139 } 139 }
140 else 140 else
diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs
index f91e5e2..5cad041 100644
--- a/OpenSim/Region/ClientStack/UDPServer.cs
+++ b/OpenSim/Region/ClientStack/UDPServer.cs
@@ -26,6 +26,7 @@
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Collections;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Net; 31using System.Net;
31using System.Net.Sockets; 32using System.Net.Sockets;
@@ -36,6 +37,68 @@ using OpenSim.Framework.Console;
36 37
37namespace OpenSim.Region.ClientStack 38namespace OpenSim.Region.ClientStack
38{ 39{
40 public sealed class PacketPool
41 {
42 // Set up a thread-safe singleton pattern
43 static PacketPool()
44 {
45 }
46
47 static readonly PacketPool instance = new PacketPool();
48
49 public static PacketPool Instance
50 {
51 get
52 {
53 return instance;
54 }
55 }
56
57 private Hashtable pool = new Hashtable();
58
59 public Packet GetPacket(PacketType type) {
60 Packet packet = null;
61
62 lock(pool)
63 {
64 if(pool[type] == null || ((Stack) pool[type]).Count == 0)
65 {
66 // Creating a new packet if we cannot reuse an old package
67 packet = Packet.BuildPacket(type);
68 }
69 else
70 {
71 // Recycle old packages
72 packet=(Packet) ((Stack) pool[type]).Pop();
73 }
74 }
75
76 return packet;
77 }
78
79 public Packet GetPacket(byte[] bytes, ref int packetEnd, byte[] zeroBuffer) {
80 Packet packet = GetPacket(Packet.GetType(bytes, packetEnd, zeroBuffer));
81
82 int i = 0;
83 packet.FromBytes(bytes, ref i, ref packetEnd, zeroBuffer);
84 return packet;
85 }
86
87 public void ReturnPacket(Packet packet) {
88 lock(pool)
89 {
90 PacketType type=packet.Type;
91
92 if(pool[type] == null)
93 {
94 pool[type] = new Stack();
95 }
96
97 ((Stack) pool[type]).Push(packet);
98 }
99 }
100 }
101
39 public class UDPServer : ClientStackNetworkHandler 102 public class UDPServer : ClientStackNetworkHandler
40 { 103 {
41 protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>(); 104 protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
@@ -194,7 +257,7 @@ namespace OpenSim.Region.ClientStack
194 257
195 try 258 try
196 { 259 {
197 packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); 260 packet = PacketPool.Instance.GetPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
198 } 261 }
199 catch(Exception) 262 catch(Exception)
200 { 263 {