ddn.net.dtls.polltransport

POSIX datagram transport and poll-based timer for DTLS.

Provides PollDtlsTransport which wraps a POSIX UDP socket as a DtlsTransport, and PollDtlsTimer which implements DtlsTimerSink using monotonic deadlines suitable for poll()-based event loops.

These are the concrete I/O adapters that bridge the DTLS engine to real network sockets without depending on any event loop framework.

Example:

import ddn.net.dtls;

// Create non-blocking UDP socket
auto fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
scope(exit) close(fd);

auto transport = new PollDtlsTransport(fd);
auto timer = new PollDtlsTimer();
auto engine = new NativeDtlsEngine(transport, timer, "example.com");

Types 2

DTLS transport over a POSIX UDP socket.

Wraps a non-blocking UDP file descriptor, converting between the portable DatagramEndpoint struct and native sockaddr_in / sockaddr_in6.

The socket must be created and bound by the caller. It should be set to non-blocking mode for proper DTLS operation.

Thread safety: NOT thread-safe. All calls must be serialized.

Fields
private int fd_
Methods
ptrdiff_t recvFrom(ubyte[] buffer, out DatagramEndpoint sender)Receives a single datagram from the socket.
ptrdiff_t sendTo(const(ubyte)[] data, DatagramEndpoint dest)Sends a single datagram to the given address.
PollHandle pollHandle() @property constReturns the socket file descriptor as a PollHandle.
bool isOpen() @property constReturns whether the socket is still open.
void close()Closes the underlying socket.
int fd() @property const pure nothrow @nogcReturns the raw file descriptor.
Constructors
this(int fd)Constructs a transport wrapping a POSIX UDP socket.

Poll-friendly DTLS timer using monotonic deadlines.

Designed for use with poll()-based event loops. The timer tracks a monotonic deadline and callback. The caller checks nextTimeoutMs() to get the poll timeout value, then calls check() after poll returns to fire any expired timer.

Example:

auto timer = new PollDtlsTimer();
dtls.handshake();

// In event loop:
int timeout = timer.nextTimeoutMs();
pollfd pfd = { fd, POLLIN, 0 };
poll(&pfd, 1, timeout);
timer.check(); // fires callback if deadline passed

Fields
private MonoTime deadline_
private void delegate() callback_
Methods
void scheduleTimeout(Duration delay, void delegate() onTimeout)Schedules a timeout callback.
void cancelTimeout()Cancels any previously scheduled timeout.
int nextTimeoutMs()Returns milliseconds until the next timeout, or -1 for infinite.
bool check()Checks if the deadline has passed and fires the callback.
bool hasPendingTimeout() @property constReturns true if a timeout is currently scheduled.
MonoTime deadline() @property const pure nothrow @nogcReturns the current deadline, or MonoTime.max if none.

Functions 2

fnDatagramEndpoint nativeToDatagramEndpoint(sockaddr * addr, socklen_t addrLen) @trustedConvert a native sockaddr to a portable DatagramEndpoint.
fnvoid socketAddressToNative(DatagramEndpoint addr, sockaddr * outAddr, ref socklen_t outLen) @trusted nothrowConvert a portable DatagramEndpoint to a native sockaddr.