udp: add io-uring implementation

This commit is contained in:
Joakim Frostegård 2021-11-14 02:47:15 +01:00
parent efbf51ba19
commit 18635bf26c
9 changed files with 37 additions and 19 deletions

View file

@ -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)
}
}
}

View file

@ -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,

View file

@ -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")?;

View file

@ -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<u64> 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<AtomicUsize>,