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