Skip to main content

named_pipe_server_routine

Function named_pipe_server_routine 

async fn named_pipe_server_routine(
    server: NamedPipeServer,
    receiver: &mut Receiver<[u8; 13]>,
    clients: Arc<Mutex<Clients>>,
)
Expand description

Correlate the connecting client by PID, then multiplex input records, ClientState updates, and keep-alives onto the named pipe.

The post-subscribe initial-state push is intentional: state_receiver.changed only fires on transitions observed after subscribe, so a state set in the brief window between Client construction and subscribe would otherwise leave the client on its default until the next transition.

The select! is biased toward recv so the keep-alive tick never preempts active input traffic; the ClientState::Disabled arm therefore probes the pipe itself, otherwise sustained input would hide a disconnect.

§Errors and termination

An unknown PID exits the process (production) or panics (tests) - the daemon’s bookkeeping is broken and recovery is not possible. A failed pipe write or a dropped [watch::Sender] ends the routine cleanly.