error.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // ssl/error.hpp
  3. // ~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_SSL_ERROR_HPP
  11. #define BOOST_ASIO_SSL_ERROR_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/system/error_code.hpp>
  17. #include <boost/asio/ssl/detail/openssl_types.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace error {
  22. enum ssl_errors
  23. {
  24. // Error numbers are those produced by openssl.
  25. };
  26. extern BOOST_ASIO_DECL
  27. const boost::system::error_category& get_ssl_category();
  28. static const boost::system::error_category&
  29. ssl_category BOOST_ASIO_UNUSED_VARIABLE
  30. = boost::asio::error::get_ssl_category();
  31. } // namespace error
  32. namespace ssl {
  33. namespace error {
  34. enum stream_errors
  35. {
  36. #if defined(GENERATING_DOCUMENTATION)
  37. /// The underlying stream closed before the ssl stream gracefully shut down.
  38. stream_truncated,
  39. /// The underlying SSL library returned a system error without providing
  40. /// further information.
  41. unspecified_system_error,
  42. /// The underlying SSL library generated an unexpected result from a function
  43. /// call.
  44. unexpected_result
  45. #else // defined(GENERATING_DOCUMENTATION)
  46. # if (OPENSSL_VERSION_NUMBER < 0x10100000L) \
  47. && !defined(OPENSSL_IS_BORINGSSL) \
  48. && !defined(BOOST_ASIO_USE_WOLFSSL)
  49. stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ),
  50. # else
  51. stream_truncated = 1,
  52. # endif
  53. unspecified_system_error = 2,
  54. unexpected_result = 3
  55. #endif // defined(GENERATING_DOCUMENTATION)
  56. };
  57. extern BOOST_ASIO_DECL
  58. const boost::system::error_category& get_stream_category();
  59. static const boost::system::error_category&
  60. stream_category BOOST_ASIO_UNUSED_VARIABLE
  61. = boost::asio::ssl::error::get_stream_category();
  62. } // namespace error
  63. } // namespace ssl
  64. } // namespace asio
  65. } // namespace boost
  66. namespace boost {
  67. namespace system {
  68. template<> struct is_error_code_enum<boost::asio::error::ssl_errors>
  69. {
  70. static const bool value = true;
  71. };
  72. template<> struct is_error_code_enum<boost::asio::ssl::error::stream_errors>
  73. {
  74. static const bool value = true;
  75. };
  76. } // namespace system
  77. } // namespace boost
  78. namespace boost {
  79. namespace asio {
  80. namespace error {
  81. inline boost::system::error_code make_error_code(ssl_errors e)
  82. {
  83. return boost::system::error_code(
  84. static_cast<int>(e), get_ssl_category());
  85. }
  86. } // namespace error
  87. namespace ssl {
  88. namespace error {
  89. inline boost::system::error_code make_error_code(stream_errors e)
  90. {
  91. return boost::system::error_code(
  92. static_cast<int>(e), get_stream_category());
  93. }
  94. } // namespace error
  95. } // namespace ssl
  96. } // namespace asio
  97. } // namespace boost
  98. #include <boost/asio/detail/pop_options.hpp>
  99. #if defined(BOOST_ASIO_HEADER_ONLY)
  100. # include <boost/asio/ssl/impl/error.ipp>
  101. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  102. #endif // BOOST_ASIO_SSL_ERROR_HPP