diff --git a/lib/netplay/error_categories.cpp b/lib/netplay/error_categories.cpp index 0b0683425b8..eb990de3c2f 100644 --- a/lib/netplay/error_categories.cpp +++ b/lib/netplay/error_categories.cpp @@ -98,13 +98,29 @@ std::error_condition GenericSystemErrorCategory::default_error_condition(int ev) return std::system_category().default_error_condition(ev); } +std::string GetaddrinfoErrorCategory::message(int ev) const +{ + return gai_strerror(ev); +} + const std::error_category& generic_system_error_category() { static GenericSystemErrorCategory instance; return instance; } +const std::error_category& getaddrinfo_error_category() +{ + static GetaddrinfoErrorCategory instance; + return instance; +} + std::error_code make_network_error_code(int ev) { return { ev, generic_system_error_category() }; } + +std::error_code make_getaddrinfo_error_code(int ev) +{ + return { ev, getaddrinfo_error_category() }; +} diff --git a/lib/netplay/error_categories.h b/lib/netplay/error_categories.h index a266fcfd5e0..87a3fd20079 100644 --- a/lib/netplay/error_categories.h +++ b/lib/netplay/error_categories.h @@ -47,6 +47,26 @@ class GenericSystemErrorCategory : public std::error_category std::error_condition default_error_condition(int ev) const noexcept override; }; +/// +/// Custom error category which maps error codes from `getaddrinfo()` function to +/// the appropriate error messages. +/// +class GetaddrinfoErrorCategory : public std::error_category +{ +public: + + constexpr GetaddrinfoErrorCategory() = default; + + const char* name() const noexcept override + { + return "getaddrinfo"; + } + + std::string message(int ev) const override; +}; + const std::error_category& generic_system_error_category(); +const std::error_category& getaddrinfo_error_category(); std::error_code make_network_error_code(int ev); +std::error_code make_getaddrinfo_error_code(int ev);