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

Function copy_ws_to_tcp

crates/openshell-cli/src/edge_tunnel.rs:217–245  ·  view source on GitHub ↗

Copy bytes from WebSocket binary frames into a local TCP writer.

(
    mut ws_source: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
    mut tcp_write: tokio::io::WriteHalf<TcpStream>,
)

Source from the content-addressed store, hash-verified

215
216/// Copy bytes from WebSocket binary frames into a local TCP writer.
217async fn copy_ws_to_tcp(
218 mut ws_source: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
219 mut tcp_write: tokio::io::WriteHalf<TcpStream>,
220) {
221 while let Some(msg) = ws_source.next().await {
222 match msg {
223 Ok(Message::Binary(data)) => {
224 if tcp_write.write_all(&data).await.is_err() {
225 break;
226 }
227 }
228 Ok(Message::Close(_)) => break,
229 Ok(Message::Ping(_) | Message::Pong(_) | Message::Frame(_)) => {
230 // Handled automatically by tungstenite.
231 }
232 Ok(Message::Text(text)) => {
233 // Some proxies send text frames — treat as binary.
234 if tcp_write.write_all(text.as_bytes()).await.is_err() {
235 break;
236 }
237 }
238 Err(e) => {
239 debug!(error = %e, "ws read error");
240 break;
241 }
242 }
243 }
244 let _ = tcp_write.shutdown().await;
245}

Callers 1

handle_connectionFunction · 0.85

Calls 1

nextMethod · 0.45

Tested by

no test coverage detected