error.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // ssl/error.hpp
  3. // ~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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. #elif (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL)
  40. stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)
  41. #else
  42. stream_truncated = 1
  43. #endif
  44. };
  45. extern BOOST_ASIO_DECL
  46. const boost::system::error_category& get_stream_category();
  47. static const boost::system::error_category&
  48. stream_category BOOST_ASIO_UNUSED_VARIABLE
  49. = boost::asio::ssl::error::get_stream_category();
  50. } // namespace error
  51. } // namespace ssl
  52. } // namespace asio
  53. } // namespace boost
  54. namespace boost {
  55. namespace system {
  56. template<> struct is_error_code_enum<boost::asio::error::ssl_errors>
  57. {
  58. static const bool value = true;
  59. };
  60. template<> struct is_error_code_enum<boost::asio::ssl::error::stream_errors>
  61. {
  62. static const bool value = true;
  63. };
  64. } // namespace system
  65. } // namespace boost
  66. namespace boost {
  67. namespace asio {
  68. namespace error {
  69. inline boost::system::error_code make_error_code(ssl_errors e)
  70. {
  71. return boost::system::error_code(
  72. static_cast<int>(e), get_ssl_category());
  73. }
  74. } // namespace error
  75. namespace ssl {
  76. namespace error {
  77. inline boost::system::error_code make_error_code(stream_errors e)
  78. {
  79. return boost::system::error_code(
  80. static_cast<int>(e), get_stream_category());
  81. }
  82. } // namespace error
  83. } // namespace ssl
  84. } // namespace asio
  85. } // namespace boost
  86. #include <boost/asio/detail/pop_options.hpp>
  87. #if defined(BOOST_ASIO_HEADER_ONLY)
  88. # include <boost/asio/ssl/impl/error.ipp>
  89. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  90. #endif // BOOST_ASIO_SSL_ERROR_HPP