Skip to content

Commit a6299d4

Browse files
committed
feat: Add UDP GRO option
1 parent 3a93893 commit a6299d4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/sys/unix.rs

+30
Original file line numberDiff line numberDiff line change
@@ -3097,6 +3097,36 @@ impl crate::Socket {
30973097
)
30983098
}
30993099
}
3100+
3101+
/// Get the value of the `UDP_GRO` option on this socket.
3102+
///
3103+
/// For more information about this option, see [`set_udp_gro`].
3104+
///
3105+
/// [`set_udp_gro`]: Socket::set_udp_gro
3106+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
3107+
#[cfg_attr(
3108+
docsrs,
3109+
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
3110+
)]
3111+
pub fn udp_gro(&self) -> io::Result<bool> {
3112+
unsafe {
3113+
getsockopt::<c_int>(self.as_raw(), libc::SOL_UDP, libc::UDP_GRO).map(|reuse| reuse != 0)
3114+
}
3115+
}
3116+
3117+
/// Set value for the `UDP_GRO` option on this socket.
3118+
///
3119+
/// This indicates that the kernel can combine multiple datagrams into a
3120+
/// single buffer, this needs to be used in combination with [`Self::recvmsg`]
3121+
/// to get the number of segments in the buffer from the [`MsgHdr`].
3122+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
3123+
#[cfg_attr(
3124+
docsrs,
3125+
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
3126+
)]
3127+
pub fn set_udp_gro(&self, reuse: bool) -> io::Result<()> {
3128+
unsafe { setsockopt(self.as_raw(), libc::SOL_UDP, libc::UDP_GRO, reuse as c_int) }
3129+
}
31003130
}
31013131

31023132
/// See [`Socket::dccp_available_ccids`].

tests/socket.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,12 @@ test!(reuse_address, set_reuse_address(true));
13551355
not(any(windows, target_os = "solaris", target_os = "illumos"))
13561356
))]
13571357
test!(reuse_port, set_reuse_port(true));
1358+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
1359+
#[cfg_attr(
1360+
docsrs,
1361+
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
1362+
)]
1363+
test!(udp_gro, set_udp_gro(true));
13581364
#[cfg(all(feature = "all", target_os = "freebsd"))]
13591365
test!(reuse_port_lb, set_reuse_port_lb(true));
13601366
#[cfg(all(feature = "all", unix, not(target_os = "redox")))]

0 commit comments

Comments
 (0)