pub struct Connection<S> { /* private fields */ }Expand description
One connection: length-prefixed postcard frames over S, the Unix socket on this machine.
Split into its halves, each is a Connection that only sends or only receives, so a WaOS
sends a program’s output on one task while another watches for the connection closing.
Implementations§
Source§impl<S> Connection<S>
impl<S> Connection<S>
pub fn new(stream: S) -> Connection<S>
Source§impl<S: AsyncRead + AsyncWrite + Unpin> Connection<S>
impl<S: AsyncRead + AsyncWrite + Unpin> Connection<S>
Sourcepub async fn agree_on_protocol(&mut self) -> Result<()>
pub async fn agree_on_protocol(&mut self) -> Result<()>
The first frame each way: says this build’s PROTOCOL, and reads the other side’s
before anything else. When they differ the connection is done, and the error, of kind
Unsupported, names both numbers; cargo waos prints it. An other side that closed
before saying its number is UnexpectedEof, or BrokenPipe when it was gone before this
side’s frame went out.
Source§impl<S: AsyncWrite + Unpin> Connection<S>
impl<S: AsyncWrite + Unpin> Connection<S>
Source§impl<S: AsyncRead + Unpin> Connection<S>
impl<S: AsyncRead + Unpin> Connection<S>
Sourcepub async fn receive<M: DeserializeOwned>(&mut self) -> Result<Option<M>>
pub async fn receive<M: DeserializeOwned>(&mut self) -> Result<Option<M>>
The next message; none once the other side closed between frames.
Source§impl Connection<UnixStream>
impl Connection<UnixStream>
Sourcepub async fn connect(path: &Path) -> Result<Connection<UnixStream>>
pub async fn connect(path: &Path) -> Result<Connection<UnixStream>>
Connects to the WaOS listening at path: NotFound or ConnectionRefused when none is.
Sourcepub fn into_split(
self,
) -> (Connection<OwnedReadHalf>, Connection<OwnedWriteHalf>)
pub fn into_split( self, ) -> (Connection<OwnedReadHalf>, Connection<OwnedWriteHalf>)
The two halves, to receive on one task while another sends.