100.00% Lines (3/3) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
3   // Copyright (c) 2026 Michael Vandeberg 3   // Copyright (c) 2026 Michael Vandeberg
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 5   // Distributed under the Boost Software License, Version 1.0. (See accompanying
6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/cppalliance/capy 8   // Official repository: https://github.com/cppalliance/capy
9   // 9   //
10   10  
11   #ifndef BOOST_CAPY_COND_HPP 11   #ifndef BOOST_CAPY_COND_HPP
12   #define BOOST_CAPY_COND_HPP 12   #define BOOST_CAPY_COND_HPP
13   13  
14   #include <boost/capy/detail/config.hpp> 14   #include <boost/capy/detail/config.hpp>
15   #include <system_error> 15   #include <system_error>
16   16  
17   namespace boost { 17   namespace boost {
18   namespace capy { 18   namespace capy {
19   19  
20 - /** Portable error conditions for capy I/O operations. 20 + /** Group error codes from capy operations into portable conditions.
21   21  
22   These are the conditions callers should compare against when 22   These are the conditions callers should compare against when
23 - handling errors from capy operations. The @ref error enum values 23 + handling errors from capy operations. Capy @ref error values map
24 - map to these conditions, as do platform-specific error codes 24 + to these conditions. So does any code equivalent to
25 - (e.g., `ECANCELED`, SSL EOF errors). 25 + `std::errc::operation_canceled` (for example `ECANCELED`) or
  26 + `std::errc::timed_out`.
26   27  
27   @par Example 28   @par Example
28   29  
29   @par !example example 30   @par !example example
30   31  
31   32  
32   @see @ref error 33   @see @ref error
33   */ 34   */
34   enum class cond 35   enum class cond
35   { 36   {
36 - /** End-of-stream condition. 37 + /** Match codes that report the end of a stream.
37   38  
38   An `error_code` compares equal to `eof` when the stream 39   An `error_code` compares equal to `eof` when the stream
39   reached its natural end. Examples are a peer sending TCP 40   reached its natural end. Examples are a peer sending TCP
40   FIN, or a file reaching EOF. 41   FIN, or a file reaching EOF.
41   */ 42   */
42   eof = 1, 43   eof = 1,
43   44  
44 - /** Operation cancelled condition. 45 + /** Match codes that report a canceled operation.
45   46  
46   An `error_code` compares equal to `canceled` when the 47   An `error_code` compares equal to `canceled` when the
47   operation's stop token was activated, the I/O object's 48   operation's stop token was activated, the I/O object's
48   `cancel()` was called, or a platform cancellation error 49   `cancel()` was called, or a platform cancellation error
49   occurred. 50   occurred.
50   */ 51   */
51   canceled = 2, 52   canceled = 2,
52   53  
53 - /** Stream truncated condition. 54 + /** Match codes that report a truncated TLS stream.
54   55  
55   An `error_code` compares equal to `stream_truncated` when 56   An `error_code` compares equal to `stream_truncated` when
56   a TLS peer closed the connection without sending a proper 57   a TLS peer closed the connection without sending a proper
57   shutdown alert. 58   shutdown alert.
58   */ 59   */
59   stream_truncated = 3, 60   stream_truncated = 3,
60   61  
61 - /** Operation timed out condition. 62 + /** Match codes that report a timed-out operation.
62   63  
63   An `error_code` compares equal to `timeout` when an 64   An `error_code` compares equal to `timeout` when an
64 - operation exceeded its allowed duration. 65 + operation exceeded its allowed duration, or when it is
  66 + equivalent to `std::errc::timed_out`.
65   */ 67   */
66   timeout = 4 68   timeout = 4
67   }; 69   };
68   70  
69   } // capy 71   } // capy
70   } // boost 72   } // boost
71   73  
72   namespace std { 74   namespace std {
73   template<> 75   template<>
74   struct is_error_condition_enum< 76   struct is_error_condition_enum<
75   ::boost::capy::cond> 77   ::boost::capy::cond>
76   : std::true_type {}; 78   : std::true_type {};
77   } // std 79   } // std
78   80  
79   namespace boost { 81   namespace boost {
80   namespace capy { 82   namespace capy {
81   83  
82   namespace detail { 84   namespace detail {
83   85  
84   struct BOOST_CAPY_SYMBOL_VISIBLE 86   struct BOOST_CAPY_SYMBOL_VISIBLE
85   cond_cat_type 87   cond_cat_type
86   : std::error_category 88   : std::error_category
87   { 89   {
88   BOOST_CAPY_DECL const char* name( 90   BOOST_CAPY_DECL const char* name(
89   ) const noexcept override; 91   ) const noexcept override;
90   BOOST_CAPY_DECL std::string message( 92   BOOST_CAPY_DECL std::string message(
91   int) const override; 93   int) const override;
92   BOOST_CAPY_DECL bool equivalent( 94   BOOST_CAPY_DECL bool equivalent(
93   std::error_code const& ec, 95   std::error_code const& ec,
94   int condition) const noexcept override; 96   int condition) const noexcept override;
95   constexpr cond_cat_type() noexcept = default; 97   constexpr cond_cat_type() noexcept = default;
96   }; 98   };
97   99  
98   BOOST_CAPY_DECL extern cond_cat_type cond_cat; 100   BOOST_CAPY_DECL extern cond_cat_type cond_cat;
99   101  
100   } // detail 102   } // detail
101   103  
102   /** Create an error_condition from a cond value. 104   /** Create an error_condition from a cond value.
103   105  
104   @param ev The library condition value. 106   @param ev The library condition value.
105   107  
106   @return An `std::error_condition` holding `ev` in the library's 108   @return An `std::error_condition` holding `ev` in the library's
107   condition category. 109   condition category.
108   */ 110   */
109   inline 111   inline
110   std::error_condition 112   std::error_condition
HITCBC 111   741 make_error_condition( 113   799 make_error_condition(
112   cond ev) noexcept 114   cond ev) noexcept
113   { 115   {
HITCBC 114   741 return std::error_condition{ 116   799 return std::error_condition{
115   static_cast<std::underlying_type< 117   static_cast<std::underlying_type<
116   cond>::type>(ev), 118   cond>::type>(ev),
HITCBC 117   741 detail::cond_cat}; 119   799 detail::cond_cat};
118   } 120   }
119   121  
120   } // capy 122   } // capy
121   } // boost 123   } // boost
122   124  
123   #endif 125   #endif