LLUDP Client View
* Experimenting with the PacketPool mechanism. * It's still disabled in the code, however there's now a flag to enable it. * Converted to use Generic Collections vs Hashtables, also now uses a list of 'OK to pool' packets, starting with the high volume PacketAck packet.0.6.0-stable
parent
d10a578096
commit
dcdfde834f
|
@ -26,8 +26,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using OpenMetaverse.Packets;
|
using OpenMetaverse.Packets;
|
||||||
|
|
||||||
|
@ -37,7 +36,9 @@ namespace OpenSim.Framework
|
||||||
{
|
{
|
||||||
private static readonly PacketPool instance = new PacketPool();
|
private static readonly PacketPool instance = new PacketPool();
|
||||||
|
|
||||||
private Hashtable pool = new Hashtable();
|
private const bool packetPoolEnabled = false;
|
||||||
|
|
||||||
|
private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>();
|
||||||
|
|
||||||
static PacketPool()
|
static PacketPool()
|
||||||
{
|
{
|
||||||
|
@ -54,7 +55,7 @@ namespace OpenSim.Framework
|
||||||
|
|
||||||
lock (pool)
|
lock (pool)
|
||||||
{
|
{
|
||||||
if (pool[type] == null || ((Stack) pool[type]).Count == 0)
|
if (pool[type] == null || (pool[type]).Count == 0)
|
||||||
{
|
{
|
||||||
// Creating a new packet if we cannot reuse an old package
|
// Creating a new packet if we cannot reuse an old package
|
||||||
packet = Packet.BuildPacket(type);
|
packet = Packet.BuildPacket(type);
|
||||||
|
@ -62,7 +63,7 @@ namespace OpenSim.Framework
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Recycle old packages
|
// Recycle old packages
|
||||||
packet = (Packet) ((Stack) pool[type]).Pop();
|
packet = (pool[type]).Pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,13 +95,13 @@ namespace OpenSim.Framework
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
id = (ushort) decoded_header[7];
|
id = decoded_header[7];
|
||||||
freq = PacketFrequency.Medium;
|
freq = PacketFrequency.Medium;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
id = (ushort) decoded_header[6];
|
id = decoded_header[6];
|
||||||
freq = PacketFrequency.High;
|
freq = PacketFrequency.High;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ namespace OpenSim.Framework
|
||||||
|
|
||||||
int z;
|
int z;
|
||||||
for (z = 0 ; z < zeroBuffer.Length ; z++)
|
for (z = 0 ; z < zeroBuffer.Length ; z++)
|
||||||
zeroBuffer[z] = (byte)0;
|
zeroBuffer[z] = 0;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Packet packet = GetPacket(type);
|
Packet packet = GetPacket(type);
|
||||||
|
@ -127,23 +128,32 @@ namespace OpenSim.Framework
|
||||||
/// <param name="packet"></param>
|
/// <param name="packet"></param>
|
||||||
public void ReturnPacket(Packet packet)
|
public void ReturnPacket(Packet packet)
|
||||||
{
|
{
|
||||||
return; // packet pool disabled
|
if(!packetPoolEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
/* // Commented out to remove a compiler warning. :)
|
switch(packet.Type)
|
||||||
|
{
|
||||||
|
// List pooling packets here
|
||||||
|
case PacketType.PacketAck:
|
||||||
lock (pool)
|
lock (pool)
|
||||||
{
|
{
|
||||||
PacketType type=packet.Type;
|
PacketType type = packet.Type;
|
||||||
|
|
||||||
if (pool[type] == null)
|
if (pool[type] == null)
|
||||||
{
|
{
|
||||||
pool[type] = new Stack();
|
pool[type] = new Stack<Packet>();
|
||||||
}
|
}
|
||||||
if (((Stack)pool[type]).Count < 50)
|
if ((pool[type]).Count < 50)
|
||||||
{
|
{
|
||||||
((Stack)pool[type]).Push(packet);
|
(pool[type]).Push(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
break;
|
||||||
|
|
||||||
|
// Other packets wont pool
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,6 +327,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
m_socket.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender,
|
m_socket.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender,
|
||||||
ReceivedData, null);
|
ReceivedData, null);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue