improve locking of m_llsdHandlers in BaseHttpServer

bulletsim
Justin Clark-Casey (justincc) 2011-08-22 01:52:08 +01:00
parent 2f1ac1d144
commit 8254116dc6
1 changed files with 32 additions and 30 deletions

View File

@ -285,6 +285,7 @@ namespace OpenSim.Framework.Servers.HttpServer
public List<string> GetLLSDHandlerKeys() public List<string> GetLLSDHandlerKeys()
{ {
lock (m_llsdHandlers)
return new List<string>(m_llsdHandlers.Keys); return new List<string>(m_llsdHandlers.Keys);
} }
@ -1107,7 +1108,6 @@ namespace OpenSim.Framework.Servers.HttpServer
/// <returns>true if we have one, false if not</returns> /// <returns>true if we have one, false if not</returns>
private bool DoWeHaveALLSDHandler(string path) private bool DoWeHaveALLSDHandler(string path)
{ {
string[] pathbase = path.Split('/'); string[] pathbase = path.Split('/');
string searchquery = "/"; string searchquery = "/";
@ -1123,14 +1123,12 @@ namespace OpenSim.Framework.Servers.HttpServer
string bestMatch = null; string bestMatch = null;
lock (m_llsdHandlers)
{
foreach (string pattern in m_llsdHandlers.Keys) foreach (string pattern in m_llsdHandlers.Keys)
{ {
if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length) if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length)
{
bestMatch = pattern; bestMatch = pattern;
} }
} }
@ -1143,12 +1141,10 @@ namespace OpenSim.Framework.Servers.HttpServer
if (String.IsNullOrEmpty(bestMatch)) if (String.IsNullOrEmpty(bestMatch))
{ {
return false; return false;
} }
else else
{ {
return true; return true;
} }
} }
@ -1233,6 +1229,8 @@ namespace OpenSim.Framework.Servers.HttpServer
string bestMatch = null; string bestMatch = null;
lock (m_llsdHandlers)
{
foreach (string pattern in m_llsdHandlers.Keys) foreach (string pattern in m_llsdHandlers.Keys)
{ {
if (searchquery.ToLower().StartsWith(pattern.ToLower())) if (searchquery.ToLower().StartsWith(pattern.ToLower()))
@ -1258,6 +1256,7 @@ namespace OpenSim.Framework.Servers.HttpServer
return true; return true;
} }
} }
}
private OSDMap GenerateNoLLSDHandlerResponse() private OSDMap GenerateNoLLSDHandlerResponse()
{ {
@ -1855,6 +1854,8 @@ namespace OpenSim.Framework.Servers.HttpServer
public bool RemoveLLSDHandler(string path, LLSDMethod handler) public bool RemoveLLSDHandler(string path, LLSDMethod handler)
{ {
try try
{
lock (m_llsdHandlers)
{ {
if (handler == m_llsdHandlers[path]) if (handler == m_llsdHandlers[path])
{ {
@ -1862,6 +1863,7 @@ namespace OpenSim.Framework.Servers.HttpServer
return true; return true;
} }
} }
}
catch (KeyNotFoundException) catch (KeyNotFoundException)
{ {
// This is an exception to prevent crashing because of invalid code // This is an exception to prevent crashing because of invalid code