aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/UDPServer.cs
diff options
context:
space:
mode:
authorTedd Hansen2008-02-02 06:34:07 +0000
committerTedd Hansen2008-02-02 06:34:07 +0000
commitb089ccfa3d351b4dba43bcbc284d87d7c4963dae (patch)
tree19c7e9baea656b1c112754ce777cde391101369b /OpenSim/Region/ClientStack/UDPServer.cs
parentLast patch was a disaster... reset terrain whenever bug occurred. Trying agai... (diff)
downloadopensim-SC-b089ccfa3d351b4dba43bcbc284d87d7c4963dae.zip
opensim-SC-b089ccfa3d351b4dba43bcbc284d87d7c4963dae.tar.gz
opensim-SC-b089ccfa3d351b4dba43bcbc284d87d7c4963dae.tar.bz2
opensim-SC-b089ccfa3d351b4dba43bcbc284d87d7c4963dae.tar.xz
Hopefully fixed MySQL DB crash on startup issue (so we can remove 3 sec wait).
Added option to try alternate UDP ports if the one configured is in use. UDP packets are now bound to the actual outside IP address and hopefully won't "randomly" select IP on multihomed systems.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/UDPServer.cs45
1 files changed, 37 insertions, 8 deletions
diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs
index dc76c20..e292c2c 100644
--- a/OpenSim/Region/ClientStack/UDPServer.cs
+++ b/OpenSim/Region/ClientStack/UDPServer.cs
@@ -52,6 +52,8 @@ namespace OpenSim.Region.ClientStack
52 protected ulong m_regionHandle; 52 protected ulong m_regionHandle;
53 53
54 protected uint listenPort; 54 protected uint listenPort;
55 protected bool Allow_Alternate_Port;
56 protected IPAddress listenIP = IPAddress.Parse("0.0.0.0");
55 protected IScene m_localScene; 57 protected IScene m_localScene;
56 protected AssetCache m_assetCache; 58 protected AssetCache m_assetCache;
57 protected LogBase m_log; 59 protected LogBase m_log;
@@ -82,13 +84,20 @@ namespace OpenSim.Region.ClientStack
82 { 84 {
83 } 85 }
84 86
85 public UDPServer(uint port, AssetCache assetCache, LogBase console, AgentCircuitManager authenticateClass) 87 public UDPServer(IPAddress _listenIP, ref uint port, bool allow_alternate_port, AssetCache assetCache, LogBase console, AgentCircuitManager authenticateClass)
86 { 88 {
89 listenIP = _listenIP;
87 listenPort = port; 90 listenPort = port;
91 Allow_Alternate_Port = allow_alternate_port;
88 m_assetCache = assetCache; 92 m_assetCache = assetCache;
89 m_log = console; 93 m_log = console;
90 m_authenticateSessionsClass = authenticateClass; 94 m_authenticateSessionsClass = authenticateClass;
91 CreatePacketServer(); 95 CreatePacketServer();
96
97 // Return new port
98 // This because in Grid mode it is not really important what port the region listens to as long as it is correctly registered.
99 // So the option allow_alternate_ports="true" was added to default.xml
100 port = listenPort;
92 } 101 }
93 102
94 protected virtual void CreatePacketServer() 103 protected virtual void CreatePacketServer()
@@ -98,7 +107,7 @@ namespace OpenSim.Region.ClientStack
98 107
99 protected virtual void OnReceivedData(IAsyncResult result) 108 protected virtual void OnReceivedData(IAsyncResult result)
100 { 109 {
101 ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); 110 ipeSender = new IPEndPoint(listenIP, 0);
102 epSender = (EndPoint) ipeSender; 111 epSender = (EndPoint) ipeSender;
103 Packet packet = null; 112 Packet packet = null;
104 113
@@ -246,20 +255,40 @@ namespace OpenSim.Region.ClientStack
246 255
247 public void ServerListener() 256 public void ServerListener()
248 { 257 {
249 m_log.Verbose("SERVER", "Opening UDP socket on " + listenPort.ToString());
250 258
251 ServerIncoming = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int) listenPort); 259 uint newPort = listenPort;
252 Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); 260 for (uint i = 0; i < 10; i++)
253 Server.Bind(ServerIncoming); 261 {
262 newPort = listenPort + i;
263 m_log.Verbose("SERVER", "Opening UDP socket on " + listenIP.ToString() + " " + newPort + ". Allow alternate ports: " + Allow_Alternate_Port.ToString());
264 try
265 {
266 ServerIncoming = new IPEndPoint(listenIP, (int) newPort);
267 Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
268 Server.Bind(ServerIncoming);
269 listenPort = newPort;
270 break;
271 }
272 catch (Exception ex)
273 {
274 // We are not looking for alternate ports?
275 if (!Allow_Alternate_Port)
276 throw (ex);
277
278 // We are looking for alternate ports!
279 m_log.Verbose("SERVER", "UDP socket on " + listenIP.ToString() + " " + listenPort.ToString() + " is not available, trying next.");
280 }
281 System.Threading.Thread.Sleep(100); // Wait before we retry socket
282 }
254 283
255 m_log.Verbose("SERVER", "UDP socket bound, getting ready to listen"); 284 m_log.Verbose("SERVER", "UDP socket bound, getting ready to listen");
256 285
257 ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); 286 ipeSender = new IPEndPoint(listenIP, 0);
258 epSender = (EndPoint) ipeSender; 287 epSender = (EndPoint) ipeSender;
259 ReceivedData = new AsyncCallback(OnReceivedData); 288 ReceivedData = new AsyncCallback(OnReceivedData);
260 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); 289 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
261 290
262 m_log.Status("SERVER", "Listening..."); 291 m_log.Status("SERVER", "Listening on port " + newPort);
263 } 292 }
264 293
265 public virtual void RegisterPacketServer(PacketServer server) 294 public virtual void RegisterPacketServer(PacketServer server)