Struct UnixStreamLink

Source
pub struct UnixStreamLink { /* private fields */ }
Expand description

Exchange stream data via the mio UnixStream type

For the incoming Unix stream both “close” and “abort” are detected and passed on. For the Unix outgoing stream, “close” handling is mapped to a normal shutdown on the outgoing half of the Unix stream. The incoming half of the Unix stream, if still open, remains open until the other end closes, as expected.

For outgoing “abort”, this code does a normal shutdown on both incoming and outgoing Unix streams, and does an “abort” on the side of the pipe for incoming Unix-stream data. This should cause rapid shutdown of things locally.

To start with both reading and writing via the Unix stream are paused. So call set_pause_writes(false) or set_pause_reads(false) as soon as the stream indicates “ready” in order to allow data to flow.

Implementations§

Source

pub fn new() -> Self

Create the component with default settings:

  • max_read_unit of 2048

  • Both reads and writes paused

Source

pub fn set_max_read_unit(&mut self, max_read_unit: usize)

Change the maximum number of bytes to read in each process call. This allows managing how much data you wish to handle at a time, to allow the possibility of backpressure, and to control how large the pipe buffers in your processing chain will grow. If memory is not an issue, there is no problem with setting this large, which will likely give higher efficiency.

Source

pub fn set_pause_writes(&mut self, pause: bool)

Pause or unpause writes. This takes effect on the next process call.

Source

pub fn set_pause_reads(&mut self, pause: bool)

Pause or unpause reads. This takes effect on the next process call.

Source

pub fn process( &mut self, stream: &mut UnixStream, pbuf: PBufRdWr<'_>, ) -> Result<bool>

Read and write as much data as possible to and from the given Unix stream. Returns the activity status: Ok(true) if something changed, Ok(false) if no progress could be made, or Err(_) if there was a fatal error on the stream.

Assumes that it is always called with the same UnixStream and pipe-buffer. Things will behave unpredictably otherwise.

Source

pub fn process_out( &mut self, stream: &mut UnixStream, pbuf: PBufRdWr<'_>, ) -> Result<bool>

Write as much data as possible out to the given Unix stream. Returns the activity status: Ok(true) if something changed, Ok(false) if no progress could be made, or Err(_) if there was a fatal error on the stream.

Assumes that it is always called with the same UnixStream and pipe-buffer. Things will behave unpredictably otherwise.

Source

pub fn process_in( &mut self, stream: &mut UnixStream, pbuf: PBufRdWr<'_>, ) -> Result<bool>

Read as much data as possible from to the given Unix stream, up to max_read_unit bytes. Returns the activity status: Ok(true) if something changed, Ok(false) if no progress could be made, or Err(_) if there was a fatal error on the stream.

Assumes that it is always called with the same UnixStream and pipe-buffer. Things will behave unpredictably otherwise.

Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.