title: How to detect when a boost tcp socket disconnects
body: <p>Suppose I have a socket:</p>
  
  <pre><code>std::shared_ptr&lt;tcp::socket&gt; socket( new tcp::socket(acceptor.get_io_service()) );
  acceptor.async_accept( *socket, std::bind( handleAccept, this, std::placeholders::_1, socket, std::ref(acceptor)) );
  </code></pre>
  
  <p>And I store a weak_ptr to the said socket in a container. I need this because I want to allow clients to request for a list of other clients, so they can send messages to each other.</p>
  
  <pre><code>clients_.insert(socket);  // pseudocode
  </code></pre>
  
  <p>Then I run some async operations</p>
  
  <pre><code>socket-&gt;async_receive( boost::asio::buffer(&amp;(*header), sizeof(Header))
      , 0
      , std::bind(handleReceiveHeader, this, std::placeholders::_1, std::placeholders::_2, header, socket));
  </code></pre>
  
  <p>How do I detect when the connection is closed so I can remove my socket from the container?</p>
  
  <pre><code>clients_.erase(socket); // pseudocode
  </code></pre>