Skip to main content

StreamWriters

Struct StreamWriters 

Source
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

Source

pub fn new() -> Self

Create an empty stream registry.

Source

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.

Source

pub fn remove(&mut self, sname: &str) -> bool

Remove a stream (mirrors Engine.remove_stream). Returns whether a stream was actually removed.

Source

pub fn contains(&self, sname: &str) -> bool

Whether a stream with this name is currently registered.

Source

pub fn len(&self) -> usize

Number of registered streams.

Source

pub fn is_empty(&self) -> bool

Whether there are no registered streams.

Source

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.

Source

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.

Source

pub fn buffered_len(&self, sname: &str) -> usize

Bytes still buffered for this stream (0 for unknown streams).

Source

pub fn pending_fds(&self) -> Vec<RawFd> ⓘ

Fds with pending data or pending EOF — the write-interest set.

Source

pub fn handle_write(&mut self, sname: &str) -> Result<StreamWriteOutcome>

Flush a stream’s buffer to its fd (mirrors EngineClient._handle_write).

Trait Implementations§

Source§

impl Debug for StreamWriters

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StreamWriters

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.