eve.aio.posix.udp

Async UDP datagram socket primitives for POSIX platforms.

This module provides the POSIX implementation of UDP networking primitives using standard BSD sockets API. It works on Linux, BSD, and macOS.

UDP is message-oriented: each send/receive operates on complete datagrams. Unlike TCP, there is no connection state or backpressure mechanism.

Types 7

UDP socket configuration.

Fields
size_t maxDatagramSizeMaximum datagram size for receive buffer.
bool reuseAddrEnable SO_REUSEADDR on bind.
bool broadcastEnable SO_BROADCAST for sending broadcast messages.
Methods
bool isValid() @property const pure @safe nothrow @nogcValidate the config.

Represents a remote endpoint address.

Fields
ushort familyAddress family (AFINET or AFINET6).
ushort portPort number in host byte order.
ubyte[4] ipv4IPv4 address bytes (only valid if family == AF_INET).
ubyte[16] ipv6IPv6 address bytes (only valid if family == AF_INET6).
Methods
bool isValid() @property const pure @safe nothrow @nogcCheck if this is a valid address.
bool isIPv4() @property const pure @safe nothrow @nogcCheck if this is an IPv4 address.
bool isIPv6() @property const pure @safe nothrow @nogcCheck if this is an IPv6 address.
private aliasDataCallback = void delegate( ref UdpSocket socket, scope const(ubyte)[] data, SocketAddress sender) @safe
private aliasErrorCallback = void delegate(ref UdpSocket socket, int errorNumber) @safe
structUdpSocket

Async UDP socket wrapper.

Wraps a non-blocking UDP socket and integrates with the Layer 1 event loop for async send/receive operations.

Fields
Methods
UdpSocket create(UdpSocketConfig config = UdpSocketConfig.init) @trustedCreate a detached UDP socket wrapper.
void onData(DataCallback callback) @property @trustedSet the data received callback.
void onError(ErrorCallback callback) @property @trustedSet the error callback.
bool isBound() @property const @safe nothrow @nogcReport whether the socket is currently bound.
ushort localPort() @property const @safe nothrow @nogcReport the local port the socket is bound to.
int bind(ref EventLoop loop, scope const(char)[] host, ushort port) @trustedBind the socket to a local endpoint.
DatagramResult sendTo(scope const(ubyte)[] data, scope const(char)[] host, ushort port) @trustedSend a datagram to a specific destination.
DatagramResult sendToAddress(scope const(ubyte)[] data, SocketAddress dest) @trustedSend a datagram to a specific destination address.
void pauseReceiving() @trusted nothrowPause receiving datagrams.
void resumeReceiving() @trusted nothrowResume receiving datagrams.
void close() @trusted nothrowClose the socket.
void dispose() @trusted nothrowDispose the socket and its watcher registration.
private classUdpSocketState
Fields
EventLoop * _loop
Handle _handle
Token _token
ushort _localPort
bool _receivingPaused
ubyte[] _recvBuffer
Methods
bool isBound() @property const @safe nothrow @nogc
int bind(ref EventLoop loop, scope const(char)[] host, ushort port) @trusted nothrow
DatagramResult sendTo(scope const(ubyte)[] data, scope const(char)[] host, ushort port) @trusted nothrow
DatagramResult sendToAddress(scope const(ubyte)[] data, SocketAddress dest) @trusted nothrow
void pauseReceiving() @trusted nothrow
void resumeReceiving() @trusted nothrow
void close() @trusted nothrow
void handleIo(ref EventLoop loop, Token token, IoReady ready) @safe nothrow
UdpSocket owner() @safe nothrow
void receiveAvailable() @trusted nothrow
int refreshInterest() @trusted nothrow
void invokeData(scope const(ubyte)[] data, SocketAddress sender) @trusted nothrow
void invokeError(int errorNumber) @trusted nothrow
Constructors
private structAddrinfoRange

Range adapter for iterating over addrinfo linked list.

Fields
addrinfo * current
Methods
bool empty() @property const pure @safe nothrow @nogcCheck if the range is exhausted.
addrinfo * front() @property pure @safe nothrow @nogcGet the current addrinfo entry.
void popFront() pure @safe nothrow @nogcAdvance to the next entry.

Functions 8

private fnUdpSocketConfig validated(UdpSocketConfig config) pure @safe nothrow @nogcValidate a socket config, returning defaults if invalid.
private fnconst(char) * copyStringz(scope const(char)[] source, scope char[] buffer) @trusted nothrowCopy a D string slice to a null-terminated C string buffer.
private fnint setNonBlocking(int fd) @trusted nothrowSet a file descriptor to non-blocking mode.
private fnbool wouldBlock(int value) pure @safe nothrow @nogcCheck if an errno value indicates the operation would block.
private fnint resolveErrno(int status) @trusted nothrowConvert getaddrinfo error to errno equivalent.
private fnushort queryLocalPort(int fd) @trusted nothrowQuery the local port number for a bound socket.
private fnSocketAddress parseSocketAddress(ref const sockaddr_storage storage) @trusted nothrow @nogcParse a sockaddr_storage into a SocketAddress.
private fnAddrinfoRange addrinfoRange(addrinfo * first) pure @safe nothrow @nogcCreate a range over an addrinfo linked list.