From 02869e3041cf7c30d8cb71c967931352dea66b80 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Fri, 23 Sep 2022 14:53:38 +0200 Subject: [PATCH] replace --remote with the --bind flag in remote-test-server --- src/tools/remote-test-server/src/main.rs | 32 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/tools/remote-test-server/src/main.rs b/src/tools/remote-test-server/src/main.rs index 8164b2b29ee6..058cf9a911a9 100644 --- a/src/tools/remote-test-server/src/main.rs +++ b/src/tools/remote-test-server/src/main.rs @@ -12,6 +12,7 @@ #[cfg(not(windows))] use std::fs::Permissions; +use std::net::SocketAddr; #[cfg(not(windows))] use std::os::unix::prelude::*; @@ -41,26 +42,41 @@ static TEST: AtomicUsize = AtomicUsize::new(0); #[derive(Copy, Clone)] struct Config { - remote: bool, verbose: bool, + bind: SocketAddr, } impl Config { pub fn default() -> Config { - Config { remote: false, verbose: false } + Config { + verbose: false, + bind: if cfg!(target_os = "android") || cfg!(windows) { + ([0, 0, 0, 0], 12345).into() + } else { + ([10, 0, 2, 15], 12345).into() + }, + } } pub fn parse_args() -> Config { let mut config = Config::default(); let args = env::args().skip(1); + let mut next_is_bind = false; for argument in args { match &argument[..] { - "--remote" => config.remote = true, + bind if next_is_bind => { + config.bind = t!(bind.parse()); + next_is_bind = false; + } + "--bind" => next_is_bind = true, "--verbose" | "-v" => config.verbose = true, arg => panic!("unknown argument: {}", arg), } } + if next_is_bind { + panic!("missing value for --bind"); + } config } @@ -77,13 +93,7 @@ fn main() { let config = Config::parse_args(); - let bind_addr = if cfg!(target_os = "android") || cfg!(windows) || config.remote { - "0.0.0.0:12345" - } else { - "10.0.2.15:12345" - }; - - let listener = t!(TcpListener::bind(bind_addr)); + let listener = t!(TcpListener::bind(config.bind)); let (work, tmp): (PathBuf, PathBuf) = if cfg!(target_os = "android") { ("/data/tmp/work".into(), "/data/tmp/work/tmp".into()) } else { @@ -93,7 +103,7 @@ fn main() { tmp_dir.push("tmp"); (work_dir, tmp_dir) }; - println!("listening on {}!", bind_addr); + println!("listening on {}!", config.bind); t!(fs::create_dir_all(&work)); t!(fs::create_dir_all(&tmp));