From 257b1b517dec58bf902bac63bc7ab7080286d415 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 15 Jun 2012 02:03:50 +0100 Subject: Add main instance to internal MainServer.m_Servers list to simplify internal logic. This does require the server to be added before it is set as the main Instance --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 8 --- OpenSim/Framework/Servers/MainServer.cs | 64 +++++++++++++++++++++- 2 files changed, 61 insertions(+), 11 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 6b52485..0db1329 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -53,14 +53,6 @@ namespace OpenSim.Framework.Servers.HttpServer private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); - /// - /// Control the printing of certain debug messages. - /// - /// - /// If DebugLevel >= 1, then short warnings are logged when receiving bad input data. - /// If DebugLevel >= 2, then long warnings are logged when receiving bad input data. - /// If DebugLevel >= 3, then short notices about all incoming non-poll HTTP requests are logged. - /// public int DebugLevel { get; set; } private volatile int NotSocketErrors = 0; diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs index efac6e1..becbbc2 100644 --- a/OpenSim/Framework/Servers/MainServer.cs +++ b/OpenSim/Framework/Servers/MainServer.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections.Generic; using System.Reflection; using System.Net; @@ -40,13 +41,20 @@ namespace OpenSim.Framework.Servers private static BaseHttpServer instance = null; private static Dictionary m_Servers = new Dictionary(); + /// + /// Control the printing of certain debug messages. + /// + /// + /// If DebugLevel >= 1, then short warnings are logged when receiving bad input data. + /// If DebugLevel >= 2, then long warnings are logged when receiving bad input data. + /// If DebugLevel >= 3, then short notices about all incoming non-poll HTTP requests are logged. + /// public static int DebugLevel { get { return s_debugLevel; } set { s_debugLevel = value; - Instance.DebugLevel = s_debugLevel; lock (m_Servers) foreach (BaseHttpServer server in m_Servers.Values) @@ -56,20 +64,70 @@ namespace OpenSim.Framework.Servers private static int s_debugLevel; + /// + /// Set the main HTTP server instance. + /// + /// + /// This will be used to register all handlers that listen to the default port. + /// + /// + /// Thrown if the HTTP server has not already been registered via AddHttpServer() + /// public static BaseHttpServer Instance { get { return instance; } - set { instance = value; } + + set + { + lock (m_Servers) + if (!m_Servers.ContainsValue(value)) + throw new Exception("HTTP server must already have been registered to be set as the main instance"); + + instance = value; + } } /// - /// Add an already started HTTP server to the collection of known servers. + /// Register an already started HTTP server to the collection of known servers. /// /// public static void AddHttpServer(BaseHttpServer server) { lock (m_Servers) + { + if (m_Servers.ContainsKey(server.Port)) + throw new Exception(string.Format("HTTP server for port {0} already exists.", server.Port)); + m_Servers.Add(server.Port, server); + } + } + + /// + /// Removes the http server listening on the given port. + /// + /// + /// It is the responsibility of the caller to do clean up. + /// + /// + /// + public static bool RemoveHttpServer(uint port) + { + lock (m_Servers) + return m_Servers.Remove(port); + } + + /// + /// Does this collection of servers contain one with the given port? + /// + /// + /// Unlike GetHttpServer, this will not instantiate a server if one does not exist on that port. + /// + /// + /// true if a server with the given port is registered, false otherwise. + public static bool ContainsHttpServer(uint port) + { + lock (m_Servers) + return m_Servers.ContainsKey(port); } /// -- cgit v1.1