Merge branch 'master' into careminster

Conflicts:
	OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
avinationmerge
Melanie 2012-10-17 23:50:48 +01:00
commit 9b68446811
4 changed files with 62 additions and 14 deletions

View File

@ -45,7 +45,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public Packet Packet; public Packet Packet;
/// <summary> /// <summary>
/// Default constructor /// No arg constructor.
/// </summary>
public IncomingPacket() {}
/// <summary>
/// Constructor
/// </summary> /// </summary>
/// <param name="client">Reference to the client this packet came from</param> /// <param name="client">Reference to the client this packet came from</param>
/// <param name="packet">Packet data</param> /// <param name="packet">Packet data</param>

View File

@ -5522,16 +5522,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#region Scene/Avatar #region Scene/Avatar
private bool HandleAgentUpdate(IClientAPI sener, Packet Pack) private bool HandleAgentUpdate(IClientAPI sener, Packet packet)
{ {
if (OnAgentUpdate != null) if (OnAgentUpdate != null)
{ {
bool update = false; bool update = false;
AgentUpdatePacket agenUpdate = (AgentUpdatePacket)Pack; AgentUpdatePacket agenUpdate = (AgentUpdatePacket)packet;
#region Packet Session and User Check #region Packet Session and User Check
if (agenUpdate.AgentData.SessionID != SessionId || agenUpdate.AgentData.AgentID != AgentId) if (agenUpdate.AgentData.SessionID != SessionId || agenUpdate.AgentData.AgentID != AgentId)
{
PacketPool.Instance.ReturnPacket(packet);
return false; return false;
}
#endregion #endregion
AgentUpdatePacket.AgentDataBlock x = agenUpdate.AgentData; AgentUpdatePacket.AgentDataBlock x = agenUpdate.AgentData;
@ -5597,6 +5600,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
} }
PacketPool.Instance.ReturnPacket(packet);
return true; return true;
} }
@ -12041,8 +12046,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (!ProcessPacketMethod(packet)) if (!ProcessPacketMethod(packet))
m_log.Warn("[CLIENT]: unhandled packet " + packet.Type); m_log.Warn("[CLIENT]: unhandled packet " + packet.Type);
PacketPool.Instance.ReturnPacket(packet);
} }
private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket) private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)

View File

