mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 18:55:32 +00:00
udp: uring: branch less in RecvHelper::parse
This commit is contained in:
parent
aa2c36a373
commit
9bb69627c8
1 changed files with 24 additions and 16 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
cell::UnsafeCell,
|
cell::UnsafeCell,
|
||||||
net::{IpAddr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
|
net::{Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
|
||||||
ptr::null_mut,
|
ptr::null_mut,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ use crate::config::Config;
|
||||||
use super::{SOCKET_IDENTIFIER, USER_DATA_RECV};
|
use super::{SOCKET_IDENTIFIER, USER_DATA_RECV};
|
||||||
|
|
||||||
pub struct RecvHelper {
|
pub struct RecvHelper {
|
||||||
network_address: IpAddr,
|
socket_is_ipv4: bool,
|
||||||
max_scrape_torrents: u8,
|
max_scrape_torrents: u8,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
name_v4: Box<UnsafeCell<libc::sockaddr_in>>,
|
name_v4: Box<UnsafeCell<libc::sockaddr_in>>,
|
||||||
|
|
@ -61,7 +61,7 @@ impl RecvHelper {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
network_address: config.network.address.ip(),
|
socket_is_ipv4: config.network.address.is_ipv4(),
|
||||||
max_scrape_torrents: config.protocol.max_scrape_torrents,
|
max_scrape_torrents: config.protocol.max_scrape_torrents,
|
||||||
name_v4,
|
name_v4,
|
||||||
msghdr_v4,
|
msghdr_v4,
|
||||||
|
|
@ -71,7 +71,7 @@ impl RecvHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_entry(&self, buf_group: u16) -> io_uring::squeue::Entry {
|
pub fn create_entry(&self, buf_group: u16) -> io_uring::squeue::Entry {
|
||||||
let msghdr: *const libc::msghdr = if self.network_address.is_ipv4() {
|
let msghdr: *const libc::msghdr = if self.socket_is_ipv4 {
|
||||||
self.msghdr_v4.get()
|
self.msghdr_v4.get()
|
||||||
} else {
|
} else {
|
||||||
self.msghdr_v6.get()
|
self.msghdr_v6.get()
|
||||||
|
|
@ -86,25 +86,31 @@ impl RecvHelper {
|
||||||
&self,
|
&self,
|
||||||
buffer: &[u8],
|
buffer: &[u8],
|
||||||
) -> (Result<Request, RequestParseError>, CanonicalSocketAddr) {
|
) -> (Result<Request, RequestParseError>, CanonicalSocketAddr) {
|
||||||
let msghdr = unsafe {
|
let (msg, addr) = if self.socket_is_ipv4 {
|
||||||
if self.network_address.is_ipv4() {
|
let msg = unsafe {
|
||||||
&*(self.msghdr_v4.get() as *const _)
|
let msghdr = &*(self.msghdr_v4.get() as *const _);
|
||||||
} else {
|
|
||||||
&*(self.msghdr_v6.get() as *const _)
|
RecvMsgOut::parse(buffer, msghdr).unwrap()
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let msg = RecvMsgOut::parse(buffer, msghdr).unwrap();
|
|
||||||
|
|
||||||
let addr = unsafe {
|
let addr = unsafe {
|
||||||
if self.network_address.is_ipv4() {
|
|
||||||
let name_data = *(msg.name_data().as_ptr() as *const libc::sockaddr_in);
|
let name_data = *(msg.name_data().as_ptr() as *const libc::sockaddr_in);
|
||||||
|
|
||||||
SocketAddr::V4(SocketAddrV4::new(
|
SocketAddr::V4(SocketAddrV4::new(
|
||||||
u32::from_be(name_data.sin_addr.s_addr).into(),
|
u32::from_be(name_data.sin_addr.s_addr).into(),
|
||||||
u16::from_be(name_data.sin_port),
|
u16::from_be(name_data.sin_port),
|
||||||
))
|
))
|
||||||
|
};
|
||||||
|
|
||||||
|
(msg, addr)
|
||||||
} else {
|
} else {
|
||||||
|
let msg = unsafe {
|
||||||
|
let msghdr = &*(self.msghdr_v6.get() as *const _);
|
||||||
|
|
||||||
|
RecvMsgOut::parse(buffer, msghdr).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
let addr = unsafe {
|
||||||
let name_data = *(msg.name_data().as_ptr() as *const libc::sockaddr_in6);
|
let name_data = *(msg.name_data().as_ptr() as *const libc::sockaddr_in6);
|
||||||
|
|
||||||
SocketAddr::V6(SocketAddrV6::new(
|
SocketAddr::V6(SocketAddrV6::new(
|
||||||
|
|
@ -113,7 +119,9 @@ impl RecvHelper {
|
||||||
u32::from_be(name_data.sin6_flowinfo),
|
u32::from_be(name_data.sin6_flowinfo),
|
||||||
u32::from_be(name_data.sin6_scope_id),
|
u32::from_be(name_data.sin6_scope_id),
|
||||||
))
|
))
|
||||||
}
|
};
|
||||||
|
|
||||||
|
(msg, addr)
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue