pub struct StreamWriters { /* private fields */ }Expand description
Registry of named output streams with ClusterShell EngineClient write
semantics.
Ported behavior (commit cfe0448):
- on EPIPE the stream is removed/closed cleanly at the point of error instead of erroring repeatedly;
- writes (and EOF requests) to an unknown or removed stream are dropped silently, since the stream may have been removed while an event handler is still running.
File descriptors are borrowed: removal never closes the fd; ownership stays with the caller.
Implementations§
Source§impl StreamWriters
impl StreamWriters
Sourcepub fn set_writer(&mut self, sname: &str, fd: RawFd)
pub fn set_writer(&mut self, sname: &str, fd: RawFd)
Register a named write stream over fd (mirrors set_writer).
Registering an existing name resets its buffer and EOF flag.
Sourcepub fn remove(&mut self, sname: &str) -> bool
pub fn remove(&mut self, sname: &str) -> bool
Remove a stream (mirrors Engine.remove_stream). Returns whether a
stream was actually removed.
Sourcepub fn contains(&self, sname: &str) -> bool
pub fn contains(&self, sname: &str) -> bool
Whether a stream with this name is currently registered.
Sourcepub fn write(&mut self, sname: &str, buf: &[u8])
pub fn write(&mut self, sname: &str, buf: &[u8])
Add data to be written to the stream (mirrors EngineClient._write).
Writes to an unknown or already-removed stream are dropped silently (cfe0448): the stream may have been removed on EPIPE while an event handler was still running.
Sourcepub fn set_write_eof(&mut self, sname: &str)
pub fn set_write_eof(&mut self, sname: &str)
Request EOF once the buffer drains (mirrors _set_write_eof).
Unknown streams are ignored, like upstream.
Sourcepub fn buffered_len(&self, sname: &str) -> usize
pub fn buffered_len(&self, sname: &str) -> usize
Bytes still buffered for this stream (0 for unknown streams).
Sourcepub fn pending_fds(&self) -> Vec<RawFd> ⓘ
pub fn pending_fds(&self) -> Vec<RawFd> ⓘ
Fds with pending data or pending EOF — the write-interest set.
Sourcepub fn handle_write(&mut self, sname: &str) -> Result<StreamWriteOutcome>
pub fn handle_write(&mut self, sname: &str) -> Result<StreamWriteOutcome>
Flush a stream’s buffer to its fd (mirrors
EngineClient._handle_write).
- empty buffer + EOF requested → stream removed,
StreamWriteOutcome::Closed - EAGAIN → buffer kept,
StreamWriteOutcome::Pending(retry later) - EPIPE → stream removed at the point of error,
StreamWriteOutcome::BrokenPipe; NOT an error (cfe0448) - other I/O errors are propagated
- full/partial write →
StreamWriteOutcome::Flushed/StreamWriteOutcome::Pending; if EOF was requested and the buffer drained, the stream is removed (StreamWriteOutcome::Closed)