Index: /trunk/FACT++/src/gtcdust.cc
===================================================================
--- /trunk/FACT++/src/gtcdust.cc	(revision 20087)
+++ /trunk/FACT++/src/gtcdust.cc	(revision 20088)
@@ -13,5 +13,5 @@
 #include "StateMachineDim.h"
 #include "StateMachineAsio.h"
-#include "Connection.h"
+#include "ConnectionSSL.h"
 #include "LocalControl.h"
 #include "Configuration.h"
@@ -32,5 +32,5 @@
 // ------------------------------------------------------------------------
 
-class ConnectionGTC : public Connection
+class ConnectionGTC : public ConnectionSSL
 {
     uint16_t fInterval;
@@ -45,5 +45,6 @@
     Time fLastReception;
 
-    boost::asio::streambuf fBuffer;
+//    boost::asio::streambuf fBuffer;
+    boost::array<char, 4096> fArray;
     string fData;
 
@@ -54,13 +55,19 @@
     void ProcessAnswer(string s)
     {
+        std::stringstream ss;
+        pt::ptree tree;
         try
         {
-            std::stringstream ss;
             ss << s;
-
-            pt::ptree tree;
             pt::read_json(ss, tree);
 
+        }
+        catch (std::exception const& e)
+        {
+            Error(string("Parsing JSON failed: ")+e.what());
+        }
             // {"pm25":{"Value":"13.9000","Date":"2019-10-03 10:31:40"}}
+        try
+        {
 
             const auto &pm25 = tree.get_child("pm25");
@@ -80,5 +87,5 @@
         catch (std::exception const& e)
         {
-            Error(string("Parsing JSON failed: ")+e.what());
+            Error(string("Illformated report: ")+e.what());
         }
     }
@@ -92,16 +99,9 @@
             // the connection being closed by the server.
             // I do not understand why bytes_received is 0 then.
-            //
-            // Extract whatever is left in the buffer
-            istream is(&fBuffer);
-            string buffer;
-            getline(is, buffer);
-            fData += buffer;
-
-            if (fIsVerbose)
-                Out() << "EOF|" << buffer << endl;
-
-            if (err==ba::error::eof)
+            if (err==ba::error::eof || err==ba::ssl::error::stream_truncated)
             {
+                if (fIsVerbose)
+                    Out() << "EOF" << endl;
+
                 // Does the message contain a header?
                 const size_t p1 = fData.find("\r\n\r\n");
@@ -113,5 +113,4 @@
 
                 PostClose(false);
-
                 return;
             }
@@ -119,5 +118,5 @@
             // 107: Transport endpoint is not connected (bs::error_code(107, bs::system_category))
             // 125: Operation canceled
-            if (err && err!=ba::error::eof &&                     // Connection closed by remote host
+            if (err &&                                            // Connection closed by remote host
                 err!=ba::error::basic_errors::not_connected &&    // Connection closed by remote host
                 err!=ba::error::basic_errors::operation_aborted)  // Connection closed by us
@@ -133,29 +132,18 @@
         fLastReception = Time();
 
-        istream is(&fBuffer);
-
-        string buffer;
-        if (!getline(is, buffer, '\n'))
-        {
-            Fatal("Received message does not contain \\n... closing connection.");
-            PostClose(false);
-            return;
-        }
-
+        const string buffer(fArray.data(), bytes_received);
         if (fIsVerbose)
             Out() << bytes_received << "|" << buffer << endl;
-
         fData += buffer;
-        fData += '\n';
-
-        StartReadLine();
-    }
-
-    void StartReadLine()
+
+        StartRead();
+    }
+
+    void StartRead()
     {
         // The last report (payload) is simply termined by the connection being closed by the server.
-        async_read_until(*this, fBuffer, '\n',
-                         boost::bind(&ConnectionGTC::HandleRead, this,
-                                     dummy::error, dummy::bytes_transferred));
+        stream->async_read_some(ba::buffer(fArray),
+                                boost::bind(&ConnectionGTC::HandleRead, this,
+                                            dummy::error, dummy::bytes_transferred));
     }
 
@@ -204,5 +192,5 @@
         }
 
-        if (!is_open())
+        if (IsClosed())
         {
             // For example: Here we could schedule a new accept if we
@@ -228,9 +216,9 @@
     {
         Request();
-        StartReadLine();
+        StartRead();
     }
 
 public:
-    ConnectionGTC(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
+    ConnectionGTC(ba::io_service& ioservice, MessageImp &imp) : ConnectionSSL(ioservice, imp()),
         fIsVerbose(true), fLastReport(Time::none), fLastReception(Time::none), fKeepAlive(ioservice)
     {
@@ -241,5 +229,5 @@
     {
         fIsVerbose = b;
-        Connection::SetVerbose(b);
+        ConnectionSSL::SetVerbose(b);
     }
 
