diff --git a/Common/OpenSim.Servers/OpenSim.Servers.csproj b/Common/OpenSim.Servers/OpenSim.Servers.csproj index a4f56fe38b..7a992060ed 100644 --- a/Common/OpenSim.Servers/OpenSim.Servers.csproj +++ b/Common/OpenSim.Servers/OpenSim.Servers.csproj @@ -113,6 +113,9 @@ Code + + Code + Code diff --git a/Common/OpenSim.Servers/OpenSim.Servers.dll.build b/Common/OpenSim.Servers/OpenSim.Servers.dll.build index 25bcd6554a..6147ea7334 100644 --- a/Common/OpenSim.Servers/OpenSim.Servers.dll.build +++ b/Common/OpenSim.Servers/OpenSim.Servers.dll.build @@ -18,6 +18,7 @@ + diff --git a/Common/OpenSim.Servers/SocketRegistry.cs b/Common/OpenSim.Servers/SocketRegistry.cs new file mode 100644 index 0000000000..2ebf80cdca --- /dev/null +++ b/Common/OpenSim.Servers/SocketRegistry.cs @@ -0,0 +1,63 @@ +/* + * Created by SharpDevelop. + * User: Adam Stevenson + * Date: 6/13/2007 + * Time: 12:55 AM + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; + +namespace OpenSim.Servers +{ + /// + /// + /// + public class SocketRegistry + { + static List _Sockets; + + static SocketRegistry() + { + _Sockets = new List(); + } + + private SocketRegistry() + { + + } + + public static void Register(Socket pSocket) + { + _Sockets.Add(pSocket); + } + + public static void Unregister(Socket pSocket) + { + _Sockets.Remove(pSocket); + } + + public static void UnregisterAllAndClose() + { + int iSockets = _Sockets.Count; + + for (int i = 0; i < iSockets; i++) + { + try + { + _Sockets[i].Close(); + } + catch + { + + } + } + + _Sockets.Clear(); + } + } +} diff --git a/Common/OpenSim.Servers/UDPServerBase.cs b/Common/OpenSim.Servers/UDPServerBase.cs index b472c978bd..b7633155ab 100644 --- a/Common/OpenSim.Servers/UDPServerBase.cs +++ b/Common/OpenSim.Servers/UDPServerBase.cs @@ -78,6 +78,13 @@ namespace OpenSim.Servers 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); ipeSender = new IPEndPoint(IPAddress.Any, 0); @@ -93,3 +100,4 @@ namespace OpenSim.Servers } } + diff --git a/OpenGridServices/OpenGrid.Config/GridConfigDb4o/OpenGrid.Config.GridConfigDb4o.dll.build b/OpenGridServices/OpenGrid.Config/GridConfigDb4o/OpenGrid.Config.GridConfigDb4o.dll.build index 075593ba3e..d0ba0a8c96 100644 --- a/OpenGridServices/OpenGrid.Config/GridConfigDb4o/OpenGrid.Config.GridConfigDb4o.dll.build +++ b/OpenGridServices/OpenGrid.Config/GridConfigDb4o/OpenGrid.Config.GridConfigDb4o.dll.build @@ -21,8 +21,8 @@ - - + + diff --git a/OpenGridServices/OpenGrid.Framework.Manager/OpenGrid.Framework.Manager.dll.build b/OpenGridServices/OpenGrid.Framework.Manager/OpenGrid.Framework.Manager.dll.build index 9430ab94ea..7195699e4e 100644 --- a/OpenGridServices/OpenGrid.Framework.Manager/OpenGrid.Framework.Manager.dll.build +++ b/OpenGridServices/OpenGrid.Framework.Manager/OpenGrid.Framework.Manager.dll.build @@ -20,10 +20,10 @@ - - + + - + diff --git a/OpenGridServices/OpenGridServices.AssetServer/OpenGridServices.AssetServer.exe.build b/OpenGridServices/OpenGridServices.AssetServer/OpenGridServices.AssetServer.exe.build index 808f015636..f9976e3931 100644 --- a/OpenGridServices/OpenGridServices.AssetServer/OpenGridServices.AssetServer.exe.build +++ b/OpenGridServices/OpenGridServices.AssetServer/OpenGridServices.AssetServer.exe.build @@ -22,14 +22,14 @@ - - - - + + + + - + diff --git a/OpenGridServices/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build b/OpenGridServices/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build index 60c0f85e90..f8951b7460 100644 --- a/OpenGridServices/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build +++ b/OpenGridServices/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build @@ -24,14 +24,14 @@ - - - - + + + + - + diff --git a/OpenGridServices/OpenGridServices.InventoryServer/OpenGridServices.InventoryServer.csproj.user b/OpenGridServices/OpenGridServices.InventoryServer/OpenGridServices.InventoryServer.csproj.user index ea58087314..179959e750 100644 --- a/OpenGridServices/OpenGridServices.InventoryServer/OpenGridServices.InventoryServer.csproj.user +++ b/OpenGridServices/OpenGridServices.InventoryServer/OpenGridServices.InventoryServer.csproj.user @@ -2,7 +2,7 @@ Debug AnyCPU - C:\Documents and Settings\Stefan\My Documents\source\opensim\trunk\bin\ + E:\work\oslauth\sim\trunk\bin\ 8.0.50727 ProjectFiles 0 diff --git a/OpenGridServices/OpenGridServices.InventoryServer/OpenGridServices.InventoryServer.exe.build b/OpenGridServices/OpenGridServices.InventoryServer/OpenGridServices.InventoryServer.exe.build index 5e67af13f8..ff980ad3c4 100644 --- a/OpenGridServices/OpenGridServices.InventoryServer/OpenGridServices.InventoryServer.exe.build +++ b/OpenGridServices/OpenGridServices.InventoryServer/OpenGridServices.InventoryServer.exe.build @@ -22,14 +22,14 @@ - - - - + + + + - + diff --git a/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build b/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build index 68cbef70ff..894c28264f 100644 --- a/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build +++ b/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build @@ -23,14 +23,14 @@ - - - - + + + + - + diff --git a/OpenGridServices/OpenUser.Config/UserConfigDb4o/OpenUser.Config.UserConfigDb4o.dll.build b/OpenGridServices/OpenUser.Config/UserConfigDb4o/OpenUser.Config.UserConfigDb4o.dll.build index bd5d49fb8d..31801c737e 100644 --- a/OpenGridServices/OpenUser.Config/UserConfigDb4o/OpenUser.Config.UserConfigDb4o.dll.build +++ b/OpenGridServices/OpenUser.Config/UserConfigDb4o/OpenUser.Config.UserConfigDb4o.dll.build @@ -21,8 +21,8 @@ - - + + diff --git a/OpenGridServices/ServiceManager/ServiceManager.exe.build b/OpenGridServices/ServiceManager/ServiceManager.exe.build index e0502c68e5..d50b1bb39b 100644 --- a/OpenGridServices/ServiceManager/ServiceManager.exe.build +++ b/OpenGridServices/ServiceManager/ServiceManager.exe.build @@ -19,8 +19,8 @@ - - + + diff --git a/OpenSim/OpenSim.RegionServer/UDPServer.cs b/OpenSim/OpenSim.RegionServer/UDPServer.cs index f0d33670ee..ae62607ed1 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 e3b23ad999..15fcd93252 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") + 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++) { - 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") - { - 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; + + sim.StartUp(); + + while (true) + { + OpenSim.Framework.Console.MainConsole.Instance.MainConsolePrompt(); } } - - 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(); - - while (true) + catch (Exception oException) { - OpenSim.Framework.Console.MainConsole.Instance.MainConsolePrompt(); + Console.WriteLine(oException.Message); + Console.WriteLine("Fatal error. Server is shutdown. Press 'Enter' to close."); + Console.ReadLine(); + + } + finally + { + /// 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(); } } } diff --git a/Prebuild/Prebuild.sln b/Prebuild/Prebuild.sln index 227677f007..449896b4ee 100644 --- a/Prebuild/Prebuild.sln +++ b/Prebuild/Prebuild.sln @@ -3,17 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 9.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prebuild", "src\Prebuild.csproj", "{92E80C1C-0000-0000-0000-000000000000}" EndProject Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {92E80C1C-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {92E80C1C-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {92E80C1C-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {92E80C1C-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {92E80C1C-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92E80C1C-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92E80C1C-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92E80C1C-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection EndGlobal