Struct nix_compat::nix_daemon::handler::NixDaemon
source · pub struct NixDaemon<IO, R, W> {
io: Arc<IO>,
protocol_version: ProtocolVersion,
client_settings: ClientSettings,
reader: NixReader<R>,
writer: Arc<Mutex<NixWriter<W>>>,
}
Expand description
Handles a single connection with a nix client.
As part of its initialization
it performs the handshake with the client
and determines the ProtocolVersion and ClientSettings to use for the remainder of the session.
Once initialized, [handle_client
] needs to be called to handle the rest of the session,
it delegates all operation handling to an instance of NixDaemonIO.
Fields§
§io: Arc<IO>
§protocol_version: ProtocolVersion
§client_settings: ClientSettings
§reader: NixReader<R>
§writer: Arc<Mutex<NixWriter<W>>>
Implementations§
source§impl<IO, R, W> NixDaemon<IO, R, W>
impl<IO, R, W> NixDaemon<IO, R, W>
pub fn new( io: Arc<IO>, protocol_version: ProtocolVersion, client_settings: ClientSettings, reader: NixReader<R>, writer: NixWriter<W>, ) -> Self
source§impl<IO, RW> NixDaemon<IO, ReadHalf<RW>, WriteHalf<RW>>
impl<IO, RW> NixDaemon<IO, ReadHalf<RW>, WriteHalf<RW>>
sourcepub async fn initialize(io: Arc<IO>, connection: RW) -> Result<Self, Error>
pub async fn initialize(io: Arc<IO>, connection: RW) -> Result<Self, Error>
Async constructor for NixDaemon.
Performs the initial handshake with the client and retrieves the client’s preferred settings.
The resulting daemon can handle the client session by calling NixDaemon::handle_client.
sourcepub async fn handle_client(&mut self) -> Result<(), Error>
pub async fn handle_client(&mut self) -> Result<(), Error>
Main client connection loop, reads client’s requests and responds to them accordingly.
sourceasync fn handle<T>(
writer: &Arc<Mutex<NixWriter<WriteHalf<RW>>>>,
future: impl Future<Output = Result<T>>,
) -> Result<(), Error>where
T: NixSerialize + Send,
async fn handle<T>(
writer: &Arc<Mutex<NixWriter<WriteHalf<RW>>>>,
future: impl Future<Output = Result<T>>,
) -> Result<(), Error>where
T: NixSerialize + Send,
Handles the operation and sends the response or error to the client.
As per nix daemon protocol, after sending the request, the client expects zero or more log lines/activities followed by either
- STDERR_LAST and the response bytes
- STDERR_ERROR and the error
This is a helper method, awaiting on the passed in future and then handling log lines/activities as described above.