error.ipp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_IMPL_ERROR_IPP
  10. #define BOOST_BEAST_IMPL_ERROR_IPP
  11. #include <boost/beast/core/error.hpp>
  12. namespace boost {
  13. namespace beast {
  14. namespace detail {
  15. class error_codes : public error_category
  16. {
  17. public:
  18. const char*
  19. name() const noexcept override
  20. {
  21. return "boost.beast";
  22. }
  23. error_codes() : error_category(0x002f6e94401c6e8bu) {}
  24. BOOST_BEAST_DECL
  25. char const*
  26. message(int ev, char*, std::size_t) const noexcept override
  27. {
  28. switch(static_cast<error>(ev))
  29. {
  30. default:
  31. case error::timeout: return
  32. "The socket was closed due to a timeout";
  33. }
  34. }
  35. BOOST_BEAST_DECL
  36. std::string
  37. message(int ev) const override
  38. {
  39. return message(ev, nullptr, 0);
  40. }
  41. BOOST_BEAST_DECL
  42. error_condition
  43. default_error_condition(int ev) const noexcept override
  44. {
  45. switch(static_cast<error>(ev))
  46. {
  47. default:
  48. // return {ev, *this};
  49. case error::timeout:
  50. return condition::timeout;
  51. }
  52. }
  53. };
  54. class error_conditions : public error_category
  55. {
  56. public:
  57. BOOST_BEAST_DECL
  58. const char*
  59. name() const noexcept override
  60. {
  61. return "boost.beast";
  62. }
  63. error_conditions() : error_category(0x3dd0b0ce843c5b10u) {}
  64. BOOST_BEAST_DECL
  65. char const*
  66. message(int cv, char*, std::size_t) const noexcept override
  67. {
  68. switch(static_cast<condition>(cv))
  69. {
  70. default:
  71. case condition::timeout:
  72. return "The operation timed out";
  73. }
  74. }
  75. BOOST_BEAST_DECL
  76. std::string
  77. message(int cv) const override
  78. {
  79. return message(cv, nullptr, 0);
  80. }
  81. };
  82. } // detail
  83. error_code
  84. make_error_code(error e)
  85. {
  86. static detail::error_codes const cat{};
  87. return error_code{static_cast<
  88. std::underlying_type<error>::type>(e), cat};
  89. }
  90. error_condition
  91. make_error_condition(condition c)
  92. {
  93. static detail::error_conditions const cat{};
  94. return error_condition{static_cast<
  95. std::underlying_type<condition>::type>(c), cat};
  96. }
  97. } // beast
  98. } // boost
  99. #endif