livox_mid360_core
C++ driver library for the Livox Mid-360 LiDAR
Loading...
Searching...
No Matches
livox::mid360::UdpSocket Class Reference

Non-blocking IPv4 UDP socket. Move-only; closes the descriptor on destruction. More...

#include <livox/mid360/transport.hpp>

Public Member Functions

 UdpSocket (UdpSocket &&other) noexcept
 Takes over the descriptor; other is left closed.
UdpSocket & operator= (UdpSocket &&other) noexcept
 Closes the current descriptor and takes over the one of other.
 UdpSocket (const UdpSocket &)=delete
UdpSocket & operator= (const UdpSocket &)=delete
bool is_open () const noexcept
 True while the socket holds a descriptor.
int native_handle () const noexcept
 Raw descriptor (for Poller and tests). -1 when closed.
Endpoint local_endpoint () const noexcept
 Address actually bound (port resolved when 0 was requested).
std::expected< std::size_t, TransportError > recv_buffer_bytes () const
 Effective SO_RCVBUF as reported by the kernel.
std::expected< std::size_t, TransportError > send_to (std::span< const std::byte > data, const Endpoint &to) const
 Send one datagram. Returns bytes sent (always data.size() for UDP on success).
std::expected< std::size_t, TransportError > recv_batch (std::span< Datagram > out) const
 Receive up to out.size() datagrams without blocking.
std::expected< Datagram, TransportError > recv_one (std::span< std::byte > buffer) const
 Convenience: receive a single datagram into buffer.
void close () noexcept
 Close the descriptor. Safe to call on a closed socket.

Static Public Member Functions

static std::expected< UdpSocket, TransportError > open (Endpoint bind_to, const SocketOptions &options={})
 Create a non-blocking socket and bind it to bind_to (port 0 = ephemeral).

Detailed Description

Non-blocking IPv4 UDP socket. Move-only; closes the descriptor on destruction.

Member Function Documentation

◆ open()

std::expected< UdpSocket, TransportError > livox::mid360::UdpSocket::open ( Endpoint bind_to,
const SocketOptions & options = {} )
staticnodiscard

Create a non-blocking socket and bind it to bind_to (port 0 = ephemeral).

Setting the reserved multicast_group or bind_to_device fails with kInvalidArgument.

◆ recv_batch()

std::expected< std::size_t, TransportError > livox::mid360::UdpSocket::recv_batch ( std::span< Datagram > out) const
nodiscard

Receive up to out.size() datagrams without blocking.

Each out[i].data must point to a caller-owned buffer on entry; on return it is trimmed to the received size and from / recv_time_ns are filled. Returns the number of datagrams received, or kWouldBlock when nothing is pending.


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