7#include "fastmm/net/io_result.hpp"
8#include "fastmm/net/tcp_socket.hpp"
10#include <sys/socket.h>
21[[nodiscard]]
bool parse_ipv4(std::string_view text, std::uint32_t& out_be)
noexcept;
23 return (addr_be & 0xF0U) == 0xE0U;
28struct McastInterface {
64 [[nodiscard]]
int bind(const SockAddr& addr) noexcept;
65 [[nodiscard]]
int connect(const SockAddr& addr) noexcept;
69 [[nodiscard]]
int set_rcvbuf(
int bytes) noexcept;
70 [[nodiscard]]
int rcvbuf() const noexcept;
77 std::uint32_t source_be,
101 IoResult
recv_from(std::span<std::
byte> buf, SockAddr* from =
nullptr) noexcept;
102 IoResult
send_to(std::span<const std::
byte> buf, const SockAddr& to) noexcept;
103 IoResult
send(std::span<const std::
byte> buf) noexcept;
106 int recv_batch(std::span<mmsghdr> msgs) noexcept;
107 int send_batch(std::span<mmsghdr> msgs) noexcept;
117 int fd() const noexcept {
return fd_; }
118 bool valid() const noexcept {
return fd_ >= 0; }
122 int set_int_opt(
int level,
int name,
int value)
noexcept;
Definition udp_socket.hpp:44
bool valid() const noexcept
Definition udp_socket.hpp:120
UdpSocket(const UdpSocket &)=delete
int set_multicast_if(const McastInterface &ifc) noexcept
int rcvbuf() const noexcept
int connect(const SockAddr &addr) noexcept
IoResult recv_from(std::span< std::byte > buf, SockAddr *from=nullptr) noexcept
One datagram.
int set_busy_poll_budget(int packets) noexcept
std::optional< SockAddr > local_addr() const noexcept
int set_multicast_ttl(int ttl) 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,...
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 interf...
int last_error() const noexcept
Definition udp_socket.hpp:121
~UdpSocket()
Definition udp_socket.hpp:48
static UdpSocket open() noexcept
Non-blocking, close-on-exec AF_INET datagram socket.
int set_prefer_busy_poll(bool on) noexcept
IoResult send_to(std::span< const std::byte > buf, const SockAddr &to) noexcept
int set_reuseaddr(bool on) noexcept
UdpSocket & operator=(const UdpSocket &)=delete
int release() noexcept
Definition udp_socket.hpp:114
int set_rcvbuf(int bytes) noexcept
SO_RCVBUFFORCE (CAP_NET_ADMIN), falling back to SO_RCVBUF, which net.core.rmem_max caps.
int join_source_group(std::uint32_t group_be, std::uint32_t source_be, const McastInterface &ifc) noexcept
int fd() const noexcept
Definition udp_socket.hpp:119
int set_multicast_all(bool on) noexcept
IP_MULTICAST_ALL: off delivers only the groups this socket joined.
int set_sndbuf(int bytes) noexcept
int enable_rx_timestamps() noexcept
SO_TIMESTAMPING with RX_SOFTWARE | SOFTWARE | RX_HARDWARE | RAW_HARDWARE.
int set_multicast_loop(bool on) noexcept
int send_batch(std::span< mmsghdr > msgs) noexcept
UdpSocket(int fd) noexcept
Definition udp_socket.hpp:47
int bind(const SockAddr &addr) noexcept
int set_busy_poll(int usec) noexcept
SO_BUSY_POLL (µs), SO_PREFER_BUSY_POLL and SO_BUSY_POLL_BUDGET (both Linux 5.11).
Definition reactor.hpp:37
int enable_hw_timestamps(std::string_view ifname) noexcept
SIOCSHWTSTAMP on ifname: hardware timestamps for all received packets, TX off.
bool parse_ipv4(std::string_view text, std::uint32_t &out_be) noexcept
Parses dotted-quad IPv4 into network byte order. Returns false on anything else.
constexpr bool is_ipv4_multicast(std::uint32_t addr_be) noexcept
Definition udp_socket.hpp:24
Interface for multicast membership and IP_MULTICAST_IF: an IPv4 address or an interface index.
Definition udp_socket.hpp:30
std::uint32_t addr_be
Definition udp_socket.hpp:31
unsigned index
Definition udp_socket.hpp:32
static int resolve(std::string_view spec, McastInterface &out) noexcept
"" (kernel's choice), a dotted-quad address, or an interface name ("eth0", resolved with if_nametoind...