eve.aio.windows.udp

Async UDP datagram socket primitives for Windows.

This module provides the Windows implementation of UDP networking primitives using Winsock2 API.

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

Types 8

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 (AF_INET or AF_INET6).
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
private UdpSocketState _state
Methods
UdpSocket create(UdpSocketConfig config = UdpSocketConfig.init) static @trustedCreate a detached UDP socket wrapper.
void onData(DataCallback callback) @property @trusted Set the data received callback. Fires when a datagram arrives. The `data` parameter is borrowed — valid only for the duration of the callback. Copy it if needed beyond. Thread affinity: even...
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 lastError() @property const @safe nothrow @nogcGet the last error recorded by a socket operation.
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) @trusted Send a datagram to a specific destination address. In WSAPoll mode, data is borrowed directly by the OS sendto call (Borrow semantics). In IOCP overlapped mode, data is copied into an internal...
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 UdpSocketState mutableState() @trusted
private structBufferedDatagram

A datagram received while receiving was paused.

Stores both the data and sender address for later delivery when receiving is resumed.

Fields
ubyte[] data
private classUdpSocketState
Fields
private EventLoop * _loop
private SOCKET _socket
private Token _token
private UdpSocketConfig _config
private ushort _localPort
private bool _receivingPaused
private ubyte[] _recvBuffer
private int _lastError
private bool _useOverlappedIoWhether this socket uses overlapped I/O mode.
private Token _prepareTokenPrepare token for polling IOCP completion status.
private OVERLAPPED _readOverlappedOverlapped structure for pending read operations.
private OVERLAPPED _writeOverlappedOverlapped structure for pending write operations.
private ubyte[UDP_BUFFER_SIZE] _overlappedRecvBufferRead buffer — must remain valid during overlapped read.
private ubyte[UDP_BUFFER_SIZE] _overlappedSendBufferWrite buffer — must remain valid during overlapped write.
private bool _readInProgressWhether a read operation is currently in progress.
private bool _writeInProgressWhether a write operation is currently in progress.
private SOCKADDR_STORAGE _senderAddrSender address storage for overlapped receive.
private int _senderAddrLenSender address length for overlapped receive.
private SOCKADDR_STORAGE _pendingSendAddrPending send destination address.
private int _pendingSendAddrLenPending send destination address length.
private size_t _pendingSendLenNumber of bytes in the pending send buffer.
private BufferedDatagram[] _pausedReceiveQueueQueue for datagrams received while receiving is paused (IOCP mode only). When paused, incoming datagrams are stored here instead of being delivered.
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
private UdpSocket owner() @safe nothrow
private void receiveAvailable() @trusted nothrow
private int refreshInterest() @trusted nothrow
private void invokeData(scope const(ubyte)[] data, SocketAddress sender) @trusted nothrow
private void invokeError(int errorNumber) @trusted nothrow
private void handlePrepare(ref EventLoop loop, Token token) @trusted nothrowHandle prepare phase callback from the event loop.
private int associateWithIocp() @trusted nothrowAssociate the socket with the event loop's IOCP.
private void submitRecvFrom() @trusted nothrowSubmit an overlapped receive operation for datagrams.
private void processRecvCompletion() @trusted nothrowProcess a completed receive operation.
private void submitSendTo() @trusted nothrowSubmit an overlapped send operation for datagrams.
private void processSendCompletion() @trusted nothrowProcess a completed send operation.
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 9

private fnint resolveGaiError(int gaiError) pure @safe nothrow @nogcMap getaddrinfo error codes to POSIX errno values.
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 fnconst(char) * portToString(ushort port, scope char[] buffer) @trusted nothrowConvert a port number to a null-terminated string.
private fnint setNonBlocking(SOCKET sock) @trusted nothrowSet a socket to non-blocking mode.
private fnbool wouldBlock() @trusted nothrowCheck if the last Winsock error indicates the operation would block.
private fnushort queryLocalPort(SOCKET sock) @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.

Variables 1

private enumvarUDP_BUFFER_SIZE = 65507

Size of the internal read/write buffer for overlapped I/O.