pub struct DrainState<F>{ /* private fields */ }Expand description
Orchestrates non-blocking process I/O.
DrainState tracks the state of stdin, stdout, and stderr pipes for a
single process. It handles the multiplexing of data between these pipes
and internal buffers.
§Example
while !drain.is_done() {
let mut events = Vec::new();
reactor.wait(&mut events, 64, -1)?;
for ev in events {
// Map event tokens to drain calls...
}
}Implementations§
Source§impl<F> DrainState<F>
impl<F> DrainState<F>
Sourcepub fn new(
stdin_fd: Option<Fd>,
stdin_buf: Option<Box<[u8]>>,
stdout_fd: Option<Fd>,
stderr_fd: Option<Fd>,
limit: usize,
early_exit: Option<F>,
chunk_sink: Option<ChunkSink>,
pty_master: bool,
) -> Result<Self, CoreError>
pub fn new( stdin_fd: Option<Fd>, stdin_buf: Option<Box<[u8]>>, stdout_fd: Option<Fd>, stderr_fd: Option<Fd>, limit: usize, early_exit: Option<F>, chunk_sink: Option<ChunkSink>, pty_master: bool, ) -> Result<Self, CoreError>
Initialize a new drain state for the provided descriptors.
This consumes the descriptors and sets them to non-blocking mode.
chunk_sink enables streaming mode: every retained output chunk is
forwarded to the sink instead of being accumulated into the internal
buffers.
§Errors
EBADF: One of the provided file descriptors is invalid.
Sourcepub fn write_stdin(&mut self) -> Result<bool, CoreError>
pub fn write_stdin(&mut self) -> Result<bool, CoreError>
Perform a non-blocking write to stdin if pending.
Returns Ok(true) if the write buffer is empty or the descriptor is
closed.
§Errors
EPIPE: The child process closed its reading end of the pipe.EIO: Low-level I/O error.
Sourcepub fn read_fd(&mut self, is_stdout: bool) -> Result<bool, CoreError>
pub fn read_fd(&mut self, is_stdout: bool) -> Result<bool, CoreError>
Perform a non-blocking read from stdout or stderr.
Returns Ok(true) if the stream reached EOF, the early-exit condition
was met, or the stream is paused on a full sink queue (the caller
resumes it later). In the paused case the slot is retained.
§Errors
EOVERFLOW: The captured output exceeded the specified limit.EIO: Low-level I/O error.
Sourcepub fn stdout_paused(&self) -> bool
pub fn stdout_paused(&self) -> bool
Return whether the stdout stream is paused on a full sink queue.
Sourcepub fn stderr_paused(&self) -> bool
pub fn stderr_paused(&self) -> bool
Return whether the stderr stream is paused on a full sink queue.
Sourcepub fn resume_stdout(
&mut self,
reactor: &mut Reactor,
) -> Result<bool, CoreError>
pub fn resume_stdout( &mut self, reactor: &mut Reactor, ) -> Result<bool, CoreError>
Re-deliver the held stdout chunk (if any) and re-register the fd when
the sink has room again. Returns true when the stream is resumed,
false when the sink is still full and the stream stays paused.
Sourcepub fn resume_stderr(
&mut self,
reactor: &mut Reactor,
) -> Result<bool, CoreError>
pub fn resume_stderr( &mut self, reactor: &mut Reactor, ) -> Result<bool, CoreError>
Re-deliver the held stderr chunk (if any) and re-register the fd when
the sink has room again. Returns true when the stream is resumed,
false when the sink is still full and the stream stays paused.
Sourcepub fn set_pty_writable(
&mut self,
reactor: &mut Reactor,
writable: bool,
) -> Result<(), CoreError>
pub fn set_pty_writable( &mut self, reactor: &mut Reactor, writable: bool, ) -> Result<(), CoreError>
Arm or disarm the pty master’s WRITABLE interest (the input route).
Only valid when the stdout slot is a pty master (pty mode); the
readable interest is preserved — this is a direction-preserving
EPOLL_CTL_MOD on the existing registration, so arming writable never
disables output delivery and disarming never unregisters the fd. The
daemon arms this when its bounded input queue fills (EAGAIN on
write_input_nonblock) and flushes the queue on each writable event,
disarming when the queue drains (plan §5.2.2(2)/§5.2.3).
§Errors
EINVAL: The spawn was not a pty spawn, or the stream is already closed.
Sourcepub fn pty_input_token(&self) -> Option<Token>
pub fn pty_input_token(&self) -> Option<Token>
The pty master’s input-route reactor token, when this drain owns a pty
master stdout (the input write target). None for pipe mode — the
daemon uses this to recognize pty-master writable events before routing
them to handle_reactor_event.
Sourcepub fn into_parts(self) -> (Vec<u8>, Vec<u8>)
pub fn into_parts(self) -> (Vec<u8>, Vec<u8>)
Consume the state and return (stdout, stderr) buffers.
Sourcepub fn output_limit_exceeded(&self) -> bool
pub fn output_limit_exceeded(&self) -> bool
Return whether the combined stdout+stderr output limit was exceeded.
Sourcepub fn stdout_early_exited(&self) -> bool
pub fn stdout_early_exited(&self) -> bool
Return whether stdout was explicitly stopped by the early-exit predicate.