Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(s2n-quic-platform): make GSO/GRO configuration more ergonomic #2091

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions quic/s2n-quic-platform/src/io/tokio/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ impl Builder {
Ok(self)
}

/// Configures Generic Segmentation Offload (GSO)
///
/// By default, GSO will be used unless the platform does not support it or an attempt to use
/// GSO fails. If it is known that GSO is not available, set this option to explicitly disable it.
pub fn with_gso(self, enabled: bool) -> io::Result<Self> {
if enabled {
Ok(self)
} else {
self.with_gso_disabled()
}
}

/// Disables Generic Receive Offload (GRO)
///
/// By default, GRO will be used unless the platform does not support it. If it is known that
Expand All @@ -131,6 +143,18 @@ impl Builder {
Ok(self)
}

/// Configures Generic Receive Offload (GRO)
///
/// By default, GRO will be used unless the platform does not support it. If it is known that
/// GRO is not available, set this option to explicitly disable it.
pub fn with_gro(self, enabled: bool) -> io::Result<Self> {
if enabled {
Ok(self)
} else {
self.with_gro_disabled()
}
}

/// Enables the port reuse (SO_REUSEPORT) socket option
pub fn with_reuse_port(mut self) -> io::Result<Self> {
if !cfg!(unix) {
Expand Down
14 changes: 4 additions & 10 deletions quic/s2n-quic-qns/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ impl Server {
pub fn build(&self) -> Result<impl io::Provider> {
let mut io_builder = io::Default::builder()
.with_receive_address((self.ip, self.port).into())?
.with_max_mtu(self.max_mtu)?;

if self.disable_gso {
io_builder = io_builder.with_gso_disabled()?;
}
.with_max_mtu(self.max_mtu)?
.with_gso(!self.disable_gso)?;

if let Some(size) = self.queue_send_buffer_size {
io_builder = io_builder.with_internal_send_buffer_size(size)?;
Expand Down Expand Up @@ -102,11 +99,8 @@ impl Client {
pub fn build(&self) -> Result<impl io::Provider> {
let mut io_builder = io::Default::builder()
.with_receive_address((self.local_ip, 0u16).into())?
.with_max_mtu(self.max_mtu)?;

if self.disable_gso {
io_builder = io_builder.with_gso_disabled()?;
}
.with_max_mtu(self.max_mtu)?
.with_gso(!self.disable_gso)?;

if let Some(size) = self.queue_send_buffer_size {
io_builder = io_builder.with_internal_send_buffer_size(size)?;
Expand Down
Loading