Skip to main content

lace_tokio/
transport.rs

1mod stream;
2
3use tokio::io::{AsyncRead, AsyncWrite};
4
5pub use lace_sans_io::core::CarrierRole;
6pub(crate) use stream::{ByteStreamCarrier, TransportIoActivity};
7
8impl crate::ConnectedPeer {
9    /// Adopt an established duplex ILTP byte stream as a move-only peer.
10    ///
11    /// The host completes transport establishment and drains its output before
12    /// adoption. The stream's flush completes once it owns all preceding output
13    /// within bounded buffering; shutdown settles that output or fails.
14    pub fn from_duplex<IO>(
15        role: CarrierRole,
16        io: IO,
17        options: crate::ConnectedPeerOptions,
18    ) -> crate::Result<Self>
19    where
20        IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
21    {
22        let inputs = crate::runtime::connected_inputs(options)?;
23        Ok(Self {
24            lease: crate::runtime::ConnectedTransportLease {
25                transport: Box::new(ByteStreamCarrier::from_duplex(io)),
26                role,
27            },
28            inputs,
29        })
30    }
31
32    /// Adopt established independent ILTP input and output halves.
33    ///
34    /// `reader` is peer-to-local input and `writer` is local-to-peer output.
35    /// The writer's flush completes once it owns all preceding output within
36    /// bounded buffering; shutdown settles that output or fails.
37    pub fn from_split<R, W>(
38        role: CarrierRole,
39        reader: R,
40        writer: W,
41        options: crate::ConnectedPeerOptions,
42    ) -> crate::Result<Self>
43    where
44        R: AsyncRead + Unpin + Send + 'static,
45        W: AsyncWrite + Unpin + Send + 'static,
46    {
47        let inputs = crate::runtime::connected_inputs(options)?;
48        Ok(Self {
49            lease: crate::runtime::ConnectedTransportLease {
50                transport: Box::new(ByteStreamCarrier::from_split(reader, writer)),
51                role,
52            },
53            inputs,
54        })
55    }
56}