error.ipp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. BOOST_BEAST_DECL
  24. std::string
  25. message(int ev) const override
  26. {
  27. switch(static_cast<error>(ev))
  28. {
  29. default:
  30. case error::timeout: return
  31. "The socket was closed due to a timeout";
  32. }
  33. }
  34. BOOST_BEAST_DECL
  35. error_condition
  36. default_error_condition(int ev) const noexcept override
  37. {
  38. switch(static_cast<error>(ev))
  39. {
  40. default:
  41. // return {ev, *this};
  42. case error::timeout:
  43. return condition::timeout;
  44. }
  45. }
  46. };
  47. class error_conditions : public error_category
  48. {
  49. public:
  50. BOOST_BEAST_DECL
  51. const char*
  52. name() const noexcept override
  53. {
  54. return "boost.beast";
  55. }
  56. BOOST_BEAST_DECL
  57. std::string
  58. message(int cv) const override
  59. {
  60. switch(static_cast<condition>(cv))
  61. {
  62. default:
  63. case condition::timeout:
  64. return "The operation timed out";
  65. }
  66. }
  67. };
  68. } // detail
  69. error_code
  70. make_error_code(error e)
  71. {
  72. static detail::error_codes const cat{};
  73. return error_code{static_cast<
  74. std::underlying_type<error>::type>(e), cat};
  75. }
  76. error_condition
  77. make_error_condition(condition c)
  78. {
  79. static detail::error_conditions const cat{};
  80. return error_condition{static_cast<
  81. std::underlying_type<condition>::type>(c), cat};
  82. }
  83. } // beast
  84. } // boost
  85. #endif