diff --git a/Cargo.lock b/Cargo.lock index f41d5fc..29f7ecd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,6 +29,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "boxfnonce" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5988cb1d626264ac94100be357308f29ff7cbdd3b36bda27f450a4ee3f713426" + [[package]] name = "bumpalo" version = "3.9.1" @@ -66,6 +72,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "daemonize" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70c24513e34f53b640819f0ac9f705b673fcf4006d7aab8778bee72ebfc89815" +dependencies = [ + "boxfnonce", + "libc", +] + [[package]] name = "digest" version = "0.10.3" @@ -148,6 +164,7 @@ dependencies = [ "anyhow", "kaminari 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "realm_io", + "realm_syscall", "tokio", ] @@ -316,14 +333,25 @@ dependencies = [ [[package]] name = "realm_io" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6acf08c84d59f96c48b46d5e8bce63d311469a9e43ee971a246344f6ad4d081b" +checksum = "765e31d68e3708d65d98c7f66023c3715711614553ec279499ef5c1a2544e256" dependencies = [ "libc", "tokio", ] +[[package]] +name = "realm_syscall" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd1c4fd7ea55ef4a956906e911f99250f51154f25f699aca154d9cefe94a7c9a" +dependencies = [ + "daemonize", + "libc", + "socket2", +] + [[package]] name = "ring" version = "0.16.20" diff --git a/cmd/Cargo.toml b/cmd/Cargo.toml index ec2acc5..91829f4 100644 --- a/cmd/Cargo.toml +++ b/cmd/Cargo.toml @@ -10,7 +10,8 @@ license = "GPL-3.0" [dependencies] anyhow = "1" -realm_io = "0.3.2" +realm_io = "0.3.4" +realm_syscall = "0.1.6" kaminari = { version = "0.9.2", features = ["ws"] } tokio = { version = "1.9", features = ["rt", "net", "macros"] } diff --git a/cmd/src/client.rs b/cmd/src/client.rs index f8de4a8..44f9ac3 100644 --- a/cmd/src/client.rs +++ b/cmd/src/client.rs @@ -9,7 +9,7 @@ use kaminari::trick::Ref; use kaminari::AsyncConnect; use kaminari::nop::NopConnect; use kaminari::ws::WsConnect; -#[cfg(any(feature="tls-rustls", feature="tls-openssl"))] +#[cfg(any(feature = "tls-rustls", feature = "tls-openssl"))] use kaminari::tls::TlsConnect; use kaminari_cmd::{Endpoint, parse_cmd, parse_env}; @@ -19,7 +19,7 @@ async fn main() -> Result<()> { let (Endpoint { local, remote }, options) = parse_env().or_else(|_| parse_cmd())?; let ws = opt::get_ws_conf(&options); - #[cfg(any(feature="tls-rustls", feature="tls-openssl"))] + #[cfg(any(feature = "tls-rustls", feature = "tls-openssl"))] let tls = opt::get_tls_client_conf(&options); eprintln!("listen: {}", &local); @@ -29,13 +29,16 @@ async fn main() -> Result<()> { eprintln!("ws: {}", ws) } - #[cfg(any(feature="tls-rustls", feature="tls-openssl"))] + #[cfg(any(feature = "tls-rustls", feature = "tls-openssl"))] if let Some(tls) = &tls { eprintln!("tls: {}", &tls); } let lis = TcpListener::bind(local).await?; + #[cfg(all(unix, not(target_os = "android")))] + let _ = realm_syscall::bump_nofile_limit(); + macro_rules! run { ($cc: expr) => { println!("connect: {}", $cc.as_ref()); @@ -75,7 +78,7 @@ async fn main() -> Result<()> { } } - #[cfg(any(feature="tls-rustls", feature="tls-openssl"))] + #[cfg(any(feature = "tls-rustls", feature = "tls-openssl"))] match (ws, tls) { (None, None) => { let client = NopConnect {}; @@ -95,7 +98,7 @@ async fn main() -> Result<()> { } }; - #[cfg(not(any(feature="tls-rustls", feature="tls-openssl")))] + #[cfg(not(any(feature = "tls-rustls", feature = "tls-openssl")))] if let Some(ws) = ws { let client = WsConnect::new(NopConnect {}, ws); run_ws_each!(client); diff --git a/cmd/src/server.rs b/cmd/src/server.rs index b18206c..93d0d62 100644 --- a/cmd/src/server.rs +++ b/cmd/src/server.rs @@ -9,7 +9,7 @@ use kaminari::trick::Ref; use kaminari::AsyncAccept; use kaminari::nop::NopAccept; use kaminari::ws::WsAccept; -#[cfg(any(feature="tls-rustls", feature="tls-openssl"))] +#[cfg(any(feature = "tls-rustls", feature = "tls-openssl"))] use kaminari::tls::TlsAccept; use kaminari_cmd::{Endpoint, parse_cmd, parse_env}; @@ -30,7 +30,7 @@ async fn main() -> Result<()> { let ws = opt::get_ws_conf(&options); - #[cfg(any(feature="tls-rustls", feature="tls-openssl"))] + #[cfg(any(feature = "tls-rustls", feature = "tls-openssl"))] let tls = opt::get_tls_server_conf(&options); eprintln!("listen: {}", &local); @@ -40,13 +40,16 @@ async fn main() -> Result<()> { eprintln!("ws: {}", ws) } - #[cfg(any(feature="tls-rustls", feature="tls-openssl"))] + #[cfg(any(feature = "tls-rustls", feature = "tls-openssl"))] if let Some(tls) = &tls { eprintln!("tls: {}", &tls); } let lis = TcpListener::bind(local).await?; + #[cfg(all(unix, not(target_os = "android")))] + let _ = realm_syscall::bump_nofile_limit(); + macro_rules! run { ($ac: expr) => { println!("accept: {}", $ac.as_ref()); @@ -64,7 +67,7 @@ async fn main() -> Result<()> { }; } - #[cfg(any(feature="tls-rustls", feature="tls-openssl"))] + #[cfg(any(feature = "tls-rustls", feature = "tls-openssl"))] match (ws, tls) { (None, None) => { let server = NopAccept {}; @@ -84,7 +87,7 @@ async fn main() -> Result<()> { } }; - #[cfg(not(any(feature="tls-rustls", feature="tls-openssl")))] + #[cfg(not(any(feature = "tls-rustls", feature = "tls-openssl")))] if let Some(ws) = ws { let server = WsAccept::new(NopAccept {}, ws); run!(Ref::new(&server));