diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 6b52485523..0db1329ad2 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 efac6e1128..becbbc21b8 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); } /// diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs index c25b58cf8f..cd70410680 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs @@ -51,7 +51,16 @@ namespace OpenSim.Region.ClientStack.Linden.Tests [SetUp] public void SetUp() { - MainServer.Instance = new BaseHttpServer(9999, false, 9998, ""); + uint port = 9999; + uint sslPort = 9998; + + // This is an unfortunate bit of clean up we have to do because MainServer manages things through static + // variables and the VM is not restarted between tests. + MainServer.RemoveHttpServer(port); + + BaseHttpServer server = new BaseHttpServer(port, false, sslPort, ""); + MainServer.AddHttpServer(server); + MainServer.Instance = server; IConfigSource config = new IniConfigSource(); config.AddConfig("Startup"); diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs index 27a5879cba..c4324e8592 100644 --- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs +++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs @@ -94,6 +94,7 @@ namespace OpenSim.Region.ClientStack m_log.InfoFormat("[REGION SERVER]: Starting HTTP server on port {0}", m_httpServerPort); m_httpServer.Start(); + MainServer.AddHttpServer(m_httpServer); MainServer.Instance = m_httpServer; // "OOB" Server diff --git a/OpenSim/Server/Base/HttpServerBase.cs b/OpenSim/Server/Base/HttpServerBase.cs index d47155984f..7014303203 100644 --- a/OpenSim/Server/Base/HttpServerBase.cs +++ b/OpenSim/Server/Base/HttpServerBase.cs @@ -138,6 +138,7 @@ namespace OpenSim.Server.Base m_HttpServer = new BaseHttpServer(port, ssl_main, cert_path, cert_pass); } + MainServer.AddHttpServer(m_HttpServer); MainServer.Instance = m_HttpServer; // If https_listener = true, then add an ssl listener on the https_port... @@ -157,16 +158,8 @@ namespace OpenSim.Server.Base System.Console.WriteLine("Password for X509 certificate is missing, server can't start."); Thread.CurrentThread.Abort(); } - // Add our https_server - BaseHttpServer server = null; - server = new BaseHttpServer(https_port, ssl_listener, cert_path, cert_pass); - if (server != null) - { - m_Log.InfoFormat("[SERVER]: Starting HTTPS server on port {0}", https_port); - m_Servers.Add(https_port,server); - } - else - System.Console.WriteLine(String.Format("Failed to start HTTPS server on port {0}",https_port)); + + m_Servers.Add(https_port, new BaseHttpServer(https_port, ssl_listener, cert_path, cert_pass)); } }