Line data Source code
1 : //
2 : // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.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/cppalliance/capy
8 : //
9 :
10 : #ifndef BOOST_CAPY_ERROR_HPP
11 : #define BOOST_CAPY_ERROR_HPP
12 :
13 : #include <boost/capy/detail/config.hpp>
14 : #include <boost/system/error_category.hpp>
15 : #include <boost/system/is_error_code_enum.hpp>
16 :
17 : namespace boost {
18 : namespace capy {
19 :
20 : /** Error codes returned from algorithms and operations.
21 :
22 : Return `error::eof` when originating an eof error.
23 : Check `ec == cond::eof` for portable comparison.
24 :
25 : Return `error::canceled` when originating a cancellation error.
26 : Check `ec == cond::canceled` for portable comparison.
27 :
28 : Return `error::stream_truncated` when peer closes without TLS shutdown.
29 : Check `ec == cond::stream_truncated` for portable comparison.
30 : */
31 : enum class error
32 : {
33 : eof = 1,
34 : canceled,
35 : test_failure,
36 : stream_truncated
37 : };
38 :
39 : //-----------------------------------------------
40 :
41 : } // capy
42 :
43 : namespace system {
44 : template<>
45 : struct is_error_code_enum<
46 : ::boost::capy::error>
47 : {
48 : static bool const value = true;
49 : };
50 : } // system
51 :
52 : namespace capy {
53 :
54 : //-----------------------------------------------
55 :
56 : namespace detail {
57 :
58 : struct BOOST_SYMBOL_VISIBLE
59 : error_cat_type
60 : : system::error_category
61 : {
62 : BOOST_CAPY_DECL const char* name(
63 : ) const noexcept override;
64 : BOOST_CAPY_DECL std::string message(
65 : int) const override;
66 : BOOST_CAPY_DECL char const* message(
67 : int, char*, std::size_t
68 : ) const noexcept override;
69 : BOOST_SYSTEM_CONSTEXPR error_cat_type()
70 : : error_category(0x884562ca8e2fc5fd)
71 : {
72 : }
73 : };
74 :
75 : BOOST_CAPY_DECL extern error_cat_type error_cat;
76 :
77 : } // detail
78 :
79 : //-----------------------------------------------
80 :
81 : inline
82 : BOOST_SYSTEM_CONSTEXPR
83 : system::error_code
84 38 : make_error_code(
85 : error ev) noexcept
86 : {
87 : return system::error_code{
88 : static_cast<std::underlying_type<
89 : error>::type>(ev),
90 38 : detail::error_cat};
91 : }
92 :
93 : } // capy
94 : } // boost
95 :
96 : #endif
|