FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::net::UdpSocket Class Reference

#include <fastmm/net/udp_socket.hpp>

Public Member Functions

 UdpSocket ()=default
 
 UdpSocket (int fd) noexcept
 
 ~UdpSocket ()
 
 UdpSocket (const UdpSocket &)=delete
 
UdpSocket & operator= (const UdpSocket &)=delete
 
 UdpSocket (UdpSocket &&o) noexcept
 
UdpSocket & operator= (UdpSocket &&o) noexcept
 
int bind (const SockAddr &addr) noexcept
 
int connect (const SockAddr &addr) noexcept
 
int set_reuseaddr (bool on) noexcept
 
int set_rcvbuf (int bytes) noexcept
 SO_RCVBUFFORCE (CAP_NET_ADMIN), falling back to SO_RCVBUF, which net.core.rmem_max caps.
 
int rcvbuf () const noexcept
 
int set_sndbuf (int bytes) noexcept
 
int join_group (std::uint32_t group_be, const McastInterface &ifc) noexcept
 IP_ADD_MEMBERSHIP (any source) and source-specific membership (IP_ADD_SOURCE_MEMBERSHIP for an interface address, MCAST_JOIN_SOURCE_GROUP for an index).
 
int join_source_group (std::uint32_t group_be, std::uint32_t source_be, const McastInterface &ifc) noexcept
 
int set_multicast_all (bool on) noexcept
 IP_MULTICAST_ALL: off delivers only the groups this socket joined.
 
int set_multicast_if (const McastInterface &ifc) noexcept
 
int set_multicast_ttl (int ttl) noexcept
 
int set_multicast_loop (bool on) noexcept
 
int enable_rx_timestamps () noexcept
 SO_TIMESTAMPING with RX_SOFTWARE | SOFTWARE | RX_HARDWARE | RAW_HARDWARE.
 
int set_busy_poll (int usec) noexcept
 SO_BUSY_POLL (µs), SO_PREFER_BUSY_POLL and SO_BUSY_POLL_BUDGET (both Linux 5.11).
 
int set_prefer_busy_poll (bool on) noexcept
 
int set_busy_poll_budget (int packets) noexcept
 
IoResult recv_from (std::span< std::byte > buf, SockAddr *from=nullptr) noexcept
 One datagram.
 
IoResult send_to (std::span< const std::byte > buf, const SockAddr &to) noexcept
 
IoResult send (std::span< const std::byte > buf) noexcept
 
int recv_batch (std::span< mmsghdr > msgs) noexcept
 recvmmsg / sendmmsg without blocking: messages transferred, 0 when the socket would block, or -errno.
 
int send_batch (std::span< mmsghdr > msgs) noexcept
 
std::optional< SockAddr > local_addr () const noexcept
 
void close () noexcept
 
int release () noexcept
 
int fd () const noexcept
 
bool valid () const noexcept
 
int last_error () const noexcept
 

Static Public Member Functions

static UdpSocket open () noexcept
 Non-blocking, close-on-exec AF_INET datagram socket.
 

Constructor & Destructor Documentation

◆ UdpSocket() [1/4]

fastmm::net::UdpSocket::UdpSocket ( )
default

◆ UdpSocket() [2/4]

fastmm::net::UdpSocket::UdpSocket ( int  fd)
inlineexplicitnoexcept

◆ ~UdpSocket()

fastmm::net::UdpSocket::~UdpSocket ( )
inline

◆ UdpSocket() [3/4]

fastmm::net::UdpSocket::UdpSocket ( const UdpSocket &  )
delete

◆ UdpSocket() [4/4]

fastmm::net::UdpSocket::UdpSocket ( UdpSocket &&  o)
inlinenoexcept

Member Function Documentation

◆ operator=() [1/2]

UdpSocket & fastmm::net::UdpSocket::operator= ( const UdpSocket &  )
delete

◆ operator=() [2/2]

UdpSocket & fastmm::net::UdpSocket::operator= ( UdpSocket &&  o)
inlinenoexcept

◆ open()

static UdpSocket fastmm::net::UdpSocket::open ( )
staticnoexcept

Non-blocking, close-on-exec AF_INET datagram socket.

Invalid on failure (errno in last_error()).

◆ bind()

int fastmm::net::UdpSocket::bind ( const SockAddr &  addr)
noexcept

◆ connect()

int fastmm::net::UdpSocket::connect ( const SockAddr &  addr)
noexcept

◆ set_reuseaddr()

int fastmm::net::UdpSocket::set_reuseaddr ( bool  on)
noexcept

◆ set_rcvbuf()

int fastmm::net::UdpSocket::set_rcvbuf ( int  bytes)
noexcept

