1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-02-26 13:53:52 +01:00

remove hard dependency for tokio net and tokio signal

This commit is contained in:
Akos Vandra 2022-10-10 17:55:36 +02:00
parent c4a0f37d0c
commit 845b465f65
3 changed files with 16 additions and 4 deletions

View File

@ -19,15 +19,16 @@ name = "actix_rt"
path = "src/lib.rs" path = "src/lib.rs"
[features] [features]
default = ["macros"] default = ["macros", "net"]
macros = ["actix-macros"] macros = ["actix-macros"]
io-uring = ["tokio-uring"] io-uring = ["tokio-uring"]
net = ["tokio/net", "tokio/signal"]
[dependencies] [dependencies]
actix-macros = { version = "0.2.3", optional = true } actix-macros = { version = "0.2.3", optional = true }
futures-core = { version = "0.3", default-features = false } futures-core = { version = "0.3", default-features = false }
tokio = { version = "1.13.1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] } tokio = { version = "1.13.1", features = ["rt", "parking_lot", "sync", "time"] }
# runtime for `io-uring` feature # runtime for `io-uring` feature
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]

View File

@ -69,17 +69,19 @@ pub use self::arbiter::{Arbiter, ArbiterHandle};
pub use self::runtime::Runtime; pub use self::runtime::Runtime;
pub use self::system::{System, SystemRunner}; pub use self::system::{System, SystemRunner};
#[cfg(feature = "net")]
pub mod signal { pub mod signal {
//! Asynchronous signal handling (Tokio re-exports). //! Asynchronous signal handling (Tokio re-exports).
#[cfg(unix)] #[cfg(unix)]
pub mod unix { pub mod unix {
//! Unix specific signals (Tokio re-exports). //! Unix specific signals (Tokio re-exports).
pub use tokio::signal::unix::*; // pub use tokio::signal::unix::*;
} }
pub use tokio::signal::ctrl_c; // pub use tokio::signal::ctrl_c;
} }
#[cfg(feature = "net")]
pub mod net { pub mod net {
//! TCP/UDP/Unix bindings (mostly Tokio re-exports). //! TCP/UDP/Unix bindings (mostly Tokio re-exports).

View File

@ -12,6 +12,7 @@ pub struct Runtime {
rt: tokio::runtime::Runtime, rt: tokio::runtime::Runtime,
} }
#[cfg(feature = "net")]
pub(crate) fn default_tokio_runtime() -> io::Result<tokio::runtime::Runtime> { pub(crate) fn default_tokio_runtime() -> io::Result<tokio::runtime::Runtime> {
tokio::runtime::Builder::new_current_thread() tokio::runtime::Builder::new_current_thread()
.enable_io() .enable_io()
@ -19,6 +20,14 @@ pub(crate) fn default_tokio_runtime() -> io::Result<tokio::runtime::Runtime> {
.build() .build()
} }
#[cfg(not(feature = "net"))]
pub(crate) fn default_tokio_runtime() -> io::Result<tokio::runtime::Runtime> {
tokio::runtime::Builder::new_current_thread()
.enable_time()
.build()
}
impl Runtime { impl Runtime {
/// Returns a new runtime initialized with default configuration values. /// Returns a new runtime initialized with default configuration values.
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]