Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple TCP listeners #32

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/bin/givc-admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ use tracing::debug;
#[command(about = "A givc admin", long_about = None)]
struct Cli {
#[arg(long, env = "ADDR", default_missing_value = "127.0.0.1")]
addr: String,
addr: Option<String>,
#[arg(long, env = "PORT", default_missing_value = "9000", value_parser = clap::value_parser!(u16).range(1..))]
port: u16,
port: Option<u16>,

#[arg(long, help = "Additionally listen TCP socket (addr:port)")]
listen_tcp: Option<Vec<SocketAddr>>,

#[arg(long, help = "Additionally listen UNIX socket (path)")]
unix: Option<String>,
listen_unix: Option<Vec<String>>,

#[arg(long, help = "Additionally listen Vsock socket (cid:port format)")]
vsock: Option<String>,
Expand Down Expand Up @@ -51,8 +54,6 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();
debug!("CLI is {:#?}", cli);

let addr = SocketAddr::new(cli.addr.parse().unwrap(), cli.port);

let mut builder = Server::builder();

let tls = if cli.use_tls {
Expand All @@ -79,13 +80,25 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {

let sys_opts = tokio_listener::SystemOptions::default();
let user_opts = tokio_listener::UserOptions::default();
let tcp_addr = tokio_listener::ListenerAddress::Tcp(addr);

let mut addrs = vec![tcp_addr];
let mut addrs: Vec<tokio_listener::ListenerAddress> = Vec::new();

if let (Some(addr), Some(port)) = (cli.addr, cli.port) {
let addr = SocketAddr::new(addr.parse().unwrap(), port);
addrs.push(tokio_listener::ListenerAddress::Tcp(addr))
}

if let Some(tcp_addrs) = cli.listen_tcp {
for each in tcp_addrs {
addrs.push(tokio_listener::ListenerAddress::Tcp(each))
}
}

if let Some(unix_sock) = cli.unix {
let unix_sock_addr = tokio_listener::ListenerAddress::Path(unix_sock.into());
addrs.push(unix_sock_addr)
if let Some(unix_socks) = cli.listen_unix {
for unix_sock in unix_socks {
let unix_sock_addr = tokio_listener::ListenerAddress::Path(unix_sock.into());
addrs.push(unix_sock_addr)
}
}

if let Some(vsock) = cli.vsock {
Expand Down