SO_RCVBUFFORCE (CAP_NET_ADMIN), falling back to SO_RCVBUF, which net.core.rmem_max caps.

rcvbuf() reports what the kernel granted (twice the request, for its bookkeeping).

◆ rcvbuf()

int fastmm::net::UdpSocket::rcvbuf ( ) const
noexcept

◆ set_sndbuf()

int fastmm::net::UdpSocket::set_sndbuf ( int  bytes)
noexcept

◆ join_group()

int fastmm::net::UdpSocket::join_group ( std::uint32_t  group_be,
const McastInterface &  ifc 
)
noexcept

IP_ADD_MEMBERSHIP (any source) and source-specific membership (IP_ADD_SOURCE_MEMBERSHIP for an interface address, MCAST_JOIN_SOURCE_GROUP for an index).

Addresses in network order.

◆ join_source_group()

int fastmm::net::UdpSocket::join_source_group ( std::uint32_t  group_be,
std::uint32_t  source_be,
const McastInterface &  ifc 
)
noexcept

◆ set_multicast_all()

int fastmm::net::UdpSocket::set_multicast_all ( bool  on)
noexcept

IP_MULTICAST_ALL: off delivers only the groups this socket joined.

Linux defaults to on, which also delivers groups joined by other sockets that match the bound address.

◆ set_multicast_if()

int fastmm::net::UdpSocket::set_multicast_if ( const McastInterface &  ifc)
noexcept

◆ set_multicast_ttl()

int fastmm::net::UdpSocket::set_multicast_ttl ( int  ttl)
noexcept

◆ set_multicast_loop()

int fastmm::net::UdpSocket::set_multicast_loop ( bool  on)
noexcept

◆ enable_rx_timestamps()

int fastmm::net::UdpSocket::enable_rx_timestamps ( )
noexcept

SO_TIMESTAMPING with RX_SOFTWARE | SOFTWARE | RX_HARDWARE | RAW_HARDWARE.

Both stamps arrive in an SCM_TIMESTAMPING control message: ts[0] is the kernel's CLOCK_REALTIME receive time, ts[2] the NIC's raw PHC time, which is present only after enable_hw_timestamps() on the interface and is not CLOCK_REALTIME unless the PHC is disciplined to it (phc2sys).

◆ set_busy_poll()

int fastmm::net::UdpSocket::set_busy_poll ( int  usec)
noexcept

SO_BUSY_POLL (µs), SO_PREFER_BUSY_POLL and SO_BUSY_POLL_BUDGET (both Linux 5.11).

Each returns the setsockopt errno and changes nothing on failure: -EPERM without CAP_NET_ADMIN in the initial namespace (SO_BUSY_POLL above the current value before Linux 6.4, enabling SO_PREFER_BUSY_POLL, raising SO_BUSY_POLL_BUDGET), -ENOPROTOOPT on older kernels.

◆ set_prefer_busy_poll()

int fastmm::net::UdpSocket::set_prefer_busy_poll ( bool  on)
noexcept

◆ set_busy_poll_budget()

int fastmm::net::UdpSocket::set_busy_poll_budget ( int  packets)
noexcept

◆ recv_from()

IoResult fastmm::net::UdpSocket::recv_from ( std::span< std::byte >  buf,
SockAddr *  from = nullptr 
)
noexcept

One datagram.

would_block() on EAGAIN; bytes is the datagram's full length, which can exceed buf.size() (the rest is discarded; MSG_TRUNC).

◆ send_to()

IoResult fastmm::net::UdpSocket::send_to ( std::span< const std::byte >  buf,
const SockAddr &  to 
)
noexcept

◆ send()

IoResult fastmm::net::UdpSocket::send ( std::span< const std::byte >  buf)
noexcept

◆ recv_batch()

int fastmm::net::UdpSocket::recv_batch ( std::span< mmsghdr >  msgs)
noexcept

recvmmsg / sendmmsg without blocking: messages transferred, 0 when the socket would block, or -errno.

The caller owns the headers and resets msg_namelen / msg_controllen between calls.

◆ send_batch()

int fastmm::net::UdpSocket::send_batch ( std::span< mmsghdr >  msgs)
noexcept

◆ local_addr()

std::optional< SockAddr > fastmm::net::UdpSocket::local_addr ( ) const
noexcept

◆ close()

void fastmm::net::UdpSocket::close ( )
noexcept

◆ release()

int fastmm::net::UdpSocket::release ( )
inlinenoexcept

◆ fd()

int fastmm::net::UdpSocket::fd ( ) const
inlinenoexcept

◆ valid()

bool fastmm::net::UdpSocket::valid ( ) const
inlinenoexcept

◆ last_error()

int fastmm::net::UdpSocket::last_error ( ) const
inlinenoexcept