aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-03-24 17:11:02 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-03-24 17:11:16 +0100
commit6edef687446af8b0c88cf794aadab38c89fba514 (patch)
tree247016379a839eef58244e210fd7e5a4c3846b07
parent8e45b18354e6edf8771c205d9e8f91cfe3ea21a3 (diff)
only launch ppp2tun, tun2ppp and write_config threads once
-rw-r--r--src/main.rs40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/main.rs b/src/main.rs
index 9b9c9cf..1752d81 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -88,33 +88,31 @@ fn main() -> Result<()> {
let (send_tx, send_rx) = mpsc::channel();
let send_rx = Arc::new(Mutex::new(send_rx));
- loop {
- println!("connecting...");
+ let send_tx2 = send_tx.clone();
+ let tun2 = tun.clone();
- let clt = Client::new(config.clone())?;
+ thread::spawn(move || match tun2ppp(send_tx2, tun2) {
+ Ok(_) => {}
+ Err(e) => panic!("tun2ppp error: {}", e),
+ });
- let recv_rx2 = recv_rx.clone();
- let send_tx2 = send_tx.clone();
- let tun2 = tun.clone();
- let tun3 = tun.clone();
+ thread::spawn(move || match ppp2tun(recv_rx, tun) {
+ Ok(_) => {}
+ Err(e) => panic!("ppp2tun error: {}", e),
+ });
- thread::spawn(move || match tun2ppp(send_tx2, tun2) {
- Ok(_) => {}
- Err(e) => panic!("tun2ppp error: {}", e),
- });
+ let (ipchange_tx, ipchange_rx) = mpsc::channel();
+ thread::spawn(move || match write_config(ipchange_rx) {
+ Ok(_) => {}
+ Err(e) => panic!("write_config error: {}", e),
+ });
- thread::spawn(move || match ppp2tun(recv_rx2, tun3) {
- Ok(_) => {}
- Err(e) => panic!("ppp2tun error: {}", e),
- });
+ loop {
+ println!("connecting...");
- let (ipchange_tx, ipchange_rx) = mpsc::channel();
- thread::spawn(move || match write_config(ipchange_rx) {
- Ok(_) => {}
- Err(e) => panic!("write_config error: {}", e),
- });
+ let clt = Client::new(config.clone())?;
- clt.run(recv_tx.clone(), send_rx.clone(), ipchange_tx)?;
+ clt.run(recv_tx.clone(), send_rx.clone(), ipchange_tx.clone())?;
send_tx.send(None)?;
println!("connection lost");