Skip to content

Commit d312298

Browse files
committed
Implement --close
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 d312298

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ pub struct CommonArgs {
9999
/// The verbosity level. Repeat to increase verbosity.
100100
#[clap(short = 'v', long, action = clap::ArgAction::Count)]
101101
pub verbose: u8,
102+
103+
/// Immediately close our sending side, indicating that we will not transmit any data
104+
#[clap(long)]
105+
pub close: bool,
102106
}
103107

104108
impl CommonArgs {
@@ -323,7 +327,11 @@ async fn listen_stdio(args: ListenArgs) -> Result<()> {
323327
snafu::ensure_whatever!(buf == dumbpipe::HANDSHAKE, "invalid handshake");
324328
}
325329
tracing::info!("forwarding stdin/stdout to {}", remote_node_id);
326-
forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?;
330+
if args.common.close {
331+
forward_bidi(tokio::io::empty(), tokio::io::stdout(), r, s).await?;
332+
} else {
333+
forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?;
334+
}
327335
// stop accepting connections after the first successful one
328336
break;
329337
}
@@ -357,7 +365,11 @@ async fn connect_stdio(args: ConnectArgs) -> Result<()> {
357365
s.write_all(&dumbpipe::HANDSHAKE).await.e()?;
358366
}
359367
tracing::info!("forwarding stdin/stdout to {}", remote_node_id);
360-
forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?;
368+
if args.common.close {
369+
forward_bidi(tokio::io::empty(), tokio::io::stdout(), r, s).await?;
370+
} else {
371+
forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?;
372+
}
361373
tokio::io::stdout().flush().await.e()?;
362374
Ok(())
363375
}

0 commit comments

Comments
 (0)