waterlinkedsonar
C++ client library for the Water Linked Sonar 3D-15
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
waterlinked::sonar::UdpSocket Class Reference

IPv4 UDP socket bound for the sonar's multicast or unicast stream. More...

#include <waterlinkedsonar/udp/socket.hpp>

Classes

struct  Datagram
 Size and sender of a received datagram. More...
 

Public Member Functions

 UdpSocket (const UdpSocketConfig &config)
 Binds the socket and, in MULTICAST mode, joins the group with SO_REUSEADDR set so that several receivers can share the port.
 
 ~UdpSocket ()
 Closes the socket.
 
 UdpSocket (UdpSocket &&other) noexcept
 Takes over the socket of other, which may only be destroyed or assigned to afterwards.
 
UdpSocket & operator= (UdpSocket &&other) noexcept
 Closes this socket and takes over the socket of other.
 
 UdpSocket (const UdpSocket &)=delete
 
UdpSocket & operator= (const UdpSocket &)=delete
 
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.
 
std::uint16_t local_port () const
 Port the socket is bound to; useful when the configured port was 0.
 

Detailed Description

IPv4 UDP socket bound for the sonar's multicast or unicast stream.

Constructor & Destructor Documentation

◆ UdpSocket()

waterlinked::sonar::UdpSocket::UdpSocket ( const UdpSocketConfig &  config)
explicit

Binds the socket and, in MULTICAST mode, joins the group with SO_REUSEADDR set so that several receivers can share the port.

Exceptions
std::system_erroron failure, including EADDRINUSE when another socket holds the port in UNICAST mode.

Member Function Documentation

◆ local_port()

std::uint16_t waterlinked::sonar::UdpSocket::local_port ( ) const

Port the socket is bound to; useful when the configured port was 0.

Exceptions
std::system_errorif the socket cannot be queried.

◆ receive()

std::optional< Datagram > waterlinked::sonar::UdpSocket::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.

Returns
The datagram, or std::nullopt on timeout.
Exceptions
std::system_erroron a socket error.

The documentation for this class was generated from the following file: