From 22f09fbd213ffd414514756b4a7ee0e86325d733 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Fri, 8 Aug 2008 10:59:32 +0000 Subject: * All CheckRegion within an instance would use the same, global, bool for 'Available', which would lead to intermittent failures on parallell teleport requests. * Solidified CheckRegion somewhat, adding a second try if the first failed. --- .../Region/Communications/OGS1/OGS1GridServices.cs | 64 +++++++++++++++------- 1 file changed, 44 insertions(+), 20 deletions(-) (limited to 'OpenSim/Region/Communications/OGS1/OGS1GridServices.cs') diff --git a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs index a2cddec..af3b666 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs @@ -1558,36 +1558,60 @@ namespace OpenSim.Region.Communications.OGS1 bool m_bAvailable = false; int timeOut = 10; //10 seconds - public void CheckRegion(string address, uint port) + public bool CheckRegion(string address, uint port, bool retry) { - m_bAvailable = false; - IPAddress ia = null; + bool available = false; + bool timed_out = true; + + IPAddress ia; IPAddress.TryParse(address, out ia); IPEndPoint m_EndPoint = new IPEndPoint(ia, (int)port); - AsyncCallback ConnectedMethodCallback = new AsyncCallback(ConnectedMethod); - Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - IAsyncResult ar = socket.BeginConnect(m_EndPoint, ConnectedMethodCallback, socket); - ar.AsyncWaitHandle.WaitOne(timeOut*1000, false); - Thread.Sleep(500); - } - public bool Available - { - get { return m_bAvailable; } - } + AsyncCallback callback = delegate(IAsyncResult iar) + { + Socket s = (Socket)iar.AsyncState; + try + { + s.EndConnect(iar); + available = true; + timed_out = false; + } + catch (Exception e) + { + m_log.DebugFormat("Callback EndConnect exception: {0}:{1}", e.Message, e.StackTrace); + } + + s.Close(); + }; - void ConnectedMethod(IAsyncResult ar) - { - Socket socket = (Socket)ar.AsyncState; try { - socket.EndConnect(ar); - m_bAvailable = true; + Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + IAsyncResult ar = socket.BeginConnect(m_EndPoint, callback, socket); + ar.AsyncWaitHandle.WaitOne(timeOut * 1000, false); } - catch (Exception) + catch (Exception e) + { + m_log.DebugFormat("CheckRegion Socket Setup exception: {0}:{1}", e.Message, e.StackTrace); + return false; + } + + if (timed_out) { + m_log.DebugFormat("socket [{0}] timed out ({1}) waiting to obtain a connection.", m_EndPoint, timeOut * 1000); + + if (retry) + { + return CheckRegion(address, port, false); + } } - socket.Close(); + + return available; + } + + public bool CheckRegion(string address, uint port) + { + return CheckRegion(address, port, true); } public void NoteDeadRegion(ulong regionhandle) -- cgit v1.1