57 ove_sockaddr_ipv4(&addr.
raw, a, b, c, d,
port);
174 int err = ove_netif_init(&handle_, &storage_);
175 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
185 ove_netif_deinit(handle_);
191#ifdef CONFIG_OVE_ZERO_HEAP
201 other.handle_ =
nullptr;
211 if (
this != &other) {
213 ove_netif_deinit(handle_);
214 handle_ = other.handle_;
215 other.handle_ =
nullptr;
229 return from_rc(ove_netif_up(handle_, &cfg.raw));
254 ove_netif_down(handle_);
271 Address *netmask =
nullptr) noexcept
273 return from_rc(ove_netif_get_addr(handle_, ip ? &ip->raw :
nullptr,
274 gateway ? &gateway->raw :
nullptr,
275 netmask ? &netmask->raw :
nullptr));
284 return handle_ !=
nullptr;
297 ove_netif_t handle_{};
298 ove_netif_storage_t storage_{};
327 int err = ove_socket_open(&handle_, &storage_, OVE_AF_INET, OVE_SOCK_STREAM);
328 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
338 ove_socket_close(handle_);
344#ifdef CONFIG_OVE_ZERO_HEAP
353 : handle_(other.handle_), storage_(other.storage_), open_(other.open_)
355 other.handle_ =
nullptr;
366 if (
this != &other) {
368 ove_socket_close(handle_);
369 handle_ = other.handle_;
370 storage_ = other.storage_;
372 other.handle_ =
nullptr;
389 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
407 const int rc = ove_socket_send(handle_, data, len, &sent);
423 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
427 ove_socket_recv(handle_, buf, len, &received,
to_timeout_ns(timeout));
457 ove_socket_close(handle_);
488 TcpSocket(ove_socket_t h, ove_socket_storage_t s) : handle_(h), storage_(s), open_(true)
492 ove_socket_t handle_{};
493 ove_socket_storage_t storage_{};
517 int err = ove_socket_open(&handle_, &storage_, OVE_AF_INET, OVE_SOCK_DGRAM);
518 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
528 ove_socket_close(handle_);
534#ifdef CONFIG_OVE_ZERO_HEAP
543 : handle_(other.handle_), storage_(other.storage_), open_(other.open_)
545 other.handle_ =
nullptr;
556 if (
this != &other) {
558 ove_socket_close(handle_);
559 handle_ = other.handle_;
560 storage_ = other.storage_;
562 other.handle_ =
nullptr;
578 return from_rc(ove_socket_bind(handle_, &addr.raw));
594 const int rc = ove_socket_sendto(handle_, data, len, &sent, &dest.raw);
615 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
618 const int rc = ove_socket_recvfrom(handle_, buf, len, &received,
619 src ? &src->raw :
nullptr,
648 ove_socket_close(handle_);
672 ove_socket_t handle_{};
673 ove_socket_storage_t storage_{};
699 int err = ove_socket_open(&handle_, &storage_, OVE_AF_INET, OVE_SOCK_STREAM);
700 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
710 ove_socket_close(handle_);
716#ifdef CONFIG_OVE_ZERO_HEAP
725 : handle_(other.handle_), storage_(other.storage_), open_(other.open_)
727 other.handle_ =
nullptr;
738 if (
this != &other) {
740 ove_socket_close(handle_);
741 handle_ = other.handle_;
742 storage_ = other.storage_;
744 other.handle_ =
nullptr;
760 return from_rc(ove_socket_bind(handle_, &addr.raw));
771 return from_rc(ove_socket_listen(handle_, backlog));
792 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
794 ove_socket_t cli_handle{};
795 ove_socket_storage_t cli_storage{};
796 const int rc = ove_socket_accept(handle_, &cli_handle, &cli_storage,
800 client.handle_ = cli_handle;
801 client.storage_ = cli_storage;
832 ove_socket_close(handle_);
856 ove_socket_t handle_{};
857 ove_socket_storage_t storage_{};
882[[nodiscard]]
inline Result<Address>
883resolve(
const char *hostname, std::chrono::nanoseconds timeout = std::chrono::seconds{5})
noexcept
886 const int rc = ove_dns_resolve(hostname, &addr.raw,
to_timeout_ns(timeout));
Lightweight wrapper around ove_sockaddr_t.
Definition net.hpp:36
static Address ipv4(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint16_t port)
Creates an IPv4 address from individual octets and a port.
Definition net.hpp:54
Address()
Default-constructs a zeroed address.
Definition net.hpp:41
ove_sockaddr_t raw
The underlying C sockaddr.
Definition net.hpp:89
Address & set_port(uint16_t p)
Sets the port, returning a reference for chaining.
Definition net.hpp:82
uint16_t port() const
Returns the port in host byte order.
Definition net.hpp:65
Builder for ove_netif_config_t.
Definition net.hpp:102
NetIfConfig & dhcp()
Enables DHCP.
Definition net.hpp:131
ove_netif_config_t raw
The underlying C configuration struct.
Definition net.hpp:149
NetIfConfig & static_ip(const Address &ip, const Address &mask, const Address &gw)
Configures a static IP address.
Definition net.hpp:118
NetIfConfig()
Default-constructs a zeroed configuration.
Definition net.hpp:107
NetIfConfig & dns(const Address &d)
Sets the DNS server address.
Definition net.hpp:142
RAII wrapper around an oveRTOS network interface.
Definition net.hpp:165
NetIf & operator=(NetIf &&other) noexcept
Move-assignment operator — transfers ownership of the handle.
Definition net.hpp:209
~NetIf() noexcept
De-initialises the network interface.
Definition net.hpp:181
void down()
Tears down the network interface.
Definition net.hpp:252
NetIf()
Constructs and initialises the network interface.
Definition net.hpp:172
NetIf(NetIf &&other) noexcept
Move constructor — transfers ownership of the handle.
Definition net.hpp:199
Result< void > get_addr(Address *ip=nullptr, Address *gateway=nullptr, Address *netmask=nullptr) noexcept
Query the current addresses of the network interface.
Definition net.hpp:270
Result< void > up(const NetIfConfig &cfg) noexcept
Brings the network interface up.
Definition net.hpp:227
bool valid() const
Returns true if the underlying handle is non-null.
Definition net.hpp:282
ove_netif_t handle() const
Returns the raw oveRTOS network interface handle.
Definition net.hpp:291
RAII wrapper around an oveRTOS TCP listening socket.
Definition net.hpp:690
void close()
Closes the listening socket.
Definition net.hpp:829
Result< void > accept(TcpSocket &client, std::chrono::nanoseconds timeout=wait_forever) noexcept
Accepts an incoming connection.
Definition net.hpp:791
TcpListener()
Opens a new TCP socket for listening.
Definition net.hpp:697
ove_socket_t handle() const
Returns the raw oveRTOS socket handle.
Definition net.hpp:850
TcpListener & operator=(TcpListener &&other) noexcept
Move-assignment operator — transfers ownership of the socket.
Definition net.hpp:736
bool is_open() const
Returns true if the listening socket is open.
Definition net.hpp:841
TcpListener(TcpListener &&other) noexcept
Move constructor — transfers ownership of the socket.
Definition net.hpp:724
Result< void > bind(const Address &addr) noexcept
Binds the socket to a local address.
Definition net.hpp:758
Result< void > listen(int backlog=4) noexcept
Marks the socket as listening for incoming connections.
Definition net.hpp:769
~TcpListener() noexcept
Closes the listening socket if it is still open.
Definition net.hpp:707
RAII wrapper around an oveRTOS TCP (stream) socket.
Definition net.hpp:318
ove_socket_t handle() const
Returns the raw oveRTOS socket handle.
Definition net.hpp:475
Result< size_t > recv(void *buf, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Receives data from the connected socket.
Definition net.hpp:422
bool is_open() const
Returns true if the socket is open.
Definition net.hpp:466
TcpSocket & operator=(TcpSocket &&other) noexcept
Move-assignment operator — transfers ownership of the socket.
Definition net.hpp:364
TcpSocket(TcpSocket &&other) noexcept
Move constructor — transfers ownership of the socket.
Definition net.hpp:352
TcpSocket()
Opens a new TCP socket.
Definition net.hpp:325
~TcpSocket() noexcept
Closes the socket if it is still open.
Definition net.hpp:335
Result< void > connect(const Address &addr, std::chrono::nanoseconds timeout=wait_forever) noexcept
Connects to a remote address.
Definition net.hpp:388
void close()
Closes the TCP socket.
Definition net.hpp:454
Result< size_t > send(const void *data, size_t len) noexcept
Sends data on the connected socket.
Definition net.hpp:404
RAII wrapper around an oveRTOS UDP (datagram) socket.
Definition net.hpp:508
~UdpSocket() noexcept
Closes the socket if it is still open.
Definition net.hpp:525
Result< size_t > send_to(const void *data, size_t len, const Address &dest) noexcept
Sends a datagram to a specific destination.
Definition net.hpp:590
UdpSocket()
Opens a new UDP socket.
Definition net.hpp:515
bool is_open() const
Returns true if the socket is open.
Definition net.hpp:657
UdpSocket(UdpSocket &&other) noexcept
Move constructor — transfers ownership of the socket.
Definition net.hpp:542
Result< size_t > recv_from(void *buf, size_t len, Address *src=nullptr, std::chrono::nanoseconds timeout=wait_forever) noexcept
Receives a datagram and the sender's address.
Definition net.hpp:614
void close()
Closes the UDP socket.
Definition net.hpp:645
Result< void > bind(const Address &addr) noexcept
Binds the socket to a local address.
Definition net.hpp:576
UdpSocket & operator=(UdpSocket &&other) noexcept
Move-assignment operator — transfers ownership of the socket.
Definition net.hpp:554
ove_socket_t handle() const
Returns the raw oveRTOS socket handle.
Definition net.hpp:666
Strong ove::Error type, Result<T> alias, and std::error_code interop for the oveRTOS C++ binding.
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:20
constexpr uint64_t to_timeout_ns(std::chrono::duration< Rep, Period > d) noexcept
Convert a chrono duration to uint64_t nanoseconds for the C API.
Definition types.hpp:129
constexpr std::chrono::nanoseconds wait_forever
Sentinel duration meaning "block indefinitely".
Definition types.hpp:119
Result< void > from_rc(int rc) noexcept
Lifts a substrate rc-code into a Result<void>.
Definition error.hpp:254
std::expected< T, Error > Result
std::expected-based result alias.
Definition error.hpp:139
Common type definitions and concepts for the C++ wrapper layer.