idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
35#include <idfxx/error>
36
37#include <string>
38#include <system_error>
39#include <type_traits>
40#include <utility>
41
42namespace idfxx::net {
43
56enum class errc : esp_err_t {
57 // clang-format off
58 // ----- sockets -----
59 invalid_state = 1,
61 not_supported = 3,
62 timed_out = 4,
64 in_progress = 6,
65 interrupted = 7,
66 address_in_use = 8,
69 connection_reset = 11,
71 not_connected = 13,
73 host_unreachable = 15,
75 network_down = 17,
76 broken_pipe = 18,
77 message_too_long = 19,
79 name_resolution = 21,
80 name_not_found = 22,
81 name_temporary = 23,
82 name_no_data = 24,
83 io_error = 25,
85 unexpected_eof = 27,
87 // ----- netconn -----
89 netconn_routing = 29,
91 netconn_aborted = 31,
92 netconn_reset = 32,
93 netconn_closed = 33,
95 no_buffer_space = 34,
96 // clang-format on
97};
98
106class error_category : public std::error_category {
107public:
110
112 [[nodiscard]] std::string message(int ec) const override final;
113
135};
136
137} // namespace idfxx::net
138
140
148
149} // namespace idfxx
150
151namespace idfxx::net {
152
160[[nodiscard]] inline std::error_code make_error_code(errc e) noexcept {
161 return {std::to_underlying(e), net_category()};
162}
163
177[[nodiscard]] std::error_code errno_to_error_code(int errno_value) noexcept;
178
190[[nodiscard]] std::error_code lwip_err_to_error_code(int err_t_value) noexcept;
191
201[[nodiscard]] std::error_code gai_to_error_code(int gai) noexcept;
202
205} // namespace idfxx::net
206
208namespace std {
209template<>
210struct is_error_code_enum<idfxx::net::errc> : std::true_type {};
211} // namespace std
213
// end of idfxx_net_error
215
Error category for idfxx_net errors.
Definition error.hpp:106
std::error_condition default_error_condition(int code) const noexcept override final
Maps an errc value to its canonical portable condition.
const char * name() const noexcept override final
Returns the name of the error category.
std::string message(int ec) const override final
Returns a human-readable message for the given error code.
int esp_err_t
Definition error.hpp:35
errc
IP transport error codes.
Definition error.hpp:56
std::error_code make_error_code(errc e) noexcept
Creates an error code from an idfxx::net::errc value.
Definition error.hpp:160
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
const net::error_category & net_category() noexcept
Returns a reference to the idfxx_net error category singleton.