4#ifndef WATERLINKEDSONAR_UDP_SOCKET_HPP
5#define WATERLINKEDSONAR_UDP_SOCKET_HPP
14namespace waterlinked::sonar {
24 enum class Mode : std::uint8_t {
73 std::chrono::milliseconds timeout);
IPv4 UDP socket bound for the sonar's multicast or unicast stream.
Definition socket.hpp:42
UdpSocket & operator=(UdpSocket &&other) noexcept
Closes this socket and takes over the socket of other.
std::uint16_t local_port() const
Port the socket is bound to; useful when the configured port was 0.
std::optional< Datagram > receive(Span< std::uint8_t > buffer, std::chrono::milliseconds timeout)
Waits up to timeout for a datagram and copies it into buffer, truncating it to the buffer size.
UdpSocket(const UdpSocketConfig &config)
Binds the socket and, in MULTICAST mode, joins the group with SO_REUSEADDR set so that several receiv...
UdpSocket(UdpSocket &&other) noexcept
Takes over the socket of other, which may only be destroyed or assigned to afterwards.
~UdpSocket()
Closes the socket.
constexpr const char * MULTICAST_GROUP
Multicast group the sonar streams to by default.
Definition socket.hpp:17
constexpr std::uint16_t MULTICAST_PORT
Port the sonar streams to by default.
Definition socket.hpp:19
Non-owning view over a contiguous sequence.
tcb::span< T > Span
Non-owning view over a contiguous sequence, with the interface of C++20 std::span.
Definition span.hpp:17
Addressing, port and receive buffer of a UdpSocket.
Definition socket.hpp:22
int receive_buffer_bytes
Requested SO_RCVBUF size. The kernel caps it at net.core.rmem_max.
Definition socket.hpp:38
std::string interface_ip
Interface that joins the group in MULTICAST mode; bind address in UNICAST mode.
Definition socket.hpp:36
std::uint16_t port
Local port. In UNICAST mode, the destination port set on the sonar.
Definition socket.hpp:33
Mode mode
Multicast or unicast.
Definition socket.hpp:29
Mode
Addressing of the received stream.
Definition socket.hpp:24
@ UNICAST
Receive datagrams addressed to interface_ip.
@ MULTICAST
Join multicast_group.
std::string multicast_group
Group joined in MULTICAST mode.
Definition socket.hpp:31
Size and sender of a received datagram.
Definition socket.hpp:45
std::string source_ip
IPv4 address of the sender.
Definition socket.hpp:47
std::size_t size
Bytes written to the buffer.
Definition socket.hpp:46