Skip to main content

Module event_loop

Module event_loop 

Available on crate feature tokio only.
Expand description

Single-connection driver.

The EventLoop runs as one task that owns the Client state machine. Each Connection owns 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 one 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 Connection for the per-arm cancellation reasoning.

ModulesΒ§

aliases πŸ”’
Topic-alias bookkeeping for one 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.
connection πŸ”’
The state of an established connection and the select! loop that drives it.
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, limited 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 one connection attempt.
Endpoints πŸ”’
The channel ends the event loop serves.
EventLoop πŸ”’
The connection event loop. It owns the client state machine and the state that persists across reconnects, and runs one Connection at a time.

EnumsΒ§

DisconnectReason πŸ”’
Why one 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. Inbound reads pause only when the buffer is full, 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 one 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Β§

defer πŸ”’
Resets timer to fire delay from now.
enqueue πŸ”’
Encodes a packet into the pending outbound buffer for the writer task.
enqueue_disconnect πŸ”’
Enqueues a DISCONNECT with reason_code. Returns whether it can be flushed.
jitter_seed πŸ”’
Seeds the backoff-jitter PRNG from wall-clock nanoseconds and the client id, so distinct client instances draw distinct jitter sequences.
shutdown_requested πŸ”’
true once EventLoopHandle was stopped or dropped. Consumes the signal. The caller must exit without polling rx again.

Type AliasesΒ§

Control πŸ”’
Why a connection ended, and whether an enqueued DISCONNECT should be flushed before the socket closes.
Outbound πŸ”’
The coordinator encodes outbound packets in place into one reusable buffer and writes them from it directly. This avoids per-packet allocation and per-batch handoff.