Index: trunk/FACT++/src/sqmctrl.cc
===================================================================
--- trunk/FACT++/src/sqmctrl.cc	(revision 17918)
+++ trunk/FACT++/src/sqmctrl.cc	(revision 17929)
@@ -29,11 +29,10 @@
 
 private:
-    bool fIsVerbose;
-    bool fMsgReceived;
-    bool fMsgValid;
-
+    bool     fIsVerbose;
     uint16_t fTimeout;
 
     boost::asio::streambuf fBuffer;
+
+    boost::asio::deadline_timer fTrigger;
 
     void HandleRead(const boost::system::error_code& err, size_t bytes_received)
@@ -64,5 +63,5 @@
         if (!getline(is, buffer, '\n'))
         {
-            Error("Received message does not contain \\n... closing connection.");
+            Fatal("Received message does not contain \\n... closing connection.");
             PostClose(false);
             return;
@@ -72,9 +71,13 @@
 
         if (fIsVerbose)
-            Out() << buffer << endl;
+            Out() << Time().GetAsStr("%H:%M:%S.%f") << "[" << buffer.size() << "]: " << buffer << endl;
 
         vector<string> vec;
         boost::split(vec, buffer, boost::is_any_of(","));
 
+        // Send next request in fTimeout milliseconds
+        fTrigger.expires_from_now(boost::posix_time::milliseconds(fTimeout));
+        fTrigger.async_wait(boost::bind(&ConnectionSQM::HandleRequestTrigger,
+                                          this, dummy::error));
         try
         {
@@ -83,5 +86,5 @@
 
             if (vec[0]!="r")
-                throw runtime_error("Not a 'reading request' answer.");
+                throw runtime_error("Not a 'reading request' answer: "+vec[0]);
 
             SQM::Data data;
@@ -97,13 +100,8 @@
         catch (const exception &e)
         {
-            fMsgValid = false;
             Error("Parsing received data failed ["+string(e.what())+"]");
             Error("Received: "+buffer);
-            PostClose(false);
-            return;
-        }
-
-        fMsgValid    = true;
-        fMsgReceived = true;
+            PostClose(true);
+        }
     }
 
@@ -114,5 +112,5 @@
         {
             ostringstream str;
-            str << "Read timeout of " << URL() << ": " << error.message() << " (" << error << ")";// << endl;
+            str << "ReadTimeout of " << URL() << " failed: " << error.message() << " (" << error << ")";// << endl;
             Error(str);
 
@@ -125,5 +123,5 @@
             // For example: Here we could schedule a new accept if we
             // would not want to allow two connections at the same time.
-            PostClose(true);
+            //PostClose(true);
             return;
         }
@@ -136,12 +134,6 @@
             return;
 
-        if (fMsgReceived)
-        {
-            StartReadReport();
-            return;
-        }
-
         ostringstream str;
-        str << "No answer received from " << URL() << ".";
+        str << "No valid answer received from " << URL() << " within " << ceil(fTimeout*1.5) << "ms";
         Error(str);
 
@@ -149,14 +141,44 @@
     }
 
+    void HandleRequestTrigger(const bs::error_code &error)
+    {
+        // 125: Operation canceled (bs::error_code(125, bs::system_category))
+        if (error && error!=ba::error::basic_errors::operation_aborted)
+        {
+            ostringstream str;
+            str << "RequestTrigger failed of " << URL() << " failed: " << error.message() << " (" << error << ")";// << endl;
+            Error(str);
+
+            PostClose(true);
+            return;
+        }
+
+        if (!is_open())
+        {
+            // For example: Here we could schedule a new accept if we
+            // would not want to allow two connections at the same time.
+            //PostClose(true);
+            return;
+        }
+
+        // Check whether the deadline has passed. We compare the deadline
+        // against the current time since a new asynchronous operation
+        // may have moved the deadline before this actor had a chance
+        // to run.
+        if (fTrigger.expires_at() > ba::deadline_timer::traits_type::now())
+            return;
+
+        StartReadReport();
+    }
+
     void StartReadReport()
     {
-        fMsgReceived = false;
-
         PostMessage(string("rx\n"), 3);
+
         async_read_until(*this, fBuffer, '\n',
                          boost::bind(&ConnectionSQM::HandleRead, this,
                                      dummy::error, dummy::bytes_transferred));
 
-        fInTimeout.expires_from_now(boost::posix_time::milliseconds(fTimeout));
+        fInTimeout.expires_from_now(boost::posix_time::milliseconds(fTimeout*2.5));
         fInTimeout.async_wait(boost::bind(&ConnectionSQM::HandleReadTimeout,
                                           this, dummy::error));
@@ -175,5 +197,5 @@
 public:
     ConnectionSQM(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
-        fIsVerbose(true)
+        fIsVerbose(true), fTimeout(0), fTrigger(ioservice)
     {
         SetLogStream(&imp);
@@ -193,8 +215,5 @@
     int GetState() const
     {
-        if (!is_open())
-            return SQM::State::kDisconnected;
-
-        return fMsgValid ? SQM::State::kValid : SQM::State::kConnected;
+        return is_open() ? SQM::State::kConnected : SQM::State::kDisconnected;
     }
 };
