This is more complicated. For the case of categories defined elsewhere, we have to convert everything here.
| 156 | // This is more complicated. For the case of categories defined |
| 157 | // elsewhere, we have to convert everything here. |
| 158 | [[nodiscard]] int from_error_code(boost::system::error_code e) noexcept |
| 159 | { |
| 160 | if (!e) |
| 161 | return 0; |
| 162 | |
| 163 | auto c = dynamic_cast<const converting_category*>(&e.category()); |
| 164 | // For categories we define |
| 165 | if (c) |
| 166 | return c->from_code(e.value()); |
| 167 | |
| 168 | // For categories matching values of errno |
| 169 | if (e.category() == boost::system::system_category() || |
| 170 | e.category() == boost::system::generic_category() || |
| 171 | // ASIO uses the system category for these and matches system |
| 172 | // error values. |
| 173 | e.category() == boost::asio::error::get_netdb_category() || |
| 174 | e.category() == boost::asio::error::get_addrinfo_category()) |
| 175 | return -e.value(); |
| 176 | |
| 177 | if (e.category() == boost::asio::error::get_misc_category()) { |
| 178 | // These values are specific to asio |
| 179 | switch (e.value()) { |
| 180 | case boost::asio::error::already_open: |
| 181 | return -EIO; |
| 182 | case boost::asio::error::eof: |
| 183 | return -EIO; |
| 184 | case boost::asio::error::not_found: |
| 185 | return -ENOENT; |
| 186 | case boost::asio::error::fd_set_failure: |
| 187 | return -EINVAL; |
| 188 | } |
| 189 | } |
| 190 | // Add any other categories we use here. |
| 191 | |
| 192 | // So many things defautl to EIO this is probably the safest |
| 193 | return -EIO; |
| 194 | } |
| 195 | } |
| 196 | #pragma GCC diagnostic pop |
| 197 | #pragma clang diagnostic pop |
no test coverage detected