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>
impl Stream<Reader, Writer>
Sourcepub fn into_halves(self) -> (Reader, Writer)
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>
impl<R: Read, W: Write> Stream<R, W>
Sourcepub fn new(
reader: R,
writer: W,
shutdown: impl FnOnce() + Send + 'static,
) -> Self
pub fn new( reader: R, writer: W, shutdown: impl FnOnce() + Send + 'static, ) -> Self
Bundles the two I/O directions with their shutdown operation.
Sourcepub fn set_write_timeout(self, timeout: Duration) -> Self
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.