Skip to main content

Stream

Struct Stream 

Source
pub struct Stream<R: Read, W: Write> { /* private fields */ }
Expand description

A duplex byte stream with a shutdown operation for both directions.

Shutdown must release blocked reads, writes and flushes, including reads with no deadline. Socket adapters can shut down the underlying socket. The shutdown operation must return promptly, must not panic, and must not acquire a lock held by a blocked I/O operation. It runs at most once. Neither shutdown nor an I/O operation may call this stream’s closer. Closing would wait for the calling operation itself to return.

Closing refuses further adapter I/O. Admitted operations return their normal results and may succeed while shutdown is in progress. A failed frame send may have moved any prefix of its bytes. A successful write and flush means the adapter took the bytes, not that the peer received or processed them. Data already buffered by the transport may still be received after closing.

Dropping the stream closes it. Passing it to a client or server transfers that responsibility to the transport owner. Closer handles do not keep the reader or writer alive, and dropping a handle does not close the stream.

Implementations§

Source§

impl Stream<Reader, Writer>

Source

pub fn into_halves(self) -> (Reader, Writer)

Takes the reader and writer out of the stream without closing either half.

Each half closes its own direction on drop. Dropping the writer lets the peer drain accepted output before EOF; dropping the reader refuses further peer writes. Obtain a crate::transport::Closer with Self::closer before splitting if you need to shut down both halves from another thread.

The stream’s write timeout is discarded. Any deadlines already installed on the halves are retained; new halves have no deadline until configured.

use darkbio_wire::memory;
use darkbio_wire::transport::Client;

let (host, bus) = memory::duplex(64 * 1024);
let (reader, writer) = bus.into_halves();
let client = Client::new(host);
// Move `reader` and `writer` to the bus's input and output pumps.
Source§

impl<R: Read, W: Write> Stream<R, W>

Source

pub fn new( reader: R, writer: W, shutdown: impl FnOnce() + Send + 'static, ) -> Self

Bundles the two I/O directions with their shutdown operation.

Source

pub fn set_write_timeout(self, timeout: Duration) -> Self

Sets the budget for writing and flushing one complete frame, including any delimiter needed after failed output. Progress does not restart it. The budget begins after acquiring the writer and includes frame encoding. Waiting for locks, encryption and peer replies is outside this budget. Handshake frames also share the overall handshake deadline, which can shorten this write budget.

Zero refuses output immediately. A duration too large to add to an Instant panics when an outgoing frame’s deadline is constructed.

Source

pub fn closer(&self) -> Closer

A handle that can close the stream from another thread.

Source

pub fn close(&self)

Permanently closes the stream and waits for shutdown and admitted adapter operations to finish. Concurrent close calls wait for the same completion.

Trait Implementations§

Source§

impl<R: Read, W: Write> Debug for Stream<R, W>

Source§

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

Shows the write budget and the shutdown state, never the adapters.

Source§

impl<R: Read, W: Write> Drop for Stream<R, W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<R, W> Freeze for Stream<R, W>

§

impl<R, W> RefUnwindSafe for Stream<R, W>

§

impl<R, W> Send for Stream<R, W>
where Option<(R, W)>: Send,

§

impl<R, W> Sync for Stream<R, W>
where Option<(R, W)>: Sync,

§

impl<R, W> Unpin for Stream<R, W>

§

impl<R, W> UnsafeUnpin for Stream<R, W>

§

impl<R, W> UnwindSafe for Stream<R, W>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more