From 94a8ab80c844274de4a3cc11b9be9f25e786c77e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 22 Aug 2011 01:43:34 +0100 Subject: improve locking of m_rpcHandlers in BaseHttpServer --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index cb1117a..85fb364 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -196,7 +196,8 @@ namespace OpenSim.Framework.Servers.HttpServer public List GetXmlRpcHandlerKeys() { - return new List(m_rpcHandlers.Keys); + lock (m_rpcHandlers) + return new List(m_rpcHandlers.Keys); } public bool AddHTTPHandler(string methodName, GenericHTTPMethod handler) -- cgit v1.1 From 2f1ac1d14454cb9a59d3e74edce3bbeb81c66bc8 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 22 Aug 2011 01:45:46 +0100 Subject: minor: remove mono compiler warning --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 85fb364..b3c05a0 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -405,14 +405,14 @@ namespace OpenSim.Framework.Servers.HttpServer string requestMethod = request.HttpMethod; string uriString = request.RawUrl; - string reqnum = "unknown"; +// string reqnum = "unknown"; int tickstart = Environment.TickCount; try { // OpenSim.Framework.WebUtil.OSHeaderRequestID - if (request.Headers["opensim-request-id"] != null) - reqnum = String.Format("{0}:{1}",request.RemoteIPEndPoint,request.Headers["opensim-request-id"]); +// if (request.Headers["opensim-request-id"] != null) +// reqnum = String.Format("{0}:{1}",request.RemoteIPEndPoint,request.Headers["opensim-request-id"]); //m_log.DebugFormat("[BASE HTTP SERVER]: <{0}> handle request for {1}",reqnum,request.RawUrl); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true); -- cgit v1.1 From 8254116dc6ca0be85caac6fbf26dfa4b82fef03d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 22 Aug 2011 01:52:08 +0100 Subject: improve locking of m_llsdHandlers in BaseHttpServer --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 62 +++++++++++----------- 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index b3c05a0..897ee4f 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -285,7 +285,8 @@ namespace OpenSim.Framework.Servers.HttpServer public List GetLLSDHandlerKeys() { - return new List(m_llsdHandlers.Keys); + lock (m_llsdHandlers) + return new List(m_llsdHandlers.Keys); } public bool SetDefaultLLSDHandler(DefaultLLSDMethod handler) @@ -1107,7 +1108,6 @@ namespace OpenSim.Framework.Servers.HttpServer /// true if we have one, false if not private bool DoWeHaveALLSDHandler(string path) { - string[] pathbase = path.Split('/'); string searchquery = "/"; @@ -1123,14 +1123,12 @@ namespace OpenSim.Framework.Servers.HttpServer string bestMatch = null; - foreach (string pattern in m_llsdHandlers.Keys) + lock (m_llsdHandlers) { - - if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length) + foreach (string pattern in m_llsdHandlers.Keys) { - + if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length) bestMatch = pattern; - } } @@ -1143,12 +1141,10 @@ namespace OpenSim.Framework.Servers.HttpServer if (String.IsNullOrEmpty(bestMatch)) { - return false; } else { - return true; } } @@ -1233,29 +1229,32 @@ namespace OpenSim.Framework.Servers.HttpServer 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 (pattern == "/" && searchquery == "/" || pattern != "/") - bestMatch = pattern; + if (String.IsNullOrEmpty(bestMatch) || searchquery.Length > bestMatch.Length) + { + // You have to specifically register for '/' and to get it, you must specificaly request it + // + if (pattern == "/" && searchquery == "/" || pattern != "/") + bestMatch = pattern; + } } } - } - - if (String.IsNullOrEmpty(bestMatch)) - { - llsdHandler = null; - return false; - } - else - { - llsdHandler = m_llsdHandlers[bestMatch]; - return true; + + if (String.IsNullOrEmpty(bestMatch)) + { + llsdHandler = null; + return false; + } + else + { + llsdHandler = m_llsdHandlers[bestMatch]; + return true; + } } } @@ -1856,10 +1855,13 @@ namespace OpenSim.Framework.Servers.HttpServer { try { - if (handler == m_llsdHandlers[path]) + lock (m_llsdHandlers) { - m_llsdHandlers.Remove(path); - return true; + if (handler == m_llsdHandlers[path]) + { + m_llsdHandlers.Remove(path); + return true; + } } } catch (KeyNotFoundException) -- cgit v1.1 From 20a4367827d513d9bdafebf6622dc596c2f64879 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 22 Aug 2011 01:58:19 +0100 Subject: remove necessity to catch a KeyNotFoundException in BaseHttpServer.RemoveLLSDHandler() --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 897ee4f..473a01c 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1853,21 +1853,16 @@ namespace OpenSim.Framework.Servers.HttpServer public bool RemoveLLSDHandler(string path, LLSDMethod handler) { - try + lock (m_llsdHandlers) { - lock (m_llsdHandlers) + LLSDMethod foundHandler; + + if (m_llsdHandlers.TryGetValue(path, out foundHandler) && foundHandler == handler) { - if (handler == m_llsdHandlers[path]) - { - m_llsdHandlers.Remove(path); - return true; - } + m_llsdHandlers.Remove(path); + return true; } } - catch (KeyNotFoundException) - { - // This is an exception to prevent crashing because of invalid code - } return false; } -- cgit v1.1 From 5a11cffd2303a80dfa644c831bdf6cce3a932e7d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 22 Aug 2011 01:58:50 +0100 Subject: improve locking of m_streamHandlers in BaseHttpServer --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 473a01c..988d859 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -155,7 +155,8 @@ namespace OpenSim.Framework.Servers.HttpServer public List GetStreamHandlerKeys() { - return new List(m_streamHandlers.Keys); + lock (m_streamHandlers) + return new List(m_streamHandlers.Keys); } private static string GetHandlerKey(string httpMethod, string path) @@ -1793,7 +1794,8 @@ namespace OpenSim.Framework.Servers.HttpServer //m_log.DebugFormat("[BASE HTTP SERVER]: Removing handler key {0}", handlerKey); - lock (m_streamHandlers) m_streamHandlers.Remove(handlerKey); + lock (m_streamHandlers) + m_streamHandlers.Remove(handlerKey); } public void RemoveHTTPHandler(string httpMethod, string path) -- cgit v1.1 From f9a367e2f6aa41f9ec379e2ff5b6b22303daf2f6 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 22 Aug 2011 01:59:40 +0100 Subject: improve locking of m_HTTPHandlers in BaseHttpServer --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 988d859..22417b6 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -220,10 +220,10 @@ namespace OpenSim.Framework.Servers.HttpServer public List GetHTTPHandlerKeys() { - return new List(m_HTTPHandlers.Keys); + lock (m_HTTPHandlers) + return new List(m_HTTPHandlers.Keys); } - public bool AddPollServiceHTTPHandler(string methodName, GenericHTTPMethod handler, PollServiceEventArgs args) { bool pollHandlerResult = false; -- cgit v1.1 From 9469c62098b00d2322ac66d61d03689792d03de7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 22 Aug 2011 02:07:51 +0100 Subject: improve locking of m_agentHandlers in BaseHttpServer --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 22417b6..fd0621b 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -66,7 +66,6 @@ namespace OpenSim.Framework.Servers.HttpServer protected Dictionary m_streamHandlers = new Dictionary(); protected Dictionary m_HTTPHandlers = new Dictionary(); protected Dictionary m_agentHandlers = new Dictionary(); - protected Dictionary m_pollHandlers = new Dictionary(); @@ -247,7 +246,6 @@ namespace OpenSim.Framework.Servers.HttpServer return new List(m_pollHandlers.Keys); } - // Note that the agent string is provided simply to differentiate // the handlers - it is NOT required to be an actual agent header // value. @@ -268,7 +266,8 @@ namespace OpenSim.Framework.Servers.HttpServer public List GetAgentHandlerKeys() { - return new List(m_agentHandlers.Keys); + lock (m_agentHandlers) + return new List(m_agentHandlers.Keys); } public bool AddLLSDHandler(string path, LLSDMethod handler) @@ -749,7 +748,8 @@ namespace OpenSim.Framework.Servers.HttpServer private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler) { agentHandler = null; - try + + lock (m_agentHandlers) { foreach (IHttpAgentHandler handler in m_agentHandlers.Values) { @@ -760,9 +760,6 @@ namespace OpenSim.Framework.Servers.HttpServer } } } - catch(KeyNotFoundException) - { - } return false; } @@ -1829,10 +1826,13 @@ namespace OpenSim.Framework.Servers.HttpServer { try { - if (handler == m_agentHandlers[agent]) + lock (m_agentHandlers) { - m_agentHandlers.Remove(agent); - return true; + if (handler == m_agentHandlers[agent]) + { + m_agentHandlers.Remove(agent); + return true; + } } } catch(KeyNotFoundException) -- cgit v1.1 From c587b0a3a38337fcd23d01e08c9a990abfab0569 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 22 Aug 2011 02:10:45 +0100 Subject: oops, fix build break from last commit --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index fd0621b..fce3671 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -56,7 +56,6 @@ namespace OpenSim.Framework.Servers.HttpServer private volatile int NotSocketErrors = 0; public volatile bool HTTPDRunning = false; - protected Thread m_workerThread; // protected HttpListener m_httpListener; protected CoolHTTPListener m_httpListener2; protected Dictionary m_rpcHandlers = new Dictionary(); @@ -243,7 +242,8 @@ namespace OpenSim.Framework.Servers.HttpServer public List GetPollServiceHandlerKeys() { - return new List(m_pollHandlers.Keys); + lock (m_pollHandlers) + return new List(m_pollHandlers.Keys); } // Note that the agent string is provided simply to differentiate @@ -1824,20 +1824,16 @@ namespace OpenSim.Framework.Servers.HttpServer public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) { - try + lock (m_agentHandlers) { - lock (m_agentHandlers) + IHttpAgentHandler foundHandler; + + if (m_agentHandlers.TryGetValue(agent, out foundHandler) && foundHandler == handler) { - if (handler == m_agentHandlers[agent]) - { - m_agentHandlers.Remove(agent); - return true; - } + m_agentHandlers.Remove(agent); + return true; } } - catch(KeyNotFoundException) - { - } return false; } -- cgit v1.1 From d74686fd51b4f88ef0040b7ef7d65facf8c00e04 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 22 Aug 2011 02:25:58 +0100 Subject: read m_rpcHandlersKeepAlive under appropriate lock --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index fce3671..af9b62f 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -803,9 +803,12 @@ namespace OpenSim.Framework.Servers.HttpServer XmlRpcMethod method; bool methodWasFound; + bool keepAlive = false; lock (m_rpcHandlers) { methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method); + if (methodWasFound) + keepAlive = m_rpcHandlersKeepAlive[methodName]; } if (methodWasFound) @@ -824,7 +827,6 @@ namespace OpenSim.Framework.Servers.HttpServer } xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3] - try { xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint); @@ -846,7 +848,7 @@ namespace OpenSim.Framework.Servers.HttpServer } // if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here - response.KeepAlive = m_rpcHandlersKeepAlive[methodName]; + response.KeepAlive = keepAlive; } else { -- cgit v1.1