aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Communications/OGS1
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Communications/OGS1')
-rw-r--r--OpenSim/Region/Communications/OGS1/OGS1GridServices.cs64
1 files changed, 44 insertions, 20 deletions
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
1558 bool m_bAvailable = false; 1558 bool m_bAvailable = false;
1559 int timeOut = 10; //10 seconds 1559 int timeOut = 10; //10 seconds
1560 1560
1561 public void CheckRegion(string address, uint port) 1561 public bool CheckRegion(string address, uint port, bool retry)
1562 { 1562 {
1563 m_bAvailable = false; 1563 bool available = false;
1564 IPAddress ia = null; 1564 bool timed_out = true;
1565
1566 IPAddress ia;
1565 IPAddress.TryParse(address, out ia); 1567 IPAddress.TryParse(address, out ia);
1566 IPEndPoint m_EndPoint = new IPEndPoint(ia, (int)port); 1568 IPEndPoint m_EndPoint = new IPEndPoint(ia, (int)port);
1567 AsyncCallback ConnectedMethodCallback = new AsyncCallback(ConnectedMethod);
1568 Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
1569 IAsyncResult ar = socket.BeginConnect(m_EndPoint, ConnectedMethodCallback, socket);
1570 ar.AsyncWaitHandle.WaitOne(timeOut*1000, false);
1571 Thread.Sleep(500);
1572 }
1573 1569
1574 public bool Available 1570 AsyncCallback callback = delegate(IAsyncResult iar)
1575 { 1571 {
1576 get { return m_bAvailable; } 1572 Socket s = (Socket)iar.AsyncState;
1577 } 1573 try
1574 {
1575 s.EndConnect(iar);
1576 available = true;
1577 timed_out = false;
1578 }
1579 catch (Exception e)
1580 {
1581 m_log.DebugFormat("Callback EndConnect exception: {0}:{1}", e.Message, e.StackTrace);
1582 }
1583
1584 s.Close();
1585 };
1578 1586
1579 void ConnectedMethod(IAsyncResult ar)
1580 {
1581 Socket socket = (Socket)ar.AsyncState;
1582 try 1587 try
1583 { 1588 {
1584 socket.EndConnect(ar); 1589 Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
1585 m_bAvailable = true; 1590 IAsyncResult ar = socket.BeginConnect(m_EndPoint, callback, socket);
1591 ar.AsyncWaitHandle.WaitOne(timeOut * 1000, false);
1586 } 1592 }
1587 catch (Exception) 1593 catch (Exception e)
1594 {
1595 m_log.DebugFormat("CheckRegion Socket Setup exception: {0}:{1}", e.Message, e.StackTrace);
1596 return false;
1597 }
1598
1599 if (timed_out)
1588 { 1600 {
1601 m_log.DebugFormat("socket [{0}] timed out ({1}) waiting to obtain a connection.", m_EndPoint, timeOut * 1000);
1602
1603 if (retry)
1604 {
1605 return CheckRegion(address, port, false);
1606 }
1589 } 1607 }
1590 socket.Close(); 1608
1609 return available;
1610 }
1611
1612 public bool CheckRegion(string address, uint port)
1613 {
1614 return CheckRegion(address, port, true);
1591 } 1615 }
1592 1616
1593 public void NoteDeadRegion(ulong regionhandle) 1617 public void NoteDeadRegion(ulong regionhandle)