]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/websocket/impl/error.ipp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / beast / websocket / impl / error.ipp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 #ifndef BOOST_BEAST_WEBSOCKET_IMPL_ERROR_IPP
11 #define BOOST_BEAST_WEBSOCKET_IMPL_ERROR_IPP
12
13 namespace boost {
14
15 namespace system {
16 template<>
17 struct is_error_code_enum<beast::websocket::error>
18 {
19 static bool const value = true;
20 };
21 } // system
22
23 namespace beast {
24 namespace websocket {
25 namespace detail {
26
27 class websocket_error_category : public error_category
28 {
29 public:
30 const char*
31 name() const noexcept override
32 {
33 return "boost.beast.websocket";
34 }
35
36 std::string
37 message(int ev) const override
38 {
39 switch(static_cast<error>(ev))
40 {
41 default:
42 case error::failed: return "WebSocket connection failed due to a protocol violation";
43 case error::closed: return "WebSocket connection closed normally";
44 case error::handshake_failed: return "WebSocket upgrade handshake failed";
45 case error::buffer_overflow: return "WebSocket dynamic buffer overflow";
46 case error::partial_deflate_block: return "WebSocket partial deflate block";
47 }
48 }
49
50 error_condition
51 default_error_condition(int ev) const noexcept override
52 {
53 return error_condition(ev, *this);
54 }
55
56 bool
57 equivalent(int ev,
58 error_condition const& condition
59 ) const noexcept override
60 {
61 return condition.value() == ev &&
62 &condition.category() == this;
63 }
64
65 bool
66 equivalent(error_code const& error, int ev) const noexcept override
67 {
68 return error.value() == ev &&
69 &error.category() == this;
70 }
71 };
72
73 inline
74 error_category const&
75 get_error_category()
76 {
77 static detail::websocket_error_category const cat{};
78 return cat;
79 }
80
81 } // detail
82
83 inline
84 error_code
85 make_error_code(error e)
86 {
87 return error_code(
88 static_cast<std::underlying_type<error>::type>(e),
89 detail::get_error_category());
90 }
91
92 } // websocket
93 } // beast
94 } // boost
95
96 #endif