Timmmm February 2016

What does boost::asio::ssl::stream<boost::asio::ip::tcp::socket>::shutdown() do?

The extensive documentation helpfully says:

This function is used to shut down SSL on the stream. The function call will block until SSL has been shut down or an error occurs.

Which leaves me with these questions:

  1. Does this close the actual connection too?
  2. If not, how do I do that?
  3. Can I reuse the stream by calling boost::asio::connect(theSocket.lowest_layer(), ... again?

Answers


Richard Hodges February 2016

Under the covers, asio calls SSL_Shutdown() in the underlying OpenSSL library:

The documentation for which is here:

https://www.openssl.org/docs/manmaster/ssl/SSL_shutdown.html

... and contains the following ominous text:

The behaviour of SSL_shutdown() additionally depends on the underlying BIO.

However, my understanding of things is that the ssl::stream object is not a socket (by design) but more like a protocol layer that sits on top of a Stream-like object. Thus the asio::ssl layer has no knowledge of its next_layer() other than that it must support the free functions read,write, async_read and async_write. Certainly no knowledge about whether the layer supports the concept of shutdown() (or even close()).

Therefore I would expect the underlying socket, given by lowest_layer() to still be open when shutdown() returns. Furthermore, I would expect that shutdown() will not have been called on the lowest_layer(). You'll want to do this after ssl::shutdown returns, or in the handler passed to ssl::async_shutdown

Post Status

Asked in February 2016
Viewed 3,735 times
Voted 4
Answered 1 times

Search




Leave an answer