From 730e2d6d7c0e6ddc6448c4b6064498294134d67f Mon Sep 17 00:00:00 2001 From: Brian McBee Date: Sun, 20 Jan 2008 19:12:00 +0000 Subject: Check if remote simulator is up before attempting teleport. Teleport to a remote region should now fail gracefully if remote simulator is down. --- .../Region/Communications/OGS1/OGS1GridServices.cs | 77 ++++++++++++++++------ 1 file changed, 58 insertions(+), 19 deletions(-) (limited to 'OpenSim/Region/Communications/OGS1') diff --git a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs index e3d10b5..78dca09 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs @@ -594,28 +594,31 @@ namespace OpenSim.Region.Communications.OGS1 //don't want to be creating a new link to the remote instance every time like we are here bool retValue = false; + checkRegion(regInfo.RemotingAddress, regInfo.RemotingPort); + if (Available) + { + OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject( + typeof(OGS1InterRegionRemoting), + "tcp://" + regInfo.RemotingAddress + + ":" + regInfo.RemotingPort + + "/InterRegions"); - OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject( - typeof (OGS1InterRegionRemoting), - "tcp://" + regInfo.RemotingAddress + - ":" + regInfo.RemotingPort + - "/InterRegions"); + if (remObject != null) + { + retValue = remObject.InformRegionOfChildAgent(regionHandle, new sAgentCircuitData(agentData)); + } + else + { + Console.WriteLine("remoting object not found"); + } + remObject = null; + MainLog.Instance.Verbose("INTER", + gdebugRegionName + ": OGS1 tried to InformRegionOfChildAgent for " + + agentData.firstname + " " + agentData.lastname + " and got " + + retValue.ToString()); - if (remObject != null) - { - retValue = remObject.InformRegionOfChildAgent(regionHandle, new sAgentCircuitData(agentData)); - } - else - { - Console.WriteLine("remoting object not found"); + return retValue; } - remObject = null; - MainLog.Instance.Verbose("INTER", - gdebugRegionName + ": OGS1 tried to InformRegionOfChildAgent for " + - agentData.firstname + " " + agentData.lastname + " and got " + - retValue.ToString()); - - return retValue; } return false; @@ -1085,5 +1088,41 @@ namespace OpenSim.Region.Communications.OGS1 #endregion #endregion + + // helper to see if remote region is up + bool m_bAvailable = false; + int timeOut = 15000; //15 seconds + + public void checkRegion(string address, uint port) + { + IPAddress ia = null; + 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, false); + socket.Close(); + } + + public bool Available + { + get { return m_bAvailable; } + } + + void ConnectedMethod(IAsyncResult ar) + { + Socket socket = (Socket)ar.AsyncState; + try + { + socket.EndConnect(ar); + m_bAvailable = true; + } + catch (Exception) + { + } + socket.Close(); + } } + } \ No newline at end of file -- cgit v1.1