Revision: 8593
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8593&view=rev
Author:   hsujohnhsu
Date:     2010-03-18 02:55:26 +0000 (Thu, 18 Mar 2010)

Log Message:
-----------
reinstate realTime comparison in Client::ConnectWait() as race condition is 
evident in hudson test.

Modified Paths:
--------------
    code/gazebo/trunk/libgazebo/Client.cc

Modified: code/gazebo/trunk/libgazebo/Client.cc
===================================================================
--- code/gazebo/trunk/libgazebo/Client.cc       2010-03-18 01:31:15 UTC (rev 
8592)
+++ code/gazebo/trunk/libgazebo/Client.cc       2010-03-18 02:55:26 UTC (rev 
8593)
@@ -85,6 +85,7 @@
 void Client::ConnectWait(int serverId, int clientId)
 {
   bool simulationIfaceIsValid = false;
+  gazebo::SimulationIface *simIface = new gazebo::SimulationIface();
 
   while (!simulationIfaceIsValid)
   {
@@ -155,9 +156,36 @@
           if(kill(pid, 0) == 0) 
           {
             // a gazebo process is still alive.
-            simulationIfaceIsValid = true;
-            // it might however, still being booted up, so we need to check 
somehow
-            // or is it?
+            // it might however, still being booted up, so we need to check by 
connecting
+            // Connect to gazebo::SimulationIface and check for changing 
realTime,
+            // if simulationIface->data->realTime is not changing, the server 
might
+            // be stale leftovers from previous gazebo crash,
+            // disconnect and reconnect client
+            try
+            {
+              // Open the Simulation Interface
+              gazebo::SimulationIface simulationIface;
+              simulationIface.Open(this,"default");
+              // grab a t0
+              simulationIface.Lock(1);
+              double simTime0 = simulationIface.data->realTime;
+              simulationIface.Unlock();
+              // now check and wait for sim time to change
+              usleep(10000);
+              simulationIface.Lock(1);
+              double simTime1 = simulationIface.data->realTime;
+              simulationIface.Unlock();
+              if (simTime0 != simTime1)  // simTime changed, wait is over
+                simulationIfaceIsValid = true;
+              simulationIface.Close();
+
+            }
+            catch (std::string e)
+            {
+              //std::cout << "Gazebo error: Unable to connect to the sim 
interface\n" << e << "\n";
+            }
+
+
           } 
           else 
           {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to