Expand description
Thread-safe handle over a background-task crate::tcp::adapter::Adapter.
AdapterHandle spawns the adapter’s I/O loop onto whatever async
executor is current (tokio on native, wasm_bindgen_futures::spawn_local
on wasm32-unknown-unknown) and communicates with it through tokio
mpsc channels. The resulting StreamHandle is Send + Sync + 'static,
enabling use cases that crate::tcp::stream::AdapterStream cannot support:
- Multiple concurrent connections on the same adapter.
- Passing a stream to a
spawncall or storing it in anArc<Mutex<…>>. - Storing the stream in a struct without a lifetime parameter.
- FFI or any context that requires
'staticbounds.
The trade-off versus crate::tcp::stream::AdapterStream is a small channel
round-trip on every write, and the adapter runs in a dedicated background
task rather than being driven directly by the caller.
§Background task
AdapterHandle::new immediately spawns a task. The spawned task runs a
select! loop that races three branches:
- Incoming messages: connect/send/pcap/close requests from callers.
- Incoming packets: reads the next frame from the transport and updates connection state.
- 1 ms tick: calls
write_buffer_flush, which drains pending writes and checks for retransmission timeouts.
The task exits when the last AdapterHandle is dropped or when
AdapterHandle::close is called.
Structs§
- Adapter
Handle - A cloneable, thread-safe handle to a background
crate::tcp::adapter::Adaptertask. - Stream
Handle - A
Send + Sync + 'staticstream produced byAdapterHandle::connect. - UdpSocket
Handle - A bound UDP port on the userspace stack. Connectionless: [
recv] yields whole datagrams and [send_to] sends to a peer port. Dropping it unbinds the port.