Skip to content

Instantly share code, notes, and snippets.

@leo60228
Created November 10, 2021 17:23
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save leo60228/d3709b9b3a4b5338ef89c98b28ad078e to your computer and use it in GitHub Desktop.
use std::net::ToSocketAddrs;
use std::sync::mpsc::channel;
fn main() {
std::env::set_var("LOCALDOMAIN", "1");
let mut threads = vec![];
let (tx, rx) = channel();
for _ in 0..8 {
let tx = tx.clone();
threads.push(std::thread::spawn(move || {
for i in 0..910000 {
let addr = format!("x-{}:8000", i);
let resolved = addr
.to_socket_addrs()
.ok()
.and_then(|mut x| x.next())
.map(|x| x.to_string())
.unwrap_or_else(Default::default);
tx.send(resolved).unwrap();
}
}));
}
threads.push(std::thread::spawn(|| {
for i in 0..91000000 {
let repeated = "TEST".repeat(i % 10);
std::env::set_var(format!("{}{}", repeated, i), i.to_string());
}
}));
for v in rx {
print!("{}", v);
}
for x in threads {
x.join().unwrap();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment