From 6993a26ba599ae38dc6f66332980657d5621987a Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 15 Jun 2012 00:40:12 +0100
Subject: Get rid of some unnecessary null checks in
RegionApplicationBase.StartupSpecific() - a constructor can never return
null.
Also adds some method doc to MainServer
---
OpenSim/Framework/Servers/MainServer.cs | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
(limited to 'OpenSim/Framework/Servers/MainServer.cs')
diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs
index b8ab8d9..ea972ef 100644
--- a/OpenSim/Framework/Servers/MainServer.cs
+++ b/OpenSim/Framework/Servers/MainServer.cs
@@ -47,20 +47,43 @@ namespace OpenSim.Framework.Servers
set { instance = value; }
}
- public static IHttpServer GetHttpServer(uint port)
+ ///
+ /// Add an already started HTTP server to the collection of known servers.
+ ///
+ ///
+ public static void AddHttpServer(BaseHttpServer server)
{
- return GetHttpServer(port,null);
+ m_Servers.Add(server.Port, server);
}
- public static void AddHttpServer(BaseHttpServer server)
+ ///
+ /// Get the default http server or an http server for a specific port.
+ ///
+ ///
+ /// If the requested HTTP server doesn't already exist then a new one is instantiated and started.
+ ///
+ ///
+ /// If 0 then the default HTTP server is returned.
+ public static IHttpServer GetHttpServer(uint port)
{
- m_Servers.Add(server.Port, server);
+ return GetHttpServer(port, null);
}
+ ///
+ /// Get the default http server, an http server for a specific port
+ /// and/or an http server bound to a specific address
+ ///
+ ///
+ /// If the requested HTTP server doesn't already exist then a new one is instantiated and started.
+ ///
+ ///
+ /// If 0 then the default HTTP server is returned.
+ /// A specific IP address to bind to. If null then the default IP address is used.
public static IHttpServer GetHttpServer(uint port, IPAddress ipaddr)
{
if (port == 0)
return Instance;
+
if (instance != null && port == Instance.Port)
return Instance;
--
cgit v1.1
From 478acfff34b94c7c42bdb927be531b669c43af72 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 15 Jun 2012 01:24:36 +0100
Subject: When setting debug http level, do this for all known http servers,
not just the main instance.
---
OpenSim/Framework/Servers/MainServer.cs | 41 ++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 11 deletions(-)
(limited to 'OpenSim/Framework/Servers/MainServer.cs')
diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs
index ea972ef..efac6e1 100644
--- a/OpenSim/Framework/Servers/MainServer.cs
+++ b/OpenSim/Framework/Servers/MainServer.cs
@@ -38,8 +38,23 @@ namespace OpenSim.Framework.Servers
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static BaseHttpServer instance = null;
- private static Dictionary m_Servers =
- new Dictionary();
+ private static Dictionary m_Servers = new Dictionary();
+
+ 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)
+ server.DebugLevel = s_debugLevel;
+ }
+ }
+
+ private static int s_debugLevel;
public static BaseHttpServer Instance
{
@@ -53,7 +68,8 @@ namespace OpenSim.Framework.Servers
///
public static void AddHttpServer(BaseHttpServer server)
{
- m_Servers.Add(server.Port, server);
+ lock (m_Servers)
+ m_Servers.Add(server.Port, server);
}
///
@@ -87,18 +103,21 @@ namespace OpenSim.Framework.Servers
if (instance != null && port == Instance.Port)
return Instance;
- if (m_Servers.ContainsKey(port))
- return m_Servers[port];
+ lock (m_Servers)
+ {
+ if (m_Servers.ContainsKey(port))
+ return m_Servers[port];
- m_Servers[port] = new BaseHttpServer(port);
+ m_Servers[port] = new BaseHttpServer(port);
- if (ipaddr != null)
- m_Servers[port].ListenIPAddress = ipaddr;
+ if (ipaddr != null)
+ m_Servers[port].ListenIPAddress = ipaddr;
- m_log.InfoFormat("[MAIN HTTP SERVER]: Starting main http server on port {0}", port);
- m_Servers[port].Start();
+ m_log.InfoFormat("[MAIN HTTP SERVER]: Starting main http server on port {0}", port);
+ m_Servers[port].Start();
+ }
return m_Servers[port];
}
}
-}
+}
\ No newline at end of file
--
cgit v1.1
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
---
OpenSim/Framework/Servers/MainServer.cs | 64 +++++++++++++++++++++++++++++++--
1 file changed, 61 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Framework/Servers/MainServer.cs')
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
From 94517c8d5c63f9e8a1ea9a83b04db956f27aa25d Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 15 Jun 2012 02:51:52 +0100
Subject: Make the "debug http" command available for robust as well as the
simulator. This allows one to see incoming requests as they happen.
This required making everything use the common MainServer class for registering and retrieving http servers, rather than duplicate structures.
---
OpenSim/Framework/Servers/MainServer.cs | 60 ++++++++++++++++++++++++++++++---
1 file changed, 56 insertions(+), 4 deletions(-)
(limited to 'OpenSim/Framework/Servers/MainServer.cs')
diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs
index becbbc2..07ff60c 100644
--- a/OpenSim/Framework/Servers/MainServer.cs
+++ b/OpenSim/Framework/Servers/MainServer.cs
@@ -30,13 +30,15 @@ using System.Collections.Generic;
using System.Reflection;
using System.Net;
using log4net;
+using OpenSim.Framework;
+using OpenSim.Framework.Console;
using OpenSim.Framework.Servers.HttpServer;
namespace OpenSim.Framework.Servers
{
public class MainServer
{
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static BaseHttpServer instance = null;
private static Dictionary m_Servers = new Dictionary();
@@ -88,6 +90,57 @@ namespace OpenSim.Framework.Servers
}
///
+ /// Get all the registered servers.
+ ///
+ ///
+ /// Returns a copy of the dictionary so this can be iterated through without locking.
+ ///
+ ///
+ public static Dictionary Servers
+ {
+ get { return new Dictionary(m_Servers); }
+ }
+
+
+ public static void RegisterHttpConsoleCommands(ICommandConsole console)
+ {
+ console.Commands.AddCommand(
+ "Comms", false, "debug http", "debug http []",
+ "Turn on inbound non-poll http request debugging.",
+ "If level <= 0, then no extra logging is done.\n"
+ + "If level >= 1, then short warnings are logged when receiving bad input data.\n"
+ + "If level >= 2, then long warnings are logged when receiving bad input data.\n"
+ + "If level >= 3, then short notices about all incoming non-poll HTTP requests are logged.\n"
+ + "If no level is specified then the current level is returned.",
+ HandleDebugHttpCommand);
+ }
+
+ ///
+ /// Turn on some debugging values for OpenSim.
+ ///
+ ///
+ private static void HandleDebugHttpCommand(string module, string[] args)
+ {
+ if (args.Length == 3)
+ {
+ int newDebug;
+ if (int.TryParse(args[2], out newDebug))
+ {
+ MainServer.DebugLevel = newDebug;
+ MainConsole.Instance.OutputFormat("Debug http level set to {0}", newDebug);
+ }
+ }
+ else if (args.Length == 2)
+ {
+ MainConsole.Instance.OutputFormat("Current debug http level is {0}", MainServer.DebugLevel);
+ }
+ else
+ {
+ MainConsole.Instance.Output("Usage: debug http 0..3");
+ }
+ }
+
+ ///
/// Register an already started HTTP server to the collection of known servers.
///
///
@@ -171,11 +224,10 @@ namespace OpenSim.Framework.Servers
if (ipaddr != null)
m_Servers[port].ListenIPAddress = ipaddr;
- m_log.InfoFormat("[MAIN HTTP SERVER]: Starting main http server on port {0}", port);
m_Servers[port].Start();
- }
- return m_Servers[port];
+ return m_Servers[port];
+ }
}
}
}
\ No newline at end of file
--
cgit v1.1
From c935f0346750d510e5c3c3c2ff62c84609a115e3 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 15 Jun 2012 03:32:43 +0100
Subject: Put all debug console commands into a single Debug section rather
than scattering them over other categories
---
OpenSim/Framework/Servers/MainServer.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Framework/Servers/MainServer.cs')
diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs
index 07ff60c..8dc0e3a 100644
--- a/OpenSim/Framework/Servers/MainServer.cs
+++ b/OpenSim/Framework/Servers/MainServer.cs
@@ -105,7 +105,7 @@ namespace OpenSim.Framework.Servers
public static void RegisterHttpConsoleCommands(ICommandConsole console)
{
console.Commands.AddCommand(
- "Comms", false, "debug http", "debug http []",
+ "Debug", false, "debug http", "debug http []",
"Turn on inbound non-poll http request debugging.",
"If level <= 0, then no extra logging is done.\n"
+ "If level >= 1, then short warnings are logged when receiving bad input data.\n"
--
cgit v1.1