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
0.7.3-extended
Justin Clark-Casey (justincc) 2012-06-15 02:03:50 +01:00
parent 88596d6097
commit 584a076bec
5 changed files with 75 additions and 22 deletions

View File

@ -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();
/// <summary>
/// Control the printing of certain debug messages.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public int DebugLevel { get; set; }
private volatile int NotSocketErrors = 0;

View File

@ -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<uint, BaseHttpServer> m_Servers = new Dictionary<uint, BaseHttpServer>();
/// <summary>
/// Control the printing of certain debug messages.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
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;
/// <summary>
/// Set the main HTTP server instance.
/// </summary>
/// <remarks>
/// This will be used to register all handlers that listen to the default port.
/// </remarks>
/// <exception cref='Exception'>
/// Thrown if the HTTP server has not already been registered via AddHttpServer()
/// </exception>
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;
}
}
/// <summary>
/// Add an already started HTTP server to the collection of known servers.
/// Register an already started HTTP server to the collection of known servers.
/// </summary>
/// <param name='server'></param>
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);
}
}
/// <summary>
/// Removes the http server listening on the given port.
/// </summary>
/// <remarks>
/// It is the responsibility of the caller to do clean up.
/// </remarks>
/// <param name='port'></param>
/// <returns></returns>
public static bool RemoveHttpServer(uint port)
{
lock (m_Servers)
return m_Servers.Remove(port);
}
/// <summary>
/// Does this collection of servers contain one with the given port?
/// </summary>
/// <remarks>
/// Unlike GetHttpServer, this will not instantiate a server if one does not exist on that port.
/// </remarks>
/// <param name='port'></param>
/// <returns>true if a server with the given port is registered, false otherwise.</returns>
public static bool ContainsHttpServer(uint port)
{
lock (m_Servers)
return m_Servers.ContainsKey(port);
}
/// <summary>

View File

@ -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");

View File

@ -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

View File

@ -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));
}
}