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 --- Common/OpenSim.Servers/OpenSim.Servers.csproj | 3 ++ Common/OpenSim.Servers/OpenSim.Servers.dll.build | 1 + Common/OpenSim.Servers/SocketRegistry.cs | 63 ++++++++++++++++++++++++ Common/OpenSim.Servers/UDPServerBase.cs | 8 +++ 4 files changed, 75 insertions(+) create mode 100644 Common/OpenSim.Servers/SocketRegistry.cs (limited to 'Common') diff --git a/Common/OpenSim.Servers/OpenSim.Servers.csproj b/Common/OpenSim.Servers/OpenSim.Servers.csproj index a4f56fe..7a99206 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 25bcd65..6147ea7 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 0000000..2ebf80c --- /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 b472c97..b763315 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 } } + -- cgit v1.1