diff options
author | Justin Clark-Casey (justincc) | 2012-06-15 02:03:50 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-06-15 02:03:50 +0100 |
commit | 257b1b517dec58bf902bac63bc7ab7080286d415 (patch) | |
tree | e0528b6032f1403cbcd03a216b527c565a2ac777 /OpenSim | |
parent | minor: Tell user the current debug http level if "debug http" console command... (diff) | |
download | opensim-SC_OLD-257b1b517dec58bf902bac63bc7ab7080286d415.zip opensim-SC_OLD-257b1b517dec58bf902bac63bc7ab7080286d415.tar.gz opensim-SC_OLD-257b1b517dec58bf902bac63bc7ab7080286d415.tar.bz2 opensim-SC_OLD-257b1b517dec58bf902bac63bc7ab7080286d415.tar.xz |
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
Diffstat (limited to 'OpenSim')
5 files changed, 75 insertions, 22 deletions
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 | |||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
54 | private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); | 54 | private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); |
55 | 55 | ||
56 | /// <summary> | ||
57 | /// Control the printing of certain debug messages. | ||
58 | /// </summary> | ||
59 | /// <remarks> | ||
60 | /// If DebugLevel >= 1, then short warnings are logged when receiving bad input data. | ||
61 | /// If DebugLevel >= 2, then long warnings are logged when receiving bad input data. | ||
62 | /// If DebugLevel >= 3, then short notices about all incoming non-poll HTTP requests are logged. | ||
63 | /// </remarks> | ||
64 | public int DebugLevel { get; set; } | 56 | public int DebugLevel { get; set; } |
65 | 57 | ||
66 | private volatile int NotSocketErrors = 0; | 58 | 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 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
29 | using System.Reflection; | 30 | using System.Reflection; |
30 | using System.Net; | 31 | using System.Net; |
@@ -40,13 +41,20 @@ namespace OpenSim.Framework.Servers | |||
40 | private static BaseHttpServer instance = null; | 41 | private static BaseHttpServer instance = null; |
41 | private static Dictionary<uint, BaseHttpServer> m_Servers = new Dictionary<uint, BaseHttpServer>(); | 42 | private static Dictionary<uint, BaseHttpServer> m_Servers = new Dictionary<uint, BaseHttpServer>(); |
42 | 43 | ||
44 | /// <summary> | ||
45 | /// Control the printing of certain debug messages. | ||
46 | /// </summary> | ||
47 | /// <remarks> | ||
48 | /// If DebugLevel >= 1, then short warnings are logged when receiving bad input data. | ||
49 | /// If DebugLevel >= 2, then long warnings are logged when receiving bad input data. | ||
50 | /// If DebugLevel >= 3, then short notices about all incoming non-poll HTTP requests are logged. | ||
51 | /// </remarks> | ||
43 | public static int DebugLevel | 52 | public static int DebugLevel |
44 | { | 53 | { |
45 | get { return s_debugLevel; } | 54 | get { return s_debugLevel; } |
46 | set | 55 | set |
47 | { | 56 | { |
48 | s_debugLevel = value; | 57 | s_debugLevel = value; |
49 | Instance.DebugLevel = s_debugLevel; | ||
50 | 58 | ||
51 | lock (m_Servers) | 59 | lock (m_Servers) |
52 | foreach (BaseHttpServer server in m_Servers.Values) | 60 | foreach (BaseHttpServer server in m_Servers.Values) |
@@ -56,20 +64,70 @@ namespace OpenSim.Framework.Servers | |||
56 | 64 | ||
57 | private static int s_debugLevel; | 65 | private static int s_debugLevel; |
58 | 66 | ||
67 | /// <summary> | ||
68 | /// Set the main HTTP server instance. | ||
69 | /// </summary> | ||
70 | /// <remarks> | ||
71 | /// This will be used to register all handlers that listen to the default port. | ||
72 | /// </remarks> | ||
73 | /// <exception cref='Exception'> | ||
74 | /// Thrown if the HTTP server has not already been registered via AddHttpServer() | ||
75 | /// </exception> | ||
59 | public static BaseHttpServer Instance | 76 | public static BaseHttpServer Instance |
60 | { | 77 | { |
61 | get { return instance; } | 78 | get { return instance; } |
62 | set { instance = value; } | 79 | |
80 | set | ||
81 | { | ||
82 | lock (m_Servers) | ||
83 | if (!m_Servers.ContainsValue(value)) | ||
84 | throw new Exception("HTTP server must already have been registered to be set as the main instance"); | ||
85 | |||
86 | instance = value; | ||
87 | } | ||
63 | } | 88 | } |
64 | 89 | ||
65 | /// <summary> | 90 | /// <summary> |
66 | /// Add an already started HTTP server to the collection of known servers. | 91 | /// Register an already started HTTP server to the collection of known servers. |
67 | /// </summary> | 92 | /// </summary> |
68 | /// <param name='server'></param> | 93 | /// <param name='server'></param> |
69 | public static void AddHttpServer(BaseHttpServer server) | 94 | public static void AddHttpServer(BaseHttpServer server) |
70 | { | 95 | { |
71 | lock (m_Servers) | 96 | lock (m_Servers) |
97 | { | ||
98 | if (m_Servers.ContainsKey(server.Port)) | ||
99 | throw new Exception(string.Format("HTTP server for port {0} already exists.", server.Port)); | ||
100 | |||
72 | m_Servers.Add(server.Port, server); | 101 | m_Servers.Add(server.Port, server); |
102 | } | ||
103 | } | ||
104 | |||
105 | /// <summary> | ||
106 | /// Removes the http server listening on the given port. | ||
107 | /// </summary> | ||
108 | /// <remarks> | ||
109 | /// It is the responsibility of the caller to do clean up. | ||
110 | /// </remarks> | ||
111 | /// <param name='port'></param> | ||
112 | /// <returns></returns> | ||
113 | public static bool RemoveHttpServer(uint port) | ||
114 | { | ||
115 | lock (m_Servers) | ||
116 | return m_Servers.Remove(port); | ||
117 | } | ||
118 | |||
119 | /// <summary> | ||
120 | /// Does this collection of servers contain one with the given port? | ||
121 | /// </summary> | ||
122 | /// <remarks> | ||
123 | /// Unlike GetHttpServer, this will not instantiate a server if one does not exist on that port. | ||
124 | /// </remarks> | ||
125 | /// <param name='port'></param> | ||
126 | /// <returns>true if a server with the given port is registered, false otherwise.</returns> | ||
127 | public static bool ContainsHttpServer(uint port) | ||
128 | { | ||
129 | lock (m_Servers) | ||
130 | return m_Servers.ContainsKey(port); | ||
73 | } | 131 | } |
74 | 132 | ||
75 | /// <summary> | 133 | /// <summary> |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs index c25b58c..cd70410 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 | |||
51 | [SetUp] | 51 | [SetUp] |
52 | public void SetUp() | 52 | public void SetUp() |
53 | { | 53 | { |
54 | MainServer.Instance = new BaseHttpServer(9999, false, 9998, ""); | 54 | uint port = 9999; |
55 | uint sslPort = 9998; | ||
56 | |||
57 | // This is an unfortunate bit of clean up we have to do because MainServer manages things through static | ||
58 | // variables and the VM is not restarted between tests. | ||
59 | MainServer.RemoveHttpServer(port); | ||
60 | |||
61 | BaseHttpServer server = new BaseHttpServer(port, false, sslPort, ""); | ||
62 | MainServer.AddHttpServer(server); | ||
63 | MainServer.Instance = server; | ||
55 | 64 | ||
56 | IConfigSource config = new IniConfigSource(); | 65 | IConfigSource config = new IniConfigSource(); |
57 | config.AddConfig("Startup"); | 66 | config.AddConfig("Startup"); |
diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs index 27a5879..c4324e8 100644 --- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs +++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs | |||
@@ -94,6 +94,7 @@ namespace OpenSim.Region.ClientStack | |||
94 | m_log.InfoFormat("[REGION SERVER]: Starting HTTP server on port {0}", m_httpServerPort); | 94 | m_log.InfoFormat("[REGION SERVER]: Starting HTTP server on port {0}", m_httpServerPort); |
95 | m_httpServer.Start(); | 95 | m_httpServer.Start(); |
96 | 96 | ||
97 | MainServer.AddHttpServer(m_httpServer); | ||
97 | MainServer.Instance = m_httpServer; | 98 | MainServer.Instance = m_httpServer; |
98 | 99 | ||
99 | // "OOB" Server | 100 | // "OOB" Server |
diff --git a/OpenSim/Server/Base/HttpServerBase.cs b/OpenSim/Server/Base/HttpServerBase.cs index d471559..7014303 100644 --- a/OpenSim/Server/Base/HttpServerBase.cs +++ b/OpenSim/Server/Base/HttpServerBase.cs | |||
@@ -138,6 +138,7 @@ namespace OpenSim.Server.Base | |||
138 | m_HttpServer = new BaseHttpServer(port, ssl_main, cert_path, cert_pass); | 138 | m_HttpServer = new BaseHttpServer(port, ssl_main, cert_path, cert_pass); |
139 | } | 139 | } |
140 | 140 | ||
141 | MainServer.AddHttpServer(m_HttpServer); | ||
141 | MainServer.Instance = m_HttpServer; | 142 | MainServer.Instance = m_HttpServer; |
142 | 143 | ||
143 | // If https_listener = true, then add an ssl listener on the https_port... | 144 | // If https_listener = true, then add an ssl listener on the https_port... |
@@ -157,16 +158,8 @@ namespace OpenSim.Server.Base | |||
157 | System.Console.WriteLine("Password for X509 certificate is missing, server can't start."); | 158 | System.Console.WriteLine("Password for X509 certificate is missing, server can't start."); |
158 | Thread.CurrentThread.Abort(); | 159 | Thread.CurrentThread.Abort(); |
159 | } | 160 | } |
160 | // Add our https_server | 161 | |
161 | BaseHttpServer server = null; | 162 | m_Servers.Add(https_port, new BaseHttpServer(https_port, ssl_listener, cert_path, cert_pass)); |
162 | server = new BaseHttpServer(https_port, ssl_listener, cert_path, cert_pass); | ||
163 | if (server != null) | ||
164 | { | ||
165 | m_Log.InfoFormat("[SERVER]: Starting HTTPS server on port {0}", https_port); | ||
166 | m_Servers.Add(https_port,server); | ||
167 | } | ||
168 | else | ||
169 | System.Console.WriteLine(String.Format("Failed to start HTTPS server on port {0}",https_port)); | ||
170 | } | 163 | } |
171 | } | 164 | } |
172 | 165 | ||