chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.93k stars 1.22k forks source link

ssl::stream returns stream_truncated on reads now? #212

Open vinniefalco opened 7 years ago

vinniefalco commented 7 years ago

I'm on OpenSSL 1.0.2k (Jan 26, 2017) and Boost.Asio 1.64.0

When the remote host closes an SSL stream I get this error stream_truncated is that new? How do I properly detect graceful closure?

ljluestc commented 9 months ago

void handle_read(const boost::system::error_code& error, size_t bytes_transferred)
{
    if (!error) {
        // Process the data
    } else if (error == boost::asio::error::eof) {
        // Handle graceful closure
        try {
            ssl_stream.shutdown();
        } catch (const boost::system::system_error& e) {
            if (e.code() != boost::asio::ssl::error::stream_truncated) {
                // Handle unexpected error during shutdown
            }
            // Graceful closure with stream_truncated can be considered normal
        }
    } else {
        // Handle other errors
    }
}