Make it possible to turn the base UDP object packet pools on and off whilst running via the "debug lludp pool <on|off>" console command. For debug purposes.

This does not currently apply to the higher LLUDP packetpool.
This commit is contained in:
Justin Clark-Casey (justincc)
2012-10-23 02:44:15 +01:00
parent 4578ff74fe
commit 319ebaca06
3 changed files with 132 additions and 51 deletions

View File

@@ -77,6 +77,8 @@ namespace OpenMetaverse
/// <remarks>If IsRunningOut = false, then any request to send a packet is simply dropped.</remarks>
public bool IsRunningOutbound { get; private set; }
private Stat m_poolCountStat;
/// <summary>
/// Default constructor
/// </summary>
@@ -107,27 +109,6 @@ namespace OpenMetaverse
/// necessary</remarks>
public void StartInbound(int recvBufferSize, bool asyncPacketHandling)
{
if (UsePools)
{
m_pool = new Pool<UDPPacketBuffer>(() => new UDPPacketBuffer(), 500);
StatsManager.RegisterStat(
new Stat(
"UDPPacketBufferPoolCount",
"Objects within the UDPPacketBuffer pool",
"The number of objects currently stored within the UDPPacketBuffer pool",
"",
"clientstack",
"packetpool",
StatType.Pull,
stat => stat.Value = m_pool.Count,
StatVerbosity.Debug));
}
else
{
m_pool = null;
}
m_asyncPacketHandling = asyncPacketHandling;
if (!IsRunningInbound)
@@ -197,6 +178,49 @@ namespace OpenMetaverse
IsRunningOutbound = false;
}
protected virtual bool EnablePools()
{
if (!UsePools)
{
m_pool = new Pool<UDPPacketBuffer>(() => new UDPPacketBuffer(), 500);
m_poolCountStat
= new Stat(
"UDPPacketBufferPoolCount",
"Objects within the UDPPacketBuffer pool",
"The number of objects currently stored within the UDPPacketBuffer pool",
"",
"clientstack",
"packetpool",
StatType.Pull,
stat => stat.Value = m_pool.Count,
StatVerbosity.Debug);
StatsManager.RegisterStat(m_poolCountStat);
UsePools = true;
return true;
}
return false;
}
protected virtual bool DisablePools()
{
if (UsePools)
{
UsePools = false;
StatsManager.DeregisterStat(m_poolCountStat);
// We won't null out the pool to avoid a race condition with code that may be in the middle of using it.
return true;
}
return false;
}
private void AsyncBeginReceive()
{
UDPPacketBuffer buf;