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§impl UnixStreamLink
impl UnixStreamLink
Sourcepub fn new() -> Self
pub fn new() -> Self
Create the component with default settings:
-
max_read_unit of 2048
-
Both reads and writes paused
Sourcepub fn set_max_read_unit(&mut self, max_read_unit: usize)
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.
Sourcepub fn set_pause_writes(&mut self, pause: bool)
pub fn set_pause_writes(&mut self, pause: bool)
Pause or unpause writes. This takes effect on the next
process
call.
Sourcepub fn set_pause_reads(&mut self, pause: bool)
pub fn set_pause_reads(&mut self, pause: bool)
Pause or unpause reads. This takes effect on the next
process
call.
Sourcepub fn process(
&mut self,
stream: &mut UnixStream,
pbuf: PBufRdWr<'_>,
) -> Result<bool>
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.
Sourcepub fn process_out(
&mut self,
stream: &mut UnixStream,
pbuf: PBufRdWr<'_>,
) -> Result<bool>
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.
Sourcepub fn process_in(
&mut self,
stream: &mut UnixStream,
pbuf: PBufRdWr<'_>,
) -> Result<bool>
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.