LCOV - code coverage report
Current view: top level - capy - cond.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 3 3
Test Date: 2026-08-21 22:12:46 Functions: 100.0 % 1 1

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

Generated by: LCOV version 2.3