Skip to main content

Crate virtual_socket

Crate virtual_socket 

Source
Expand description

Virtual UDP sockets that share a single physical tokio::net::UdpSocket.

Pattern: a single physical UDP socket is owned by a top-level “router” task that reads from it. The router demultiplexes each inbound datagram to one of several VirtualUdpSockets — by peer address, by some identifier inside the payload (e.g. a QUIC Connection ID), by listener kind, or any other rule the router chooses. Each virtual socket has its own bounded inbound queue; consumers drain that queue via VirtualUdpSocket::poll_dequeue or VirtualUdpSocket::try_dequeue.

Outbound is mux: every virtual socket forwards VirtualUdpSocket::try_send_to / VirtualUdpSocket::poll_send_ready to the shared physical socket, so multiple consumers can write through the same OS endpoint without contention beyond what the OS itself imposes.

This crate is transport-policy free: it does not parse datagrams, does not own a routing table, and does not implement any application protocol. Pair it with whatever demultiplex strategy the calling system needs (e.g. peer-address fan-in, QUIC CID demux, DNS query-ID dispatch).

For an adapter that exposes VirtualUdpSocket as a quinn::AsyncUdpSocket, see the quinn-shared-socket crate.

Structs§

VirtualUdpSocket
One virtual UDP socket sharing the physical socket given at construction time. Inbound datagrams arrive only via VirtualUdpSocket::enqueue_inbound (called by the router that owns the physical socket); outbound datagrams pass through to the physical socket unchanged.

Constants§

DEFAULT_INBOUND_CAPACITY
Default inbound queue capacity. Matches a single high-throughput QUIC endpoint’s burst window without letting a single misbehaving session starve siblings sharing the physical socket.