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 503b8bb commit 7249bcc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions asio/include/asio/ssl/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,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 ASIO_DECL
Expand Down
12 changes: 12 additions & 0 deletions asio/include/asio/ssl/impl/error.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ const asio::error_category& get_ssl_category()
} // namespace error
namespace ssl {
namespace error {

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

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

#else

namespace detail {

class stream_category : public asio::error_category
Expand Down Expand Up @@ -79,6 +89,8 @@ const asio::error_category& get_stream_category()
return instance;
}

#endif

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

0 comments on commit 7249bcc

Please # to comment.