Added patch from Johan. First attempt to solve the LibSL.Packet GC problem. Works with LibSL rev>1532

This commit is contained in:
Jeff Ames
2007-12-20 05:43:02 +00:00
parent 8d84156551
commit be2ad79e52
43 changed files with 270 additions and 217 deletions

View File

@@ -535,7 +535,7 @@ namespace OpenSim.Region.ClientStack
/// <param name="regionInfo"></param>
public void SendRegionHandshake(RegionInfo regionInfo)
{
RegionHandshakePacket handshake = new RegionHandshakePacket();
RegionHandshakePacket handshake = (RegionHandshakePacket) PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
handshake.RegionInfo.BillableFactor = regionInfo.EstateSettings.billableFactor;
handshake.RegionInfo.IsEstateManager = false;
@@ -2187,17 +2187,22 @@ namespace OpenSim.Region.ClientStack
// Actually make the byte array and send it
try
{
byte[] sendbuffer = Pack.ToBytes();
if (Pack.Header.Zerocoded)
{
byte[] ZeroOutBuffer = new byte[4096];
int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode);
}
else
{
m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode);
}
byte[] sendbuffer = Pack.ToBytes();
if (Pack is RegionHandshakePacket)
{
PacketPool.Instance.ReturnPacket(Pack);
}
if (Pack.Header.Zerocoded)
{
byte[] ZeroOutBuffer = new byte[4096];
int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode);
}
else
{
m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode);
}
}
catch (Exception e)
{
@@ -2801,7 +2806,7 @@ namespace OpenSim.Region.ClientStack
case PacketType.AssetUploadRequest:
AssetUploadRequestPacket request = (AssetUploadRequestPacket) Pack;
// Console.WriteLine("upload request " + Pack.ToString());
// Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToStringHyphenated());
// Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
if (OnAssetUploadRequest != null)
{
LLUUID temp=libsecondlife.LLUUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
@@ -2928,7 +2933,7 @@ namespace OpenSim.Region.ClientStack
AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionId));
if (asset != null)
{
// Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToStringHyphenated() + " already in cache");
// Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToString() + " already in cache");
m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
}
else
@@ -2936,7 +2941,7 @@ namespace OpenSim.Region.ClientStack
asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID);
if (asset != null)
{
//Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToStringHyphenated() + " to cache");
//Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToString() + " to cache");
m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
}
else
@@ -3351,6 +3356,8 @@ namespace OpenSim.Region.ClientStack
#endregion
}
}
PacketPool.Instance.ReturnPacket(Pack);
}
private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)

View File

@@ -134,7 +134,7 @@ namespace OpenSim.Region.ClientStack
if (masterAvatar != null)
{
m_log.Verbose("PARCEL", "Found master avatar [" + masterAvatar.UUID.ToStringHyphenated() + "]");
m_log.Verbose("PARCEL", "Found master avatar [" + masterAvatar.UUID.ToString() + "]");
scene.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.UUID;
}
else

View File

@@ -26,6 +26,7 @@
*
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
@@ -36,6 +37,68 @@ using OpenSim.Framework.Console;
namespace OpenSim.Region.ClientStack
{
public sealed class PacketPool
{
// Set up a thread-safe singleton pattern
static PacketPool()
{
}
static readonly PacketPool instance = new PacketPool();
public static PacketPool Instance
{
get
{
return instance;
}
}
private Hashtable pool = new Hashtable();
public Packet GetPacket(PacketType type) {
Packet packet = null;
lock(pool)
{
if(pool[type] == null || ((Stack) pool[type]).Count == 0)
{
// Creating a new packet if we cannot reuse an old package
packet = Packet.BuildPacket(type);
}
else
{
// Recycle old packages
packet=(Packet) ((Stack) pool[type]).Pop();
}
}
return packet;
}
public Packet GetPacket(byte[] bytes, ref int packetEnd, byte[] zeroBuffer) {
Packet packet = GetPacket(Packet.GetType(bytes, packetEnd, zeroBuffer));
int i = 0;
packet.FromBytes(bytes, ref i, ref packetEnd, zeroBuffer);
return packet;
}
public void ReturnPacket(Packet packet) {
lock(pool)
{
PacketType type=packet.Type;
if(pool[type] == null)
{
pool[type] = new Stack();
}
((Stack) pool[type]).Push(packet);
}
}
}
public class UDPServer : ClientStackNetworkHandler
{
protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
@@ -194,7 +257,7 @@ namespace OpenSim.Region.ClientStack
try
{
packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
packet = PacketPool.Instance.GetPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
}
catch(Exception)
{