error.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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) && !defined(OPENSSL_IS_BORINGSSL)
  47. stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ),
  48. # else
  49. stream_truncated = 1,
  50. # endif
  51. unspecified_system_error = 2,
  52. unexpected_result = 3
  53. #endif // defined(GENERATING_DOCUMENTATION)
  54. };
  55. extern BOOST_ASIO_DECL
  56. const boost::system::error_category& get_stream_category();
  57. static const boost::system::error_category&
  58. stream_category BOOST_ASIO_UNUSED_VARIABLE
  59. = boost::asio::ssl::error::get_stream_category();
  60. } // namespace error
  61. } // namespace ssl
  62. } // namespace asio
  63. } // namespace boost
  64. namespace boost {
  65. namespace system {
  66. template<> struct is_error_code_enum<boost::asio::error::ssl_errors>
  67. {
  68. static const bool value = true;
  69. };
  70. template<> struct is_error_code_enum<boost::asio::ssl::error::stream_errors>
  71. {
  72. static const bool value = true;
  73. };
  74. } // namespace system
  75. } // namespace boost
  76. namespace boost {
  77. namespace asio {
  78. namespace error {
  79. inline boost::system::error_code make_error_code(ssl_errors e)
  80. {
  81. return boost::system::error_code(
  82. static_cast<int>(e), get_ssl_category());
  83. }
  84. } // namespace error
  85. namespace ssl {
  86. namespace error {
  87. inline boost::system::error_code make_error_code(stream_errors e)
  88. {
  89. return boost::system::error_code(
  90. static_cast<int>(e), get_stream_category());
  91. }
  92. } // namespace error
  93. } // namespace ssl
  94. } // namespace asio
  95. } // namespace boost
  96. #include <boost/asio/detail/pop_options.hpp>
  97. #if defined(BOOST_ASIO_HEADER_ONLY)
  98. # include <boost/asio/ssl/impl/error.ipp>
  99. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  100. #endif // BOOST_ASIO_SSL_ERROR_HPP