MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / relay_fixed

Function relay_fixed

crates/openshell-supervisor-network/src/l7/rest.rs:1735–1764  ·  view source on GitHub ↗

Relay exactly `len` bytes from reader to writer.

(
    reader: &mut R,
    writer: &mut W,
    len: u64,
    generation_guard: Option<&PolicyGenerationGuard>,
)

Source from the content-addressed store, hash-verified

1733
1734/// Relay exactly `len` bytes from reader to writer.
1735async fn relay_fixed<R, W>(
1736 reader: &mut R,
1737 writer: &mut W,
1738 len: u64,
1739 generation_guard: Option<&PolicyGenerationGuard>,
1740) -> Result<()>
1741where
1742 R: AsyncRead + Unpin,
1743 W: AsyncWrite + Unpin,
1744{
1745 let mut remaining = len;
1746 let mut buf = [0u8; RELAY_BUF_SIZE];
1747 while remaining > 0 {
1748 let to_read = usize::try_from(remaining)
1749 .unwrap_or(buf.len())
1750 .min(buf.len());
1751 let n = reader.read(&mut buf[..to_read]).await.into_diagnostic()?;
1752 if n == 0 {
1753 return Err(miette!(
1754 "Connection closed with {remaining} bytes remaining"
1755 ));
1756 }
1757 if let Some(guard) = generation_guard {
1758 guard.ensure_current()?;
1759 }
1760 writer.write_all(&buf[..n]).await.into_diagnostic()?;
1761 remaining -= n as u64;
1762 }
1763 Ok(())
1764}
1765
1766/// Relay chunked transfer encoding from reader to writer.
1767///

Callers 2

relay_responseFunction · 0.85

Calls 3

lenMethod · 0.80
ensure_currentMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected