Skip to main content

Module service_reply

Module service_reply 

Source
Expand description

The connection of one waiting client, answered by the landing thread and kept alive by a beat from the reading thread. What: The service’s side of one waiting client: the queue of messages the landing thread answers with, and the loop that writes them to the client’s connection together with a heartbeat while nothing else is to say. Why: A client waits for its answer with no clock of its own (service_client.rs), so the only thing that ends its wait is silence. The thread that read the request has nothing else to do while the request is queued or landing, so it writes the heartbeats, and a long batch, a long queue or a slow disk in front of the landing never reads as a dead service. The landing thread hands its messages to that same thread through a channel instead of writing the connection itself, so the connection has one writer, a line is written whole, and no lock guards it.

In TS you’d write (pseudocode):

const [reply, messages] = makeReply(); queue.push({ request, reply }); await writeUntilAnswered(socket, messages, HEARTBEAT_EVERY);

Structs§

Reply
What: The landing thread’s end of one client’s messages. Why: Dropping it is what answering the request ends with: the writer sees the channel closed, writes what is left, and closes the connection.

Functions§

write_until_answered
What: Writes each queued message to the client, and a heartbeat whenever every passes with nothing queued, until the reply is dropped or the client is gone. Why: The heartbeat is the proof of life the client’s wait rests on; the queued messages come first, in order, so a beat never stands between a notice and the answer that follows it.
write_until_answered_noting
What: write_until_answered, where note is asked for a message whenever the beat is due, and what it returns is written before the beat. Why: A client queued behind a write that never ends is told what the service is stuck in (service_busy.rs); the beat is the one moment this thread has nothing queued to write, so the notice rides on it and is asked for at most once a beat.