1//
2// Copyright (c) 2016-2019 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_IMPL_ERROR_IPP
11#define BOOST_BEAST_IMPL_ERROR_IPP
12
13#include <boost/beast/core/error.hpp>
14
15namespace boost {
16namespace beast {
17
18namespace detail {
19
20class error_codes : public error_category
21{
22public:
23 const char*
24 name() const noexcept override
25 {
26 return "boost.beast";
27 }
28
29 error_codes() : error_category(0x002f6e94401c6e8bu) {}
30
31 BOOST_BEAST_DECL
32 char const*
33 message(int ev, char*, std::size_t) const noexcept override
34 {
35 switch(static_cast<error>(ev))
36 {
37 default:
38 case error::timeout: return
39 "The socket was closed due to a timeout";
40 }
41 }
42
43 BOOST_BEAST_DECL
44 std::string
45 message(int ev) const override
46 {
47 return message(ev, nullptr, 0);
48 }
49
50 BOOST_BEAST_DECL
51 error_condition
52 default_error_condition(int ev) const noexcept override
53 {
54 switch(static_cast<error>(ev))
55 {
56 default:
57 // return {ev, *this};
58 case error::timeout:
59 return condition::timeout;
60 }
61 }
62};
63
64class error_conditions : public error_category
65{
66public:
67 BOOST_BEAST_DECL
68 const char*
69 name() const noexcept override
70 {
71 return "boost.beast";
72 }
73
74 error_conditions() : error_category(0x3dd0b0ce843c5b10u) {}
75
76 BOOST_BEAST_DECL
77 char const*
78 message(int cv, char*, std::size_t) const noexcept override
79 {
80 switch(static_cast<condition>(cv))
81 {
82 default:
83 case condition::timeout:
84 return "The operation timed out";
85 }
86 }
87
88 BOOST_BEAST_DECL
89 std::string
90 message(int cv) const override
91 {
92 return message(cv, nullptr, 0);
93 }
94};
95
96} // detail
97
98error_code
99make_error_code(error e)
100{
101 static detail::error_codes const cat{};
102 return error_code{static_cast<
103 std::underlying_type<error>::type>(e), cat};
104}
105
106error_condition
107make_error_condition(condition c)
108{
109 static detail::error_conditions const cat{};
110 return error_condition{static_cast<
111 std::underlying_type<condition>::type>(c), cat};
112}
113
114} // beast
115} // boost
116
117#endif
118

source code of boost/libs/beast/include/boost/beast/core/impl/error.ipp