title: boost::asio with SSL - problems after SSL error
body: <p>I use synchronous boost::asio SSL sockets in my application. I initialize all parameters and then connect to some hosts (one after another) and do a GET request for each host.</p>
  
  <p>Everything works until I get a "404 - Not Found" error for one of the hosts. After this error, all new connections fail with some unspecified SSL error.</p>
  
  <p>Do I have to reset the ssl::stream somehow? Is it possible to re-initialize the ssl::stream after each connection?</p>
  
  <p>In the following code snippets I removed error handling and all non asio related things.</p>
  
  <p><strong>Main:</strong></p>
  
  <pre><code>asio::io_service ioservice;
  asio::ssl::context ctx(ioservice, asio::ssl::context::sslv23);
  ctx.set_verify_mode(asio::ssl::context::verify_none);
  
  Connector *con = new Connector(ioservice, ctx);
  
  while (!iplist.empty())
  {
      ...
      con-&gt;ssl_connect(ipaddress, port);
      ...
  }
  </code></pre>
  
  <p><strong>Connector:</strong></p>
  
  <pre><code>Connector::Connector(asio::io_service&amp; io_service, asio::ssl::context &amp;ctx) 
      : sslSock(io_service, ctx)
  {
  }
  
  Connector::ssl_connect(std::string ipAdr, std::string port)
  {
      ...
      tcp::resolver resolver(ioserv);
      tcp::resolver::query query(ipAdr, port);
      endpoint_iterator = resolver.resolve(query);
      ...
  
      asio::error_code errorcode = asio::error::host_not_found;
      tcp::resolver::iterator end;
  
      // Establish connection
      while (errorcode &amp;&amp; endpoint_iterator != end)
      {
          sslSock.lowest_layer().close();
          sslSock.lowest_layer().connect(*endpoint_iterator++, errorcode);
      }
      sslSock.handshake(asio::ssl::stream_base::client, errorcode);
      ...
      asio::write(...);
      ...
      asio::read(...);
      ...
      sslSock.lowest_layer().close();
      ...
      return;
  }
  </code></pre>