replace --remote with the --bind flag in remote-test-server
This commit is contained in:
parent
c057d04b92
commit
02869e3041
1 changed files with 21 additions and 11 deletions
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue