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

Function relay_until_eof

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

Relay all bytes from reader to writer until EOF or idle timeout. Used for HTTP responses with no explicit framing (no Content-Length, no Transfer-Encoding) where the body is delimited by connection close. An idle timeout prevents blocking when servers keep the TCP connection alive longer than expected (e.g. CDN keep-alive timers).

(reader: &mut R, writer: &mut W)

Source from the content-addressed store, hash-verified

2316/// An idle timeout prevents blocking when servers keep the TCP connection
2317/// alive longer than expected (e.g. CDN keep-alive timers).
2318async fn relay_until_eof<R, W>(reader: &mut R, writer: &mut W) -> Result<()>
2319where
2320 R: AsyncRead + Unpin,
2321 W: AsyncWrite + Unpin,
2322{
2323 let mut buf = [0u8; RELAY_BUF_SIZE];
2324 loop {
2325 match tokio::time::timeout(RELAY_EOF_IDLE_TIMEOUT, reader.read(&mut buf)).await {
2326 Ok(Ok(0)) => return Ok(()),
2327 Ok(Ok(n)) => {
2328 writer.write_all(&buf[..n]).await.into_diagnostic()?;
2329 writer.flush().await.into_diagnostic()?;
2330 }
2331 Ok(Err(e)) => return Err(miette::miette!("{e}")),
2332 Err(_) => {
2333 debug!(
2334 "relay_until_eof idle timeout after {:?}",
2335 RELAY_EOF_IDLE_TIMEOUT
2336 );
2337 return Ok(());
2338 }
2339 }
2340 }
2341}
2342
2343/// Relay all bytes from reader to writer until EOF without an idle timeout.
2344///

Callers 1

relay_responseFunction · 0.85

Calls 2

readMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected