diff --git a/aquatic_udp/Cargo.toml b/aquatic_udp/Cargo.toml index 7c55a5a..d7a7b90 100644 --- a/aquatic_udp/Cargo.toml +++ b/aquatic_udp/Cargo.toml @@ -18,7 +18,8 @@ name = "aquatic_udp" default = ["with-mio"] cpu-pinning = ["aquatic_common/cpu-pinning"] with-glommio = ["cpu-pinning", "glommio", "futures-lite"] -with-mio = ["crossbeam-channel", "histogram", "mio", "socket2", "io-uring", "libc", "bytemuck"] +with-mio = ["crossbeam-channel", "histogram", "mio", "socket2"] +with-io-uring = ["crossbeam-channel", "histogram", "socket2", "io-uring", "libc", "bytemuck"] [dependencies] anyhow = "1" @@ -35,11 +36,15 @@ serde = { version = "1", features = ["derive"] } slab = "0.4" signal-hook = { version = "0.3" } -# mio +# mio / io-uring crossbeam-channel = { version = "0.5", optional = true } histogram = { version = "0.6", optional = true } -mio = { version = "0.7", features = ["udp", "os-poll", "os-util"], optional = true } socket2 = { version = "0.4.1", features = ["all"], optional = true } + +# mio +mio = { version = "0.7", features = ["udp", "os-poll", "os-util"], optional = true } + +# io-uring io-uring = { version = "0.5", optional = true } libc = { version = "0.2", optional = true } bytemuck = { version = "1", optional = true } diff --git a/aquatic_udp/src/lib/lib.rs b/aquatic_udp/src/lib/lib.rs index 34e25a8..2f3c924 100644 --- a/aquatic_udp/src/lib/lib.rs +++ b/aquatic_udp/src/lib/lib.rs @@ -5,7 +5,7 @@ pub mod config; #[cfg(all(feature = "with-glommio", target_os = "linux"))] pub mod glommio; #[cfg(feature = "with-mio")] -pub mod mio; +pub mod other; use config::Config; @@ -16,7 +16,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> { if #[cfg(all(feature = "with-glommio", target_os = "linux"))] { glommio::run(config) } else { - mio::run(config) + other::run(config) } } } diff --git a/aquatic_udp/src/lib/mio/common.rs b/aquatic_udp/src/lib/other/common.rs similarity index 100% rename from aquatic_udp/src/lib/mio/common.rs rename to aquatic_udp/src/lib/other/common.rs diff --git a/aquatic_udp/src/lib/mio/handlers.rs b/aquatic_udp/src/lib/other/handlers.rs similarity index 99% rename from aquatic_udp/src/lib/mio/handlers.rs rename to aquatic_udp/src/lib/other/handlers.rs index 7019b98..0c2c5f2 100644 --- a/aquatic_udp/src/lib/mio/handlers.rs +++ b/aquatic_udp/src/lib/other/handlers.rs @@ -9,7 +9,7 @@ use aquatic_udp_protocol::*; use crate::common::handlers::*; use crate::config::Config; -use crate::mio::common::*; +use crate::other::common::*; pub fn run_request_worker( state: State, diff --git a/aquatic_udp/src/lib/mio/mod.rs b/aquatic_udp/src/lib/other/mod.rs similarity index 84% rename from aquatic_udp/src/lib/mio/mod.rs rename to aquatic_udp/src/lib/other/mod.rs index c7da3e1..c526492 100644 --- a/aquatic_udp/src/lib/mio/mod.rs +++ b/aquatic_udp/src/lib/other/mod.rs @@ -16,7 +16,7 @@ use crate::config::Config; pub mod common; pub mod handlers; -pub mod network; +pub mod network_mio; pub mod network_uring; pub mod tasks; @@ -99,13 +99,25 @@ pub fn run_inner(config: Config, state: State) -> ::anyhow::Result<()> { WorkerIndex::SocketWorker(i), ); - network_uring::run_socket_worker( - state, - config, - i, - request_sender, - response_receiver, - num_bound_sockets, + cfg_if::cfg_if!( + if #[cfg(feature = "with-io-uring")] { + network_uring::run_socket_worker( + state, + config, + request_sender, + response_receiver, + num_bound_sockets, + ) + } else if #[cfg(feature = "with-mio")] { + network_mio::run_socket_worker( + state, + config, + i, + request_sender, + response_receiver, + num_bound_sockets, + ) + } ) }) .with_context(|| "spawn socket worker")?; diff --git a/aquatic_udp/src/lib/mio/network.rs b/aquatic_udp/src/lib/other/network_mio.rs similarity index 100% rename from aquatic_udp/src/lib/mio/network.rs rename to aquatic_udp/src/lib/other/network_mio.rs diff --git a/aquatic_udp/src/lib/mio/network_uring.rs b/aquatic_udp/src/lib/other/network_uring.rs similarity index 99% rename from aquatic_udp/src/lib/mio/network_uring.rs rename to aquatic_udp/src/lib/other/network_uring.rs index 078461a..cae1923 100644 --- a/aquatic_udp/src/lib/mio/network_uring.rs +++ b/aquatic_udp/src/lib/other/network_uring.rs @@ -1,6 +1,6 @@ use std::io::Cursor; use std::mem::size_of; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4}; use std::os::unix::prelude::AsRawFd; use std::ptr::null_mut; use std::sync::{ @@ -13,7 +13,9 @@ use aquatic_common::access_list::{create_access_list_cache, AccessListCache}; use crossbeam_channel::{Receiver, Sender}; use io_uring::types::{Fixed, Timespec}; use io_uring::SubmissionQueue; -use libc::{AF_INET, AF_INET6, c_void, in6_addr, in_addr, iovec, msghdr, sockaddr_in, sockaddr_in6}; +use libc::{ + c_void, in6_addr, in_addr, iovec, msghdr, sockaddr_in, sockaddr_in6, AF_INET, AF_INET6, +}; use rand::prelude::{Rng, SeedableRng, StdRng}; use slab::Slab; use socket2::{Domain, Protocol, Socket, Type}; @@ -103,7 +105,6 @@ impl Into for UserData { pub fn run_socket_worker( state: State, config: Config, - token_num: usize, request_sender: Sender<(ConnectedRequest, SocketAddr)>, response_receiver: Receiver<(ConnectedResponse, SocketAddr)>, num_bound_sockets: Arc, diff --git a/aquatic_udp/src/lib/mio/tasks.rs b/aquatic_udp/src/lib/other/tasks.rs similarity index 100% rename from aquatic_udp/src/lib/mio/tasks.rs rename to aquatic_udp/src/lib/other/tasks.rs diff --git a/aquatic_udp_bench/src/main.rs b/aquatic_udp_bench/src/main.rs index 28c210e..6d294e2 100644 --- a/aquatic_udp_bench/src/main.rs +++ b/aquatic_udp_bench/src/main.rs @@ -15,8 +15,8 @@ use std::time::Duration; use aquatic_cli_helpers::run_app_with_cli_and_config; use aquatic_udp::common::*; use aquatic_udp::config::Config; -use aquatic_udp::mio::common::*; -use aquatic_udp::mio::handlers; +use aquatic_udp::other::common::*; +use aquatic_udp::other::handlers; use config::BenchConfig;