error.ipp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // impl/error.ipp
  3. // ~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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_IMPL_ERROR_IPP
  11. #define BOOST_ASIO_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 <string>
  17. #include <boost/asio/error.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace error {
  22. #if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
  23. namespace detail {
  24. class netdb_category : public boost::system::error_category
  25. {
  26. public:
  27. const char* name() const noexcept
  28. {
  29. return "asio.netdb";
  30. }
  31. std::string message(int value) const
  32. {
  33. if (value == error::host_not_found)
  34. return "Host not found (authoritative)";
  35. if (value == error::host_not_found_try_again)
  36. return "Host not found (non-authoritative), try again later";
  37. if (value == error::no_data)
  38. return "The query is valid, but it does not have associated data";
  39. if (value == error::no_recovery)
  40. return "A non-recoverable error occurred during database lookup";
  41. return "asio.netdb error";
  42. }
  43. };
  44. } // namespace detail
  45. const boost::system::error_category& get_netdb_category()
  46. {
  47. static detail::netdb_category instance;
  48. return instance;
  49. }
  50. namespace detail {
  51. class addrinfo_category : public boost::system::error_category
  52. {
  53. public:
  54. const char* name() const noexcept
  55. {
  56. return "asio.addrinfo";
  57. }
  58. std::string message(int value) const
  59. {
  60. if (value == error::service_not_found)
  61. return "Service not found";
  62. if (value == error::socket_type_not_supported)
  63. return "Socket type not supported";
  64. return "asio.addrinfo error";
  65. }
  66. };
  67. } // namespace detail
  68. const boost::system::error_category& get_addrinfo_category()
  69. {
  70. static detail::addrinfo_category instance;
  71. return instance;
  72. }
  73. #endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
  74. namespace detail {
  75. class misc_category : public boost::system::error_category
  76. {
  77. public:
  78. const char* name() const noexcept
  79. {
  80. return "asio.misc";
  81. }
  82. std::string message(int value) const
  83. {
  84. if (value == error::already_open)
  85. return "Already open";
  86. if (value == error::eof)
  87. return "End of file";
  88. if (value == error::not_found)
  89. return "Element not found";
  90. if (value == error::fd_set_failure)
  91. return "The descriptor does not fit into the select call's fd_set";
  92. return "asio.misc error";
  93. }
  94. };
  95. } // namespace detail
  96. const boost::system::error_category& get_misc_category()
  97. {
  98. static detail::misc_category instance;
  99. return instance;
  100. }
  101. } // namespace error
  102. } // namespace asio
  103. } // namespace boost
  104. #include <boost/asio/detail/pop_options.hpp>
  105. #endif // BOOST_ASIO_IMPL_ERROR_IPP