transport: Fixing regression with TCP transport

Integrated test TestFaces/Tcp was failing before this commit.

Change-Id: Ib08a1f27435d32d295b7818eefaef4e841f29295
diff --git a/src/transport/stream-transport.hpp b/src/transport/stream-transport.hpp
index 8721ae7..ca1ce9a 100644
--- a/src/transport/stream-transport.hpp
+++ b/src/transport/stream-transport.hpp
@@ -83,6 +83,7 @@
     m_connectionInProgress = false;
     m_transport.m_isConnected = false;
     m_transport.m_isExpectingData = false;
+    m_socket.cancel();
     m_socket.close();
     throw Transport::Error(error, "error while connecting to the forwarder");
   }
@@ -107,8 +108,11 @@
   void
   close()
   {
-    m_connectTimer.cancel();
-    m_socket.close();
+    boost::system::error_code error; // to silently ignore all errors
+    m_connectTimer.cancel(error);
+    m_socket.cancel(error);
+    m_socket.close(error);
+
     m_transport.m_isConnected = false;
     m_transport.m_isExpectingData = false;
     m_sendQueue.clear();
@@ -118,6 +122,9 @@
   void
   pause()
   {
+    if (m_connectionInProgress)
+      return;
+
     if (m_transport.m_isExpectingData)
       {
         m_transport.m_isExpectingData = false;
@@ -128,6 +135,9 @@
   void
   resume()
   {
+    if (m_connectionInProgress)
+      return;
+
     if (!m_transport.m_isExpectingData)
       {
         m_transport.m_isExpectingData = true;
@@ -192,8 +202,11 @@
           return;
         }
 
-        m_socket.close(); // closing at this point may not be that necessary
+        boost::system::error_code error; // to silently ignore all errors
+        m_socket.cancel(error);
+        m_socket.close(error); // closing at this point may not be that necessary
         m_transport.m_isConnected = true;
+        m_transport.m_isExpectingData = false;
         throw Transport::Error(error, "error while receiving data from socket");
       }
 
@@ -205,7 +218,9 @@
     if (!ok && m_inputBufferSize == MAX_LENGTH && offset == 0)
       {
         // very bad... should close connection
-        m_socket.close();
+        boost::system::error_code error; // to silently ignore all errors
+        m_socket.cancel(error);
+        m_socket.close(error);
         m_transport.m_isConnected = false;
         m_transport.m_isExpectingData = false;
         throw Transport::Error(boost::system::error_code(),