5 #ifndef PACKIO_ERROR_CODE_H
6 #define PACKIO_ERROR_CODE_H
11 #include <type_traits>
13 #include "internal/config.h"
17 #if defined(PACKIO_STANDALONE_ASIO)
18 using error_code = std::error_code;
19 using system_error = std::system_error;
20 using error_category = std::error_category;
21 #else // defined(PACKIO_STANDALONE_ASIO)
22 using error_code = boost::system::error_code;
23 using system_error = boost::system::system_error;
24 using error_category = boost::system::error_category;
25 #endif // defined(PACKIO_STANDALONE_ASIO)
37 struct packio_error_category : error_category {
38 const char* name() const noexcept
override {
return "packio"; }
39 std::string message(
int ev)
const override
41 switch (
static_cast<error>(ev)) {
45 return "Error during call";
47 return "Unknown function";
53 return "Bad result type";
55 return "Unrecognized error";
60 inline error_code make_error_code(
error e)
62 static const packio_error_category category{};
63 return {
static_cast<std::underlying_type<error>::type
>(e), category};
68 #if defined(PACKIO_STANDALONE_ASIO)
74 #else // defined(PACKIO_STANDALONE_ASIO)
75 namespace boost::system {
80 #endif // defined(PACKIO_STANDALONE_ASIO)
82 #endif // PACKIO_ERROR_CODE_H