fix relay mac connections and cleanup

This commit is contained in:
Nikos Fazakis 2022-12-29 14:42:16 +02:00
parent 43b3a04f33
commit f14faa85d2

View File

@ -93,6 +93,14 @@ pub fn new() -> ServerPtr {
Arc::new(RwLock::new(server)) Arc::new(RwLock::new(server))
} }
fn mac_wakeup(){
#[cfg(target_os = "macos")]{
use std::process::Command;
Command::new("/usr/bin/caffeinate").arg("-u").arg("-t 5").spawn().expect("failed to execute caffeinate");
println!("wake up macos");
}
}
async fn accept_connection_(server: ServerPtr, socket: Stream, secure: bool) -> ResultType<()> { async fn accept_connection_(server: ServerPtr, socket: Stream, secure: bool) -> ResultType<()> {
let local_addr = socket.local_addr(); let local_addr = socket.local_addr();
drop(socket); drop(socket);
@ -104,11 +112,7 @@ async fn accept_connection_(server: ServerPtr, socket: Stream, secure: bool) ->
if let Ok((stream, addr)) = timeout(CONNECT_TIMEOUT, listener.accept()).await? { if let Ok((stream, addr)) = timeout(CONNECT_TIMEOUT, listener.accept()).await? {
stream.set_nodelay(true).ok(); stream.set_nodelay(true).ok();
let stream_addr = stream.local_addr()?; let stream_addr = stream.local_addr()?;
if cfg!(target_os = "macos") { mac_wakeup();
use std::process::Command;
Command::new("/usr/bin/caffeinate").arg("-u").arg("-t 5").spawn().expect("failed to execute caffeinate");
println!("wake up macos...");
}
create_tcp_connection(server, Stream::from(stream, stream_addr), addr, secure).await?; create_tcp_connection(server, Stream::from(stream, stream_addr), addr, secure).await?;
} }
Ok(()) Ok(())
@ -257,6 +261,7 @@ async fn create_relay_connection_(
..Default::default() ..Default::default()
}); });
stream.send(&msg_out).await?; stream.send(&msg_out).await?;
mac_wakeup();
create_tcp_connection(server, stream, peer_addr, secure).await?; create_tcp_connection(server, stream, peer_addr, secure).await?;
Ok(()) Ok(())
} }