Chops Net IP
Loading...
Searching...
No Matches
net_ip_error.hpp
Go to the documentation of this file.
1
20#ifndef NET_IP_ERROR_HPP_INCLUDED
21#define NET_IP_ERROR_HPP_INCLUDED
22
23#include <stdexcept>
24#include <system_error>
25#include <string>
26
27namespace chops {
28namespace net {
29
30enum class net_ip_errc {
31 weak_ptr_expired = 1,
32 message_handler_terminated = 2,
33
34 io_already_started = 4,
35 io_already_stopped = 5,
36 tcp_io_handler_stopped = 6,
37 udp_io_handler_stopped = 7,
38
39 net_entity_already_started = 8,
40 net_entity_already_stopped = 9,
41
42 tcp_acceptor_stopped = 10,
43 tcp_acceptor_closed = 11,
44 udp_entity_stopped = 12,
45 udp_entity_closed = 13,
46
47 tcp_connector_stopped = 14,
48 tcp_connector_closed = 15,
49 tcp_connector_resolving_addresses = 16,
50 tcp_connector_connecting = 17,
51 tcp_connector_connected = 18,
52 tcp_connector_timeout = 19,
53 tcp_connector_no_reconnect_attempted = 20,
54
55 functor_variant_mismatch = 30,
56};
57
58namespace detail {
59
60struct net_ip_err_category : public std::error_category {
61 virtual const char *name() const noexcept override {
62 return "net_ip_err_category";
63 }
64 virtual std::string message(int val) const override {
65 switch (net_ip_errc(val)) {
66 case net_ip_errc::weak_ptr_expired:
67 return "weak pointer expired";
68 case net_ip_errc::message_handler_terminated:
69 return "message handler terminated via false return value";
70
71 case net_ip_errc::io_already_started:
72 return "io already started";
73 case net_ip_errc::io_already_stopped:
74 return "io already stopped";
75 case net_ip_errc::tcp_io_handler_stopped:
76 return "tcp io handler stopped";
77 case net_ip_errc::udp_io_handler_stopped:
78 return "udp io handler stopped";
79
80 case net_ip_errc::net_entity_already_started:
81 return "net entity already started";
82 case net_ip_errc::net_entity_already_stopped:
83 return "net entity already stopped or never started";
84
85 case net_ip_errc::tcp_acceptor_stopped:
86 return "tcp acceptor stopped";
87 case net_ip_errc::tcp_acceptor_closed:
88 return "tcp acceptor closed";
89 case net_ip_errc::udp_entity_stopped:
90 return "udp entity stopped";
91 case net_ip_errc::udp_entity_closed:
92 return "udp entity closed";
93
94 case net_ip_errc::tcp_connector_stopped:
95 return "tcp connector stopped";
96 case net_ip_errc::tcp_connector_closed:
97 return "tcp connector closed";
98 case net_ip_errc::tcp_connector_resolving_addresses:
99 return "tcp connector resolving addresses";
100 case net_ip_errc::tcp_connector_connecting:
101 return "tcp connector connecting";
102 case net_ip_errc::tcp_connector_connected:
103 return "tcp connector connected";
104 case net_ip_errc::tcp_connector_timeout:
105 return "tcp connector timeout";
106 case net_ip_errc::tcp_connector_no_reconnect_attempted:
107 return "tcp connector no reconnect attempted";
108
109 case net_ip_errc::functor_variant_mismatch:
110 return "function object does not match internal variant";
111 }
112 return "(unknown error)";
113 }
114};
115
116} // end detail namespace
117
118inline const detail::net_ip_err_category& get_err_category() {
120 return e;
121}
122
123} // end net namespace
124} // end chops namespace
125
126namespace std {
127
128template <>
129 struct is_error_code_enum<chops::net::net_ip_errc> : true_type {};
130
131inline error_code make_error_code(chops::net::net_ip_errc e) noexcept {
132 return error_code (static_cast<int>(e), chops::net::get_err_category());
133}
134
135}
136
137namespace chops {
138namespace net {
139
140
141
145class net_ip_exception : public std::runtime_error {
146public:
147 net_ip_exception (const std::error_code& e) :
148 std::runtime_error("net_ip lib exception"), err(e) { }
149
150 std::error_code err;
151};
152
153} // end net namespace
154} // end chops namespace
155
156
157#endif
158
General net_ip exception class.
Definition net_ip_error.hpp:145
Definition net_ip_error.hpp:60