Skip to content

Commit

Permalink
0 (OK) exitcode if Ctrl-C
Browse files Browse the repository at this point in the history
  • Loading branch information
slivingston committed Sep 14, 2024
1 parent 908aec6 commit 29aad72
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ serde_json = "1.0"
serde_yaml = "0.8"
tempfile = "3.1"

tokio = { version = "1.40", features = ["net", "rt"] }
tokio = { version = "1.40", features = ["net", "rt", "signal"] }

[target.'cfg(target_os="linux")'.dependencies]
v4l = { version = "0.14", features = ["v4l2"] }
Expand Down
51 changes: 38 additions & 13 deletions src/bin/rrhttp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern crate log;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
use tokio::runtime::Builder;
use tokio::{signal, time};

async fn x_to_y_nofilter(
prefix: String,
Expand Down Expand Up @@ -107,21 +108,45 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let listener = TcpListener::bind("127.0.0.1:0").await?;
println!("{}", listener.local_addr()?);

loop {
let (ingress, _) = listener.accept().await?;
ingress.set_nodelay(true)?;
tokio::spawn(async move {
loop {
let (ingress, _) = match listener.accept().await {
Ok(x) => x,
Err(err) => {
error!(
"error on accept connection: {}; sleeping and looping...",
err
);
time::sleep(std::time::Duration::from_millis(1000)).await;
continue;
}
};
match ingress.set_nodelay(true) {
Ok(()) => (),
Err(err) => {
warn!("unable to set TCP NODELAY on ingress: {}", err)
}
};

let egress = match TcpStream::connect(targetaddr.clone()).await {
Ok(c) => c,
Err(err) => {
error!("unable to connect to target: {}", err);
continue;
}
};
egress.set_nodelay(true)?;
let egress = match TcpStream::connect(targetaddr.clone()).await {
Ok(c) => c,
Err(err) => {
error!("unable to connect to target: {}", err);
continue;
}
};
match egress.set_nodelay(true) {
Ok(()) => (),
Err(err) => {
warn!("unable to set TCP NODELAY on egress: {}", err)
}
};

tokio::spawn(main_per(ingress, egress));
}
tokio::spawn(main_per(ingress, egress));
}
});

signal::ctrl_c().await?;

Ok(())
})
Expand Down

0 comments on commit 29aad72

Please sign in to comment.