@ -171,6 +171,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
protected bool m_sendPing; protected bool m_sendPing;
private ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>> m_pendingCache = new ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>>(); private ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>> m_pendingCache = new ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>>();
private Pool<IncomingPacket> m_incomingPacketPool;
private int m_defaultRTO = 0; private int m_defaultRTO = 0;
private int m_maxRTO = 0; private int m_maxRTO = 0;
@ -278,6 +279,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_throttle = new TokenBucket(null, sceneThrottleBps); m_throttle = new TokenBucket(null, sceneThrottleBps);
ThrottleRates = new ThrottleRates(configSource); ThrottleRates = new ThrottleRates(configSource);
if (UsePools)
m_incomingPacketPool = new Pool<IncomingPacket>(() => new IncomingPacket(), 500);
} }
public void Start() public void Start()
@ -313,7 +317,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
base.StartOutbound(); base.StartOutbound();
// This thread will process the packets received that are placed on the packetInbox
Watchdog.StartThread( Watchdog.StartThread(
OutgoingPacketHandler, OutgoingPacketHandler,
string.Format("Outgoing Packets ({0})", m_scene.RegionInfo.RegionName), string.Format("Outgoing Packets ({0})", m_scene.RegionInfo.RegionName),
@ -957,6 +960,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// Handle appended ACKs // Handle appended ACKs
if (packet.Header.AppendedAcks && packet.Header.AckList != null) if (packet.Header.AppendedAcks && packet.Header.AckList != null)
{ {
// m_log.DebugFormat(
// "[LLUDPSERVER]: Handling {0} appended acks from {1} in {2}",
// packet.Header.AckList.Length, client.Name, m_scene.Name);
for (int i = 0; i < packet.Header.AckList.Length; i++) for (int i = 0; i < packet.Header.AckList.Length; i++)
udpClient.NeedAcks.Acknowledge(packet.Header.AckList[i], now, packet.Header.Resent); udpClient.NeedAcks.Acknowledge(packet.Header.AckList[i], now, packet.Header.Resent);
} }
@ -966,6 +973,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{ {
PacketAckPacket ackPacket = (PacketAckPacket)packet; PacketAckPacket ackPacket = (PacketAckPacket)packet;
// m_log.DebugFormat(
// "[LLUDPSERVER]: Handling {0} packet acks for {1} in {2}",
// ackPacket.Packets.Length, client.Name, m_scene.Name);
for (int i = 0; i < ackPacket.Packets.Length; i++) for (int i = 0; i < ackPacket.Packets.Length; i++)
udpClient.NeedAcks.Acknowledge(ackPacket.Packets[i].ID, now, packet.Header.Resent); udpClient.NeedAcks.Acknowledge(ackPacket.Packets[i].ID, now, packet.Header.Resent);
@ -979,6 +990,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (packet.Header.Reliable) if (packet.Header.Reliable)
{ {
// m_log.DebugFormat(
// "[LLUDPSERVER]: Adding ack request for {0} {1} from {2} in {3}",
// packet.Type, packet.Header.Sequence, client.Name, m_scene.Name);
udpClient.PendingAcks.Enqueue(packet.Header.Sequence); udpClient.PendingAcks.Enqueue(packet.Header.Sequence);
// This is a somewhat odd sequence of steps to pull the client.BytesSinceLastACK value out, // This is a somewhat odd sequence of steps to pull the client.BytesSinceLastACK value out,
@ -1025,6 +1040,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (packet.Type == PacketType.StartPingCheck) if (packet.Type == PacketType.StartPingCheck)
{ {
// m_log.DebugFormat("[LLUDPSERVER]: Handling ping from {0} in {1}", client.Name, m_scene.Name);
// We don't need to do anything else with ping checks // We don't need to do anything else with ping checks
StartPingCheckPacket startPing = (StartPingCheckPacket)packet; StartPingCheckPacket startPing = (StartPingCheckPacket)packet;
CompletePing(udpClient, startPing.PingID.PingID); CompletePing(udpClient, startPing.PingID.PingID);
@ -1044,13 +1061,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#endregion Ping Check Handling #endregion Ping Check Handling
IncomingPacket incomingPacket;
// Inbox insertion // Inbox insertion
if (packet.Type == PacketType.AgentUpdate || if (UsePools)
packet.Type == PacketType.ChatFromViewer) {
packetInbox.EnqueueHigh(new IncomingPacket((LLClientView)client, packet)); incomingPacket = m_incomingPacketPool.GetObject();
incomingPacket.Client = (LLClientView)client;
incomingPacket.Packet = packet;
}
else else
packetInbox.EnqueueLow(new IncomingPacket((LLClientView)client, packet)); {
// packetInbox.Enqueue(new IncomingPacket((LLClientView)client, packet)); incomingPacket = new IncomingPacket((LLClientView)client, packet);
}
if (incomingPacket.Packet.Type == PacketType.AgentUpdate ||
incomingPacket.Packet.Type == PacketType.ChatFromViewer)
packetInbox.EnqueueHigh(incomingPacket);
else
packetInbox.EnqueueLow(incomingPacket);
} }
#region BinaryStats #region BinaryStats
@ -1333,7 +1362,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// on to en-US to avoid number parsing issues // on to en-US to avoid number parsing issues
Culture.SetCurrentCulture(); Culture.SetCurrentCulture();
while (base.IsRunningInbound) while (IsRunningInbound)
{ {
m_scene.ThreadAlive(1); m_scene.ThreadAlive(1);
try try
@ -1349,7 +1378,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
if (packetInbox.Dequeue(100, ref incomingPacket)) if (packetInbox.Dequeue(100, ref incomingPacket))
{
ProcessInPacket(incomingPacket);//, incomingPacket); Util.FireAndForget(ProcessInPacket, incomingPacket); ProcessInPacket(incomingPacket);//, incomingPacket); Util.FireAndForget(ProcessInPacket, incomingPacket);
if (UsePools)
m_incomingPacketPool.ReturnObject(incomingPacket);
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -108,15 +108,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{ {
if (!pool.ContainsKey(type) || pool[type] == null || (pool[type]).Count == 0) if (!pool.ContainsKey(type) || pool[type] == null || (pool[type]).Count == 0)
{ {
// m_log.DebugFormat("[PACKETPOOL]: Building {0} packet", type);
// 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);
} }
else else
{ {
// m_log.DebugFormat("[PACKETPOOL]: Pulling {0} packet", type);
// Recycle old packages // Recycle old packages
m_packetsReusedStat.Antecedent++; m_packetsReusedStat.Antecedent++;
packet = (pool[type]).Pop(); packet = pool[type].Pop();
} }
} }
@ -227,7 +231,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if ((pool[type]).Count < 50) if ((pool[type]).Count < 50)
{ {
(pool[type]).Push(packet); // m_log.DebugFormat("[PACKETPOOL]: Pushing {0} packet", type);
pool[type].Push(packet);
} }
} }
break; break;