Skip to main content

run_gridconnect_stream

Function run_gridconnect_stream 

Source
pub async fn run_gridconnect_stream<S>(hub: &Hub, stream: S) -> Result<()>
where S: AsyncRead + AsyncWrite + Unpin,
Available on crate feature hub only.
Expand description

Relay GridConnect text between a byte stream (TCP socket, serial port) and the hub until the stream closes.

Attaches a new port for the lifetime of the call. Incoming bytes are decoded with a Decoder (malformed frames are dropped); outgoing frames are written as \n-terminated GridConnect lines.

Reading and writing run concurrently: while a write to a slow peer is blocked, frames the peer sends are still read and forwarded. Frames for a peer that stays blocked pile up in the shared ring and are eventually skipped for that port (see the module docs).

ยงErrors

Returns Ok(()) when the peer closes the stream (EOF) or the hub is dropped, and the first I/O error from reading or writing otherwise.