Skip to content

Commit

Permalink
Backward compatibility for code using OpenSSL < 1.1.0.
Browse files Browse the repository at this point in the history
Some application code using asio::ssl::stream<> explicitly tests for the
SSL_R_SHORT_READ error. For compatibility, when using older versions of
OpenSSL we will define the ssl::error::stream_truncated to use this
value.
  • Loading branch information
chriskohlhoff committed Sep 11, 2016
1 parent 864ca38 commit 8ea3165
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/boost/asio/ssl/error.hpp
Expand Up @@ -41,8 +41,14 @@ namespace error {

enum stream_errors
{
#if defined(GENERATING_DOCUMENTATION)
/// The underlying stream closed before the ssl stream gracefully shut down.
stream_truncated
#elif (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL)
stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)
#else
stream_truncated = 1
#endif
};

extern BOOST_ASIO_DECL
Expand Down
12 changes: 12 additions & 0 deletions include/boost/asio/ssl/impl/error.ipp
Expand Up @@ -52,6 +52,16 @@ const boost::system::error_category& get_ssl_category()
} // namespace error
namespace ssl {
namespace error {

#if (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL)

const boost::system::error_category& get_stream_category()
{
return boost::asio::error::get_ssl_category();
}

#else

namespace detail {

class stream_category : public boost::system::error_category
Expand Down Expand Up @@ -80,6 +90,8 @@ const boost::system::error_category& get_stream_category()
return instance;
}

#endif

} // namespace error
} // namespace ssl
} // namespace asio
Expand Down

0 comments on commit 8ea3165

Please sign in to comment.