idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
connectionless_socket_base.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
7
8// Internal base class shared by `datagram_socket` and `raw_socket`. Adds the
9// per-message send/receive and disconnect operations that connectionless
10// sockets share. Stream sockets use the `ip_io_socket_base` API directly.
11
12#include "sdkconfig.h"
13
15#include <idfxx/net/endpoint>
16#include <idfxx/net/error>
17
18#include <cstddef>
19#include <span>
20
21namespace idfxx::net::detail {
22
23class connectionless_socket_base : public ip_io_socket_base {
24public:
27 using datagram = ::idfxx::net::datagram;
28
29#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
48 [[nodiscard]] std::span<std::byte> recv(std::span<std::byte> buf) { return idfxx::unwrap(try_recv(buf)); }
49#endif
50
65 [[nodiscard]] result<std::span<std::byte>> try_recv(std::span<std::byte> buf);
66
67#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
75#endif
76
82 result<void> try_disconnect();
83
84#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
97 size_t send_to(std::span<const std::byte> buf, const endpoint& to) { return idfxx::unwrap(try_send_to(buf, to)); }
98#endif
99
108 [[nodiscard]] result<size_t> try_send_to(std::span<const std::byte> buf, const endpoint& to);
109
110#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
121 [[nodiscard]] datagram recv_from(std::span<std::byte> buf) { return idfxx::unwrap(try_recv_from(buf)); }
122#endif
123
130 [[nodiscard]] result<datagram> try_recv_from(std::span<std::byte> buf);
131
132protected:
133 using ip_io_socket_base::ip_io_socket_base;
134};
135
136} // namespace idfxx::net::detail
137
result< void > try_disconnect()
Disconnects from the current access point.
void disconnect()
Disconnects from the current access point.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
Definition error.hpp:307
A datagram received together with the sender's endpoint.
Definition endpoint.hpp:228