error.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // ssl/error.hpp
  3. // ~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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 ASIO_SSL_ERROR_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #include "asio/error_code.hpp"
  17. #include "asio/ssl/detail/openssl_types.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace error {
  21. enum ssl_errors
  22. {
  23. // Error numbers are those produced by openssl.
  24. };
  25. extern ASIO_DECL
  26. const asio::error_category& get_ssl_category();
  27. static const asio::error_category&
  28. ssl_category ASIO_UNUSED_VARIABLE
  29. = asio::error::get_ssl_category();
  30. } // namespace error
  31. namespace ssl {
  32. namespace error {
  33. enum stream_errors
  34. {
  35. #if defined(GENERATING_DOCUMENTATION)
  36. /// The underlying stream closed before the ssl stream gracefully shut down.
  37. stream_truncated,
  38. /// The underlying SSL library returned a system error without providing
  39. /// further information.
  40. unspecified_system_error,
  41. /// The underlying SSL library generated an unexpected result from a function
  42. /// call.
  43. unexpected_result
  44. #else // defined(GENERATING_DOCUMENTATION)
  45. # if (OPENSSL_VERSION_NUMBER < 0x10100000L) \
  46. && !defined(OPENSSL_IS_BORINGSSL) \
  47. && !defined(ASIO_USE_WOLFSSL)
  48. stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ),
  49. # else
  50. stream_truncated = 1,
  51. # endif
  52. unspecified_system_error = 2,
  53. unexpected_result = 3
  54. #endif // defined(GENERATING_DOCUMENTATION)
  55. };
  56. extern ASIO_DECL
  57. const asio::error_category& get_stream_category();
  58. static const asio::error_category&
  59. stream_category ASIO_UNUSED_VARIABLE
  60. = asio::ssl::error::get_stream_category();
  61. } // namespace error
  62. } // namespace ssl
  63. } // namespace asio
  64. namespace std {
  65. template<> struct is_error_code_enum<asio::error::ssl_errors>
  66. {
  67. static const bool value = true;
  68. };
  69. template<> struct is_error_code_enum<asio::ssl::error::stream_errors>
  70. {
  71. static const bool value = true;
  72. };
  73. } // namespace std
  74. namespace asio {
  75. namespace error {
  76. inline asio::error_code make_error_code(ssl_errors e)
  77. {
  78. return asio::error_code(
  79. static_cast<int>(e), get_ssl_category());
  80. }
  81. } // namespace error
  82. namespace ssl {
  83. namespace error {
  84. inline asio::error_code make_error_code(stream_errors e)
  85. {
  86. return asio::error_code(
  87. static_cast<int>(e), get_stream_category());
  88. }
  89. } // namespace error
  90. } // namespace ssl
  91. } // namespace asio
  92. #include "asio/detail/pop_options.hpp"
  93. #if defined(ASIO_HEADER_ONLY)
  94. # include "asio/ssl/impl/error.ipp"
  95. #endif // defined(ASIO_HEADER_ONLY)
  96. #endif // ASIO_SSL_ERROR_HPP