Skip to content

Commit b8aef96

Browse files
committed
Implement --recv-only
This option causes the sending side to not send any data and instead immeditally send an EOF. This can be useful when you are only interested in sending data in one direction. Closes #10
1 parent fc6a9b0 commit b8aef96

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/main.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ fn parse_alpn(alpn: &str) -> Result<Vec<u8>> {
124124

125125
#[derive(Parser, Debug)]
126126
pub struct ListenArgs {
127+
/// Immediately close our sending side, indicating that we will not transmit any data
128+
#[clap(long)]
129+
pub recv_only: bool,
130+
127131
#[clap(flatten)]
128132
pub common: CommonArgs,
129133
}
@@ -157,6 +161,10 @@ pub struct ConnectArgs {
157161
/// The node to connect to
158162
pub ticket: NodeTicket,
159163

164+
/// Immediately close our sending side, indicating that we will not transmit any data
165+
#[clap(long)]
166+
pub recv_only: bool,
167+
160168
#[clap(flatten)]
161169
pub common: CommonArgs,
162170
}
@@ -323,7 +331,11 @@ async fn listen_stdio(args: ListenArgs) -> Result<()> {
323331
snafu::ensure_whatever!(buf == dumbpipe::HANDSHAKE, "invalid handshake");
324332
}
325333
tracing::info!("forwarding stdin/stdout to {}", remote_node_id);
326-
forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?;
334+
if args.recv_only {
335+
forward_bidi(tokio::io::empty(), tokio::io::stdout(), r, s).await?;
336+
} else {
337+
forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?;
338+
}
327339
// stop accepting connections after the first successful one
328340
break;
329341
}
@@ -357,7 +369,11 @@ async fn connect_stdio(args: ConnectArgs) -> Result<()> {
357369
s.write_all(&dumbpipe::HANDSHAKE).await.e()?;
358370
}
359371
tracing::info!("forwarding stdin/stdout to {}", remote_node_id);
360-
forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?;
372+
if args.recv_only {
373+
forward_bidi(tokio::io::empty(), tokio::io::stdout(), r, s).await?;
374+
} else {
375+
forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?;
376+
}
361377
tokio::io::stdout().flush().await.e()?;
362378
Ok(())
363379
}

0 commit comments

Comments
 (0)