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,7 +285,8 @@ namespace OpenSim.Framework.Servers.HttpServer
public List<string> GetLLSDHandlerKeys() public List<string> GetLLSDHandlerKeys()
{ {
return new List<string>(m_llsdHandlers.Keys); lock (m_llsdHandlers)
return new List<string>(m_llsdHandlers.Keys);
} }
public bool SetDefaultLLSDHandler(DefaultLLSDMethod handler) public bool SetDefaultLLSDHandler(DefaultLLSDMethod handler)
@ -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;
foreach (string pattern in m_llsdHandlers.Keys) lock (m_llsdHandlers)
{ {
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,29 +1229,32 @@ namespace OpenSim.Framework.Servers.HttpServer
string bestMatch = null; string bestMatch = null;
foreach (string pattern in m_llsdHandlers.Keys) lock (m_llsdHandlers)
{ {
if (searchquery.ToLower().StartsWith(pattern.ToLower())) foreach (string pattern in m_llsdHandlers.Keys)
{ {
if (String.IsNullOrEmpty(bestMatch) || searchquery.Length > bestMatch.Length) if (searchquery.ToLower().StartsWith(pattern.ToLower()))
{ {
// You have to specifically register for '/' and to get it, you must specificaly request it if (String.IsNullOrEmpty(bestMatch) || searchquery.Length > bestMatch.Length)
// {
if (pattern == "/" && searchquery == "/" || pattern != "/") // You have to specifically register for '/' and to get it, you must specificaly request it
bestMatch = pattern; //
if (pattern == "/" && searchquery == "/" || pattern != "/")
bestMatch = pattern;
}
} }
} }
}
if (String.IsNullOrEmpty(bestMatch))
if (String.IsNullOrEmpty(bestMatch)) {
{ llsdHandler = null;
llsdHandler = null; return false;
return false; }
} else
else {
{ llsdHandler = m_llsdHandlers[bestMatch];
llsdHandler = m_llsdHandlers[bestMatch]; return true;
return true; }
} }
} }
@ -1856,10 +1855,13 @@ namespace OpenSim.Framework.Servers.HttpServer
{ {
try try
{ {
if (handler == m_llsdHandlers[path]) lock (m_llsdHandlers)
{ {
m_llsdHandlers.Remove(path); if (handler == m_llsdHandlers[path])
return true; {
m_llsdHandlers.Remove(path);
return true;
}
} }
} }
catch (KeyNotFoundException) catch (KeyNotFoundException)