Rollup merge of #104146 - Ayush1325:remote-test-server, r=jyn514
Retry binding TCP Socket in remote-test-server This allows retrying binding TCP Socket multiple times. This is useful when using emulators as network might not be available in the beginning. This was orignally implemented in https://github.com/rust-lang/rust/pull/100316 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
This commit is contained in:
commit
e9b4a84dfa
@ -39,6 +39,8 @@ macro_rules! t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static TEST: AtomicUsize = AtomicUsize::new(0);
|
static TEST: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
const RETRY_INTERVAL: u64 = 1;
|
||||||
|
const NUMBER_OF_RETRIES: usize = 5;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct Config {
|
struct Config {
|
||||||
@ -115,7 +117,7 @@ fn main() {
|
|||||||
let config = Config::parse_args();
|
let config = Config::parse_args();
|
||||||
println!("starting test server");
|
println!("starting test server");
|
||||||
|
|
||||||
let listener = t!(TcpListener::bind(config.bind));
|
let listener = bind_socket(config.bind);
|
||||||
let (work, tmp): (PathBuf, PathBuf) = if cfg!(target_os = "android") {
|
let (work, tmp): (PathBuf, PathBuf) = if cfg!(target_os = "android") {
|
||||||
("/data/local/tmp/work".into(), "/data/local/tmp/work/tmp".into())
|
("/data/local/tmp/work".into(), "/data/local/tmp/work/tmp".into())
|
||||||
} else {
|
} else {
|
||||||
@ -159,6 +161,16 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bind_socket(addr: SocketAddr) -> TcpListener {
|
||||||
|
for _ in 0..(NUMBER_OF_RETRIES - 1) {
|
||||||
|
if let Ok(x) = TcpListener::bind(addr) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(RETRY_INTERVAL));
|
||||||
|
}
|
||||||
|
TcpListener::bind(addr).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_push(socket: TcpStream, work: &Path, config: Config) {
|
fn handle_push(socket: TcpStream, work: &Path, config: Config) {
|
||||||
let mut reader = BufReader::new(socket);
|
let mut reader = BufReader::new(socket);
|
||||||
let dst = recv(&work, &mut reader);
|
let dst = recv(&work, &mut reader);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user