include/boost/corosio/native/detail/make_err.hpp
87.5% Lines (7/8)
100.0% List of functions (1/1)
75.0% Branches (6/8)
Functions (1)
Function
Calls
Lines
Branches
Blocks
boost::corosio::detail::make_err(unsigned long)
:69
1910x
87.5%
75.0%
88.9%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2025 Vinnie Falco ([email protected]) | |||
| 3 | // Copyright (c) 2026 Steve Gerbino | |||
| 4 | // Copyright (c) 2026 Michael Vandeberg | |||
| 5 | // | |||
| 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||
| 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||
| 8 | // | |||
| 9 | // Official repository: https://github.com/cppalliance/corosio | |||
| 10 | // | |||
| 11 | ||||
| 12 | #ifndef BOOST_COROSIO_NATIVE_DETAIL_MAKE_ERR_HPP | |||
| 13 | #define BOOST_COROSIO_NATIVE_DETAIL_MAKE_ERR_HPP | |||
| 14 | ||||
| 15 | #include <boost/corosio/detail/config.hpp> | |||
| 16 | #include <boost/corosio/detail/platform.hpp> | |||
| 17 | #include <boost/capy/error.hpp> | |||
| 18 | #include <system_error> | |||
| 19 | ||||
| 20 | #if BOOST_COROSIO_POSIX | |||
| 21 | #include <errno.h> | |||
| 22 | #else | |||
| 23 | #ifndef WIN32_LEAN_AND_MEAN | |||
| 24 | #define WIN32_LEAN_AND_MEAN | |||
| 25 | #endif | |||
| 26 | #include <Windows.h> | |||
| 27 | #endif | |||
| 28 | ||||
| 29 | namespace boost::corosio::detail { | |||
| 30 | ||||
| 31 | #if BOOST_COROSIO_POSIX | |||
| 32 | ||||
| 33 | /** Convert a POSIX errno value to std::error_code. | |||
| 34 | ||||
| 35 | Maps ECANCELED to capy::error::canceled. | |||
| 36 | ||||
| 37 | @param errn The errno value. | |||
| 38 | @return The corresponding std::error_code. | |||
| 39 | */ | |||
| 40 | inline std::error_code | |||
| 41 | make_err(int errn) noexcept | |||
| 42 | { | |||
| 43 | if (errn == 0) | |||
| 44 | return {}; | |||
| 45 | ||||
| 46 | if (errn == ECANCELED) | |||
| 47 | return capy::error::canceled; | |||
| 48 | ||||
| 49 | return std::error_code(errn, std::system_category()); | |||
| 50 | } | |||
| 51 | ||||
| 52 | #else | |||
| 53 | ||||
| 54 | /** Convert a Windows error code to std::error_code. | |||
| 55 | ||||
| 56 | Maps ERROR_OPERATION_ABORTED and ERROR_CANCELLED to | |||
| 57 | capy::error::canceled, and ERROR_HANDLE_EOF to capy::error::eof. | |||
| 58 | Every other code passes through std::system_category(). | |||
| 59 | ||||
| 60 | ERROR_NETNAME_DELETED (64) is deliberately not mapped here: IOCP | |||
| 61 | delivers it both for a local closesocket() that cancels pending I/O | |||
| 62 | and for a remote RST, so it can only be disambiguated per operation | |||
| 63 | kind at the IOCP decode sites (see iocp_make_err in win_overlapped_op). | |||
| 64 | ||||
| 65 | @param dwError The Windows error code (DWORD). | |||
| 66 | @return The corresponding std::error_code. | |||
| 67 | */ | |||
| 68 | inline std::error_code | |||
| 69 | 1910x | make_err(unsigned long dwError) noexcept | ||
| 70 | { | |||
| 71 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 1910 times.
|
1910x | if (dwError == 0) | |
| 72 | ✗ | return {}; | ||
| 73 | ||||
| 74 |
3/4✓ Branch 4 → 5 taken 42 times.
✓ Branch 4 → 6 taken 1868 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 42 times.
|
1910x | if (dwError == ERROR_OPERATION_ABORTED || dwError == ERROR_CANCELLED) | |
| 75 | 1868x | return capy::error::canceled; | ||
| 76 | ||||
| 77 |
2/2✓ Branch 7 → 8 taken 3 times.
✓ Branch 7 → 9 taken 39 times.
|
42x | if (dwError == ERROR_HANDLE_EOF) | |
| 78 | 3x | return capy::error::eof; | ||
| 79 | ||||
| 80 | 39x | return std::error_code(static_cast<int>(dwError), std::system_category()); | ||
| 81 | } | |||
| 82 | ||||
| 83 | #endif | |||
| 84 | ||||
| 85 | } // namespace boost::corosio::detail | |||
| 86 | ||||
| 87 | #endif | |||
| 88 |