-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror_code.cpp
63 lines (49 loc) · 1.01 KB
/
error_code.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "error_code.h"
#ifdef _WIN32
# include <ws2tcpip.h> // for gai_strerror
#else
# include <netdb.h> // for gai_strerror
#endif // _WIN32
#include <string> // for std::string
namespace {
struct gai_error_code
{
int error;
gai_error_code(int e) noexcept
: error(e)
{
}
};
struct gai_error_category : public std::error_category
{
char const *name() const noexcept override
{
return "GetAddrInfoError";
}
std::string message(int messageId) const override
{
return ::gai_strerror(messageId);
}
};
gai_error_category const &gai_category()
{
static gai_error_category const c;
return c;
}
std::error_code make_error_code(gai_error_code const &ge)
{
return std::error_code(ge.error, gai_category());
}
} // unnamed namespace
namespace std {
template<>
struct is_error_code_enum<gai_error_code> : std::true_type
{
};
} // namespace std
namespace sockpuppet {
std::error_code AddressError(int code)
{
return make_error_code(gai_error_code(code));
}
} // namespace sockpuppet