From 16b43b8bffff8f11f0f633d8f503e752223a4772 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 14 Jun 2007 14:36:40 +0000 Subject: * Added maintenance patch (issue #139) from BigfootAg to /trunk --- OpenSim/OpenSim.RegionServer/UDPServer.cs | 11 ++- OpenSim/OpenSim/Application.cs | 153 +++++++++++++++++------------- 2 files changed, 95 insertions(+), 69 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/OpenSim.RegionServer/UDPServer.cs b/OpenSim/OpenSim.RegionServer/UDPServer.cs index f0d3367..ae62607 100644 --- a/OpenSim/OpenSim.RegionServer/UDPServer.cs +++ b/OpenSim/OpenSim.RegionServer/UDPServer.cs @@ -61,7 +61,7 @@ namespace OpenSim.RegionServer public class UDPServer : OpenSimNetworkHandler { protected Dictionary clientCircuits = new Dictionary(); - public Socket Server; + private Socket Server; protected IPEndPoint ServerIncoming; protected byte[] RecvBuffer = new byte[4096]; protected byte[] ZeroBuffer = new byte[8192]; @@ -201,6 +201,13 @@ namespace OpenSim.RegionServer ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort); Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + + /// Add this new socket to the list of sockets that was opened by the application. When the application + /// closes, either gracefully or not, all sockets can be cleaned up. Right now I am not aware of any method + /// to get all of the sockets for a process within .NET, but if so, this process can be refactored, as + /// socket registration would not be neccessary. + SocketRegistry.Register(Server); + Server.Bind(ServerIncoming); m_console.Notice("UDPServer.cs:ServerListener() - UDP socket bound, getting ready to listen"); @@ -255,4 +262,4 @@ namespace OpenSim.RegionServer return this.AuthenticateHandler(sessionID, agentID, circuitCode); } } -} \ No newline at end of file +} diff --git a/OpenSim/OpenSim/Application.cs b/OpenSim/OpenSim/Application.cs index e3b23ad..15fcd93 100644 --- a/OpenSim/OpenSim/Application.cs +++ b/OpenSim/OpenSim/Application.cs @@ -41,84 +41,103 @@ namespace OpenSim [STAThread] public static void Main(string[] args) { - Console.WriteLine("OpenSim " + VersionInfo.Version + "\n"); - Console.WriteLine("Starting...\n"); - - bool sandBoxMode = false; - bool startLoginServer = false; - string physicsEngine = "basicphysics"; - bool allowFlying = false; - bool userAccounts = false; - bool gridLocalAsset = false; - bool useConfigFile = false; - bool silent = false; - string configFile = "simconfig.xml"; - - for (int i = 0; i < args.Length; i++) + try { - if (args[i] == "-sandbox") - { - sandBoxMode = true; - userAccounts = true; - startLoginServer = true; - } - /* - if (args[i] == "-loginserver") - { - startLoginServer = true; - }*/ - if (args[i] == "-accounts") - { - userAccounts = true; - } - if (args[i] == "-realphysx") - { - physicsEngine = "RealPhysX"; - allowFlying = true; - } - if (args[i] == "-ode") - { - physicsEngine = "OpenDynamicsEngine"; - allowFlying = true; - } - if (args[i] == "-localasset") - { - gridLocalAsset = true; - } - if (args[i] == "-configfile") - { - useConfigFile = true; - } - if (args[i] == "-noverbose") - { - silent = true; - } - if (args[i] == "-config") + Console.WriteLine("OpenSim " + VersionInfo.Version + "\n"); + Console.WriteLine("Starting...\n"); + + bool sandBoxMode = false; + bool startLoginServer = false; + string physicsEngine = "basicphysics"; + bool allowFlying = false; + bool userAccounts = false; + bool gridLocalAsset = false; + bool useConfigFile = false; + bool silent = false; + string configFile = "simconfig.xml"; + + for (int i = 0; i < args.Length; i++) { - try + if (args[i] == "-sandbox") { - i++; - configFile = args[i]; + sandBoxMode = true; + userAccounts = true; + startLoginServer = true; } - catch (Exception e) + /* + if (args[i] == "-loginserver") { - Console.WriteLine("-config: Please specify a config file. (" + e.ToString() + ")"); + startLoginServer = true; + }*/ + if (args[i] == "-accounts") + { + userAccounts = true; + } + if (args[i] == "-realphysx") + { + physicsEngine = "RealPhysX"; + allowFlying = true; + } + if (args[i] == "-ode") + { + physicsEngine = "OpenDynamicsEngine"; + allowFlying = true; + } + if (args[i] == "-localasset") + { + gridLocalAsset = true; + } + if (args[i] == "-configfile") + { + useConfigFile = true; + } + if (args[i] == "-noverbose") + { + silent = true; + } + if (args[i] == "-config") + { + try + { + i++; + configFile = args[i]; + } + catch (Exception e) + { + Console.WriteLine("-config: Please specify a config file. (" + e.ToString() + ")"); + } } } - } - OpenSimMain sim = new OpenSimMain(sandBoxMode, startLoginServer, physicsEngine, useConfigFile, silent, configFile); - // OpenSimRoot.Instance.Application = sim; - sim.m_sandbox = sandBoxMode; - sim.user_accounts = userAccounts; - sim.gridLocalAsset = gridLocalAsset; - OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = allowFlying; + OpenSimMain sim = new OpenSimMain(sandBoxMode, startLoginServer, physicsEngine, useConfigFile, silent, configFile); + // OpenSimRoot.Instance.Application = sim; + sim.m_sandbox = sandBoxMode; + sim.user_accounts = userAccounts; + sim.gridLocalAsset = gridLocalAsset; + OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = allowFlying; - sim.StartUp(); + sim.StartUp(); - while (true) + while (true) + { + OpenSim.Framework.Console.MainConsole.Instance.MainConsolePrompt(); + } + } + catch (Exception oException) + { + Console.WriteLine(oException.Message); + Console.WriteLine("Fatal error. Server is shutdown. Press 'Enter' to close."); + Console.ReadLine(); + + } + finally { - OpenSim.Framework.Console.MainConsole.Instance.MainConsolePrompt(); + /// Ensure that all sockets have been closed before the process closes. This helps ensure that no + /// open ports are left open on process that ''. This is in the finally block, as it + /// should be done regardless of whether a exception closes the application, or if the application + /// is closed normally. + + OpenSim.Servers.SocketRegistry.UnregisterAllAndClose(); } } } -- cgit v1.1