Skip to content

Commit ab4575b

Browse files
author
Scott Hutton
committed
Make enabling GRO optional
1 parent 14e36a3 commit ab4575b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/unix.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ impl UdpSocket {
116116
self.io.set_broadcast(broadcast)
117117
}
118118

119+
/// Opportunistically try to enable GRO support for this socket. This is
120+
/// only supported on Linux platforms.
121+
#[cfg(target_os = "linux")]
122+
pub fn set_gro(&self, enable: bool) -> io::Result<()> {
123+
// See gro::gro_segments().
124+
const OPTION_OFF: libc::c_int = 0;
125+
126+
let value = if enable { OPTION_ON } else { OPTION_OFF };
127+
set_socket_option(&self.io, libc::SOL_UDP, libc::UDP_GRO, value)
128+
}
129+
119130
pub async fn connect<A: ToSocketAddrs>(&self, addrs: A) -> io::Result<()> {
120131
self.io.connect(addrs).await
121132
}
@@ -609,9 +620,6 @@ fn init(io: SockRef<'_>) -> io::Result<()> {
609620
}
610621
#[cfg(target_os = "linux")]
611622
{
612-
// opportunistically try to enable GRO. See gro::gro_segments().
613-
let _ = set_socket_option(&*io, libc::SOL_UDP, libc::UDP_GRO, OPTION_ON);
614-
615623
// Forbid IPv4 fragmentation. Set even for IPv6 to account for IPv6 mapped IPv4 addresses.
616624
set_socket_option(
617625
&*io,

0 commit comments

Comments
 (0)