Module event_loop

Module event_loop 

Expand description

Single-connection driver.

A connection runs as one task (run_connection) that owns the Client state machine, both stream halves, and the sans-io framing (PacketReader) and encoding (PacketWriter) buffers. Reading, writing, command intake, message delivery, and keep-alive are all driven from a single select!: a stalled write never blocks reads (no half-duplex deadlock), and a slow application or peer turns into backpressure rather than unbounded buffering.

Because the codec keeps all parse/encode state in its buffers rather than in a future, every select! arm is cancellation-safe and the buffers are reused for the life of the connection. There is no per-packet or per-batch allocation on the read or write path. See the loop in run_connection for the per-arm cancellation reasoning.

ModulesΒ§

aliases πŸ”’
Topic-alias bookkeeping for a single connection (Β§3.3.2.3.4).
backoff πŸ”’
Deterministic jitter for reconnect backoff.
connect πŸ”’
Connection establishment: transport connect, CONNECT/CONNACK handshake, and classification of broker rejections.
inbound πŸ”’
Inbound packet processing: framing, dispatch through the client state machine, and buffering received messages for delivery.
offline πŸ”’
Handling of user commands while the client is between connections.
outbound πŸ”’
Outbound command handling: turning user commands and stored session state into wire packets, gated by the server’s Receive Maximum and Maximum Packet Size.
pending πŸ”’
Tracking and resolution of in-flight operation futures.
write πŸ”’
Write-side helpers: the cancellation-safe write arm and the teardown delivery/flush.

StructsΒ§

ConnectionResult πŸ”’
Result of a single connection attempt.
LoopState πŸ”’
Mutable state that persists across reconnection attempts.

EnumsΒ§

DisconnectReason πŸ”’
Why a single connection attempt ended.

ConstantsΒ§

MSG_QUEUE_BOUND πŸ”’
Received messages buffered for the application before the coordinator stops reading the socket. Decouples application delivery from protocol processing: acknowledgements and keep-alive keep flowing while the application drains, and only a full buffer pauses inbound reads (which applies backpressure down to TCP).
OFFLINE_QUEUE_LIMIT πŸ”’
Maximum operations buffered while offline before new ones are rejected with Error::QueueFull, bounding memory during a long outage.
OUTBOUND_BYTE_LIMIT πŸ”’
Soft cap, in bytes, on the pending outbound buffer; new commands are not accepted while this many encoded bytes are still waiting to be written. Bounds memory when the peer stalls. Soft because a single in-progress packet may push the buffer past the limit before intake pauses.
READ_BUFFER_CAPACITY πŸ”’
Initial capacity of the inbound framing buffer, reused from the handshake through the steady-state read loop.
READ_CHUNK πŸ”’
Size of the scratch buffer each socket read fills before the bytes are fed into the framing buffer.

FunctionsΒ§

disconnect_packet πŸ”’
enqueue πŸ”’
Encodes a packet into the pending outbound buffer for the writer task.
jitter_seed πŸ”’
Seeds the backoff-jitter PRNG from wall-clock nanoseconds and the client id, so distinct client instances draw distinct jitter sequences.
persist_and_ack πŸ”’
Persists pending session ops and, on success, resolves the queued() futures the write covers. On failure both are retained for the retry after the backoff-driven reconnect.
run
run_connection πŸ”’
shutdown_requested πŸ”’
true once EventLoopHandle was stopped or dropped. Consumes the signal; the caller must exit without polling rx again.

Type AliasesΒ§

Outbound πŸ”’
The coordinator’s in-place outbound encoder: packets are encoded into one reusable buffer and written from it directly, with no per-packet allocation and no per-batch handoff.