Skip to content

Commit

Permalink
perf(udp): multi-message receive on apple (#2302)
Browse files Browse the repository at this point in the history
* feat(udp): multi-message receive on apple

* docs: improve platforms with segmentation offloading line

* refactor: use cfg_aliases

* tests: empty datagram on apple

---------

Co-authored-by: Lars Eggert <[email protected]>
  • Loading branch information
mxinden and larseggert authored Jan 9, 2025
1 parent 17c4103 commit 3c48567
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 103 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ rust-version = "1.76.0"
enum-map = { version = "2.7", default-features = false }
log = { version = "0.4", default-features = false }
qlog = { version = "0.13", default-features = false }
quinn-udp = { version = "0.5.6", default-features = false, features = ["direct-log"] }
quinn-udp = { version = "0.5.6", default-features = false, features = ["direct-log", "fast-apple-datapath"] }
regex = { version = "1.9", default-features = false, features = ["unicode-perl"] }
static_assertions = { version = "1.1", default-features = false }
url = { version = "2.5.3", default-features = false, features = ["std"] }
Expand Down
8 changes: 3 additions & 5 deletions neqo-bin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use neqo_crypto::{
};
use neqo_http3::Output;
use neqo_transport::{AppError, CloseReason, ConnectionId, Version};
use neqo_udp::RecvBuf;
use tokio::time::Sleep;
use url::{Host, Origin, Url};

Expand Down Expand Up @@ -394,7 +395,7 @@ struct Runner<'a, H: Handler> {
handler: H,
timeout: Option<Pin<Box<Sleep>>>,
args: &'a Args,
recv_buf: Vec<u8>,
recv_buf: RecvBuf,
}

impl<'a, H: Handler> Runner<'a, H> {
Expand All @@ -412,7 +413,7 @@ impl<'a, H: Handler> Runner<'a, H> {
handler,
args,
timeout: None,
recv_buf: vec![0; neqo_udp::RECV_BUF_SIZE],
recv_buf: RecvBuf::new(),
}
}

Expand Down Expand Up @@ -481,9 +482,6 @@ impl<'a, H: Handler> Runner<'a, H> {
let Some(dgrams) = self.socket.recv(self.local_addr, &mut self.recv_buf)? else {
break;
};
if dgrams.len() == 0 {
break;
}
self.client.process_multiple_input(dgrams, Instant::now());
self.process_output().await?;
}
Expand Down
5 changes: 3 additions & 2 deletions neqo-bin/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use neqo_crypto::{
init_db, AntiReplay, Cipher,
};
use neqo_transport::{Output, RandomConnectionIdGenerator, Version};
use neqo_udp::RecvBuf;
use tokio::time::Sleep;

use crate::SharedArgs;
Expand Down Expand Up @@ -202,7 +203,7 @@ pub struct ServerRunner {
server: Box<dyn HttpServer>,
timeout: Option<Pin<Box<Sleep>>>,
sockets: Vec<(SocketAddr, crate::udp::Socket)>,
recv_buf: Vec<u8>,
recv_buf: RecvBuf,
}

impl ServerRunner {
Expand All @@ -217,7 +218,7 @@ impl ServerRunner {
server,
timeout: None,
sockets,
recv_buf: vec![0; neqo_udp::RECV_BUF_SIZE],
recv_buf: RecvBuf::new(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions neqo-bin/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::{io, net::SocketAddr};

use neqo_common::Datagram;
use neqo_udp::DatagramIter;
use neqo_udp::{DatagramIter, RecvBuf};

/// Ideally this would live in [`neqo-udp`]. [`neqo-udp`] is used in Firefox.
///
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Socket {
pub fn recv<'a>(
&self,
local_address: SocketAddr,
recv_buf: &'a mut [u8],
recv_buf: &'a mut RecvBuf,
) -> Result<Option<DatagramIter<'a>>, io::Error> {
self.inner
.try_io(tokio::io::Interest::READABLE, || {
Expand Down
3 changes: 3 additions & 0 deletions neqo-udp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ log = { workspace = true }
neqo-common = { path = "./../neqo-common" }
quinn-udp = { workspace = true }

[build-dependencies]
cfg_aliases = "0.2"

[package.metadata.cargo-machete]
ignored = ["log"]

Expand Down
16 changes: 16 additions & 0 deletions neqo-udp/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use cfg_aliases::cfg_aliases;

fn main() {
// Setup cfg aliases
cfg_aliases! {
// Platforms
apple: {
any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "visionos"
)
},
}
}
Loading

0 comments on commit 3c48567

Please sign in to comment.