Committing ahzz's patch #619 - Description:

Patch provided by Openlifegrid.com 
Adds locks around clientCircuits and clientCircuits_reverse Adds existance check on adding to clientCircuits for clients resending UseCircuit packet.
Adds locks around Clientmanager.m_clients for add/remove/tryGet calls
ThreadPoolClientBranch
Teravus Ovares 2008-02-18 21:24:34 +00:00
parent 056f3dca2c
commit d0b218f667
2 changed files with 48 additions and 19 deletions

View File

@ -72,20 +72,28 @@ namespace OpenSim.Framework
public void Remove(uint id)
{
//m_log.InfoFormat("[CLIENT]: Removing client with code {0}, current count {1}", id, m_clients.Count);
lock (m_clients)
{
m_clients.Remove(id);
}
m_log.InfoFormat("[CLIENT]: Removed client with code {0}, new client count {1}", id, m_clients.Count);
}
public void Add(uint id, IClientAPI client)
{
lock (m_clients)
{
m_clients.Add(id, client);
}
}
public void InPacket(uint circuitCode, Packet packet)
{
IClientAPI client;
if (m_clients.TryGetValue(circuitCode, out client))
bool tryGetRet = false;
lock (m_clients)
tryGetRet = m_clients.TryGetValue(circuitCode, out client);
if(tryGetRet)
{
client.InPacket(packet);
}
@ -94,8 +102,10 @@ namespace OpenSim.Framework
public void CloseAllAgents(uint circuitCode)
{
IClientAPI client;
if (m_clients.TryGetValue(circuitCode, out client))
bool tryGetRet = false;
lock (m_clients)
tryGetRet = m_clients.TryGetValue(circuitCode, out client);
if (tryGetRet)
{
CloseAllCircuits(client.AgentId);
}
@ -111,8 +121,10 @@ namespace OpenSim.Framework
IClientAPI client;
try
{
if (m_clients.TryGetValue(circuits[i], out client))
bool tryGetRet = false;
lock (m_clients)
tryGetRet = m_clients.TryGetValue(circuits[i], out client);
if(tryGetRet)
{
Remove(client.CircuitCode);
client.Close(false);
@ -175,8 +187,11 @@ namespace OpenSim.Framework
}
public bool TryGetClient(uint circuitId, out IClientAPI user)
{
lock (m_clients)
{
return m_clients.TryGetValue(circuitId, out user);
}
}
}
}

View File

@ -311,23 +311,31 @@ namespace OpenSim.Region.ClientStack
private void CloseEndPoint(EndPoint sender)
{
uint circuit;
lock (clientCircuits)
{
if (clientCircuits.TryGetValue(sender, out circuit))
{
m_packetServer.CloseCircuit(circuit);
}
}
}
protected virtual void AddNewClient(Packet packet)
{
UseCircuitCodePacket useCircuit = (UseCircuitCodePacket) packet;
lock (clientCircuits)
{
if (!clientCircuits.ContainsKey(epSender))
clientCircuits.Add(epSender, useCircuit.CircuitCode.Code);
else
m_log.Error("[UDPSERVER]: clientCircuits already contans entry for user " + useCircuit.CircuitCode.Code.ToString() + ". NOT adding.");
}
lock (clientCircuits_reverse)
{
if (!clientCircuits_reverse.ContainsKey(useCircuit.CircuitCode.Code))
clientCircuits_reverse.Add(useCircuit.CircuitCode.Code, epSender);
else
m_log.Error("[UDPSERVER]: clientCurcuits_reverse already contains entry for user " + useCircuit.CircuitCode.Code.ToString() + ". NOT adding.");
}
PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_authenticateSessionsClass);
@ -380,16 +388,21 @@ namespace OpenSim.Region.ClientStack
{
// find the endpoint for this circuit
EndPoint sendto = null;
lock (clientCircuits_reverse)
{
if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto))
{
//we found the endpoint so send the packet to it
Server.SendTo(buffer, size, flags, sendto);
}
}
}
public virtual void RemoveClientCircuit(uint circuitcode)
{
EndPoint sendto = null;
lock (clientCircuits_reverse)
{
if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto))
{
clientCircuits.Remove(sendto);
@ -399,4 +412,5 @@ namespace OpenSim.Region.ClientStack
}
}
}
}
}