face: When there are no more events to process, pausing transport instead of closing it

Change-Id: I12ad55c6ef3b6b3fce4a5b3c679eb0c6dc3cfa07
Refs: #1314
diff --git a/src/transport/stream-transport.hpp b/src/transport/stream-transport.hpp
index f98b988..2ab4752 100644
--- a/src/transport/stream-transport.hpp
+++ b/src/transport/stream-transport.hpp
@@ -38,10 +38,7 @@
 
     if (!error)
       {
-        m_partialDataSize = 0;
-        m_socket.async_receive(boost::asio::buffer(m_inputBuffer, MAX_LENGTH), 0,
-                               bind(&impl::handle_async_receive, this, _1, _2));
-
+        resume();
         m_transport.m_isConnected = true;
 
         for (std::list<Block>::iterator i = m_sendQueue.begin(); i != m_sendQueue.end(); ++i)
@@ -111,6 +108,28 @@
   }
 
   void
+  pause()
+  {
+    if (m_transport.m_isExpectingData)
+      {
+        m_transport.m_isExpectingData = false;
+        m_socket.cancel();
+      }
+  }
+
+  void
+  resume()
+  {
+    if (!m_transport.m_isExpectingData)
+      {
+        m_transport.m_isExpectingData = true;
+        m_partialDataSize = 0;
+        m_socket.async_receive(boost::asio::buffer(m_inputBuffer, MAX_LENGTH), 0,
+                               bind(&impl::handle_async_receive, this, _1, _2));
+      }
+  }
+
+  void
   send(const Block& wire)
   {
     if (!m_transport.m_isConnected)