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

Receive-only UDP socket for the sonar's data stream. More...

#include <waterlinkedsonar/udp_socket.hpp>

Classes

struct  Datagram
 Byte count and sender address of one received datagram. More...
 

Public Member Functions

 UdpSocket (UdpSocketConfig config)
 Opens and binds the socket, requests SO_RCVBUF, and in multicast mode sets SO_REUSEADDR and joins the group.
 
 ~UdpSocket ()
 
 UdpSocket (const UdpSocket &)=delete
 
UdpSocketoperator= (const UdpSocket &)=delete
 
std::optional< Datagramrecv (std::uint8_t *buf, std::size_t buf_size, std::chrono::milliseconds timeout)
 Blocks up to timeout for one datagram, written to buf.
 
std::uint16_t local_port () const
 The bound port; differs from the configured one only when it was 0.
 

Detailed Description

Receive-only UDP socket for the sonar's data stream.

Carries raw datagrams; decoding is the caller's job.

Constructor & Destructor Documentation

◆ UdpSocket() [1/2]

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

Opens and binds the socket, requests SO_RCVBUF, and in multicast mode sets SO_REUSEADDR and joins the group.

Parameters
configSocket setup.
Exceptions
std::system_erroron failure, including EADDRINUSE when another unicast socket already holds the port.

◆ ~UdpSocket()

waterlinked::sonar::UdpSocket::~UdpSocket ( )

◆ UdpSocket() [2/2]

waterlinked::sonar::UdpSocket::UdpSocket ( const UdpSocket )
delete

Member Function Documentation

◆ local_port()

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

The bound port; differs from the configured one only when it was 0.

◆ operator=()

UdpSocket & waterlinked::sonar::UdpSocket::operator= ( const UdpSocket )
delete

◆ recv()

std::optional< Datagram > waterlinked::sonar::UdpSocket::recv ( std::uint8_t *  buf,
std::size_t  buf_size,
std::chrono::milliseconds  timeout 
)

Blocks up to timeout for one datagram, written to buf.

Returns
The datagram's size and source, or nullopt on timeout.
Exceptions
std::system_erroron socket errors.

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