error.ipp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // ssl/impl/error.ipp
  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_IMPL_ERROR_IPP
  11. #define BOOST_ASIO_SSL_IMPL_ERROR_IPP
  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/asio/ssl/error.hpp>
  17. #include <boost/asio/ssl/detail/openssl_init.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace error {
  22. namespace detail {
  23. class ssl_category : public boost::system::error_category
  24. {
  25. public:
  26. const char* name() const BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT
  27. {
  28. return "asio.ssl";
  29. }
  30. std::string message(int value) const
  31. {
  32. const char* s = ::ERR_reason_error_string(value);
  33. return s ? s : "asio.ssl error";
  34. }
  35. };
  36. } // namespace detail
  37. const boost::system::error_category& get_ssl_category()
  38. {
  39. static detail::ssl_category instance;
  40. return instance;
  41. }
  42. } // namespace error
  43. namespace ssl {
  44. namespace error {
  45. #if (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL)
  46. const boost::system::error_category& get_stream_category()
  47. {
  48. return boost::asio::error::get_ssl_category();
  49. }
  50. #else
  51. namespace detail {
  52. class stream_category : public boost::system::error_category
  53. {
  54. public:
  55. const char* name() const BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT
  56. {
  57. return "asio.ssl.stream";
  58. }
  59. std::string message(int value) const
  60. {
  61. switch (value)
  62. {
  63. case stream_truncated: return "stream truncated";
  64. case unspecified_system_error: return "unspecified system error";
  65. case unexpected_result: return "unexpected result";
  66. default: return "asio.ssl.stream error";
  67. }
  68. }
  69. };
  70. } // namespace detail
  71. const boost::system::error_category& get_stream_category()
  72. {
  73. static detail::stream_category instance;
  74. return instance;
  75. }
  76. #endif
  77. } // namespace error
  78. } // namespace ssl
  79. } // namespace asio
  80. } // namespace boost
  81. #include <boost/asio/detail/pop_options.hpp>
  82. #endif // BOOST_ASIO_SSL_IMPL_ERROR_IPP