66.67% Lines (4/6) 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 Steve Gerbino 3   // Copyright (c) 2026 Steve Gerbino
  4 + // Copyright (c) 2026 Michael Vandeberg
4   // 5   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 6   // 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   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 8   //
8   // Official repository: https://github.com/cppalliance/corosio 9   // Official repository: https://github.com/cppalliance/corosio
9   // 10   //
10   11  
11   #ifndef BOOST_COROSIO_NATIVE_DETAIL_MAKE_ERR_HPP 12   #ifndef BOOST_COROSIO_NATIVE_DETAIL_MAKE_ERR_HPP
12   #define BOOST_COROSIO_NATIVE_DETAIL_MAKE_ERR_HPP 13   #define BOOST_COROSIO_NATIVE_DETAIL_MAKE_ERR_HPP
13   14  
14   #include <boost/corosio/detail/config.hpp> 15   #include <boost/corosio/detail/config.hpp>
15   #include <boost/corosio/detail/platform.hpp> 16   #include <boost/corosio/detail/platform.hpp>
16   #include <boost/capy/error.hpp> 17   #include <boost/capy/error.hpp>
17   #include <system_error> 18   #include <system_error>
18   19  
19   #if BOOST_COROSIO_POSIX 20   #if BOOST_COROSIO_POSIX
20   #include <errno.h> 21   #include <errno.h>
21   #else 22   #else
22   #ifndef WIN32_LEAN_AND_MEAN 23   #ifndef WIN32_LEAN_AND_MEAN
23   #define WIN32_LEAN_AND_MEAN 24   #define WIN32_LEAN_AND_MEAN
24   #endif 25   #endif
25   #include <Windows.h> 26   #include <Windows.h>
26   #endif 27   #endif
27   28  
28   namespace boost::corosio::detail { 29   namespace boost::corosio::detail {
29   30  
30   #if BOOST_COROSIO_POSIX 31   #if BOOST_COROSIO_POSIX
31   32  
32   /** Convert a POSIX errno value to std::error_code. 33   /** Convert a POSIX errno value to std::error_code.
33   34  
34   Maps ECANCELED to capy::error::canceled. 35   Maps ECANCELED to capy::error::canceled.
35   36  
36   @param errn The errno value. 37   @param errn The errno value.
37   @return The corresponding std::error_code. 38   @return The corresponding std::error_code.
38   */ 39   */
39   inline std::error_code 40   inline std::error_code
HITCBC 40   80 make_err(int errn) noexcept 41   88 make_err(int errn) noexcept
41   { 42   {
HITCBC 42   80 if (errn == 0) 43   88 if (errn == 0)
MISUBC 43   return {}; 44   return {};
44   45  
HITCBC 45   80 if (errn == ECANCELED) 46   88 if (errn == ECANCELED)
MISUBC 46   return capy::error::canceled; 47   return capy::error::canceled;
47   48  
HITCBC 48   80 return std::error_code(errn, std::system_category()); 49   88 return std::error_code(errn, std::system_category());
49   } 50   }
50   51  
51   #else 52   #else
52   53  
53   /** Convert a Windows error code to std::error_code. 54   /** Convert a Windows error code to std::error_code.
54   55  
55 - Maps ERROR_OPERATION_ABORTED, ERROR_CANCELLED, and 56 + Maps ERROR_OPERATION_ABORTED and ERROR_CANCELLED to
56 - ERROR_NETNAME_DELETED to capy::error::canceled. 57 + capy::error::canceled, and ERROR_HANDLE_EOF to capy::error::eof.
57 - Maps ERROR_HANDLE_EOF to capy::error::eof. 58 + Every other code passes through std::system_category().
58   59  
59 - ERROR_NETNAME_DELETED (64) is what IOCP actually delivers 60 + ERROR_NETNAME_DELETED (64) is deliberately not mapped here: IOCP
60 - when closesocket() cancels pending overlapped I/O, despite 61 + delivers it both for a local closesocket() that cancels pending I/O
61 - MSDN documenting ERROR_OPERATION_ABORTED for that case. 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).
62   64  
63   @param dwError The Windows error code (DWORD). 65   @param dwError The Windows error code (DWORD).
64   @return The corresponding std::error_code. 66   @return The corresponding std::error_code.
65   */ 67   */
66   inline std::error_code 68   inline std::error_code
67   make_err(unsigned long dwError) noexcept 69   make_err(unsigned long dwError) noexcept
68   { 70   {
69   if (dwError == 0) 71   if (dwError == 0)
70   return {}; 72   return {};
71   73  
72 - if (dwError == ERROR_OPERATION_ABORTED || dwError == ERROR_CANCELLED || 74 + if (dwError == ERROR_OPERATION_ABORTED || dwError == ERROR_CANCELLED)
73 - dwError == ERROR_NETNAME_DELETED)  
74   return capy::error::canceled; 75   return capy::error::canceled;
75   76  
76   if (dwError == ERROR_HANDLE_EOF) 77   if (dwError == ERROR_HANDLE_EOF)
77   return capy::error::eof; 78   return capy::error::eof;
78   79  
79   return std::error_code(static_cast<int>(dwError), std::system_category()); 80   return std::error_code(static_cast<int>(dwError), std::system_category());
80   } 81   }
81   82  
82   #endif 83   #endif
83   84  
84   } // namespace boost::corosio::detail 85   } // namespace boost::corosio::detail
85   86  
86   #endif 87   #endif