Function named_pipe_server_routine
async fn named_pipe_server_routine(
server: NamedPipeServer,
receiver: &mut Receiver<[u8; 13]>,
clients: Arc<Mutex<Clients>>,
)Expand description
Wait for the named pipe server to connect, correlate the client by its process id, then forward serialized input records read from the broadcast channel to the named pipe server.
Correlation: after [NamedPipeServer::connect] resolves, the client is
expected to write its 4 byte little-endian process id into the pipe. The
routine looks up the Client with that PID in the daemon’s clients
collection; if it is not found, the routine logs an error and terminates
the daemon — an unknown PID indicates broken daemon bookkeeping and is
unrecoverable.
Forwarding: on every broadcast record, the routine matches on the
PipeServerState cloned from the correlated client; only
PipeServerState::Enabled writes the record to the pipe. The keep-alive
write stays unconditional so dead pipes are detected regardless of state.
If writing to the pipe fails the pipe is considered closed and the routine ends.
To detect if a client is still alive even if we are currently
not sending data, we send a “keep alive packet”,
SERIALIZED_INPUT_RECORD_0_LENGTH bytes of 1s. If that fails, the routine ends.
§Arguments
server- The named pipe server over which we send data to the client.receiver- The receiving end of the broadcast channel through which we get the serialize input records from the main thread that are to be sent to the client via the named pipe.clients- The daemon’s collection of tracked clients, used to correlate the connecting client by PID and to obtain the sharedPipeServerStatereference for this server.
§Panics
Panics if the connecting client sends a PID that is not present in
clients.