Skip to content

Commit 277caad

Browse files
XAMPPRockyThomasdezeeuw
authored andcommitted
feat: Add UDP GRO option
1 parent 795e974 commit 277caad

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/sys/unix.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,36 @@ impl crate::Socket {
28122812
)
28132813
}
28142814
}
2815+
2816+
/// Get the value of the `UDP_GRO` option on this socket.
2817+
///
2818+
/// For more information about this option, see [`set_udp_gro`].
2819+
///
2820+
/// [`set_udp_gro`]: Socket::set_udp_gro
2821+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
2822+
#[cfg_attr(
2823+
docsrs,
2824+
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
2825+
)]
2826+
pub fn udp_gro(&self) -> io::Result<bool> {
2827+
unsafe {
2828+
getsockopt::<c_int>(self.as_raw(), libc::SOL_UDP, libc::UDP_GRO).map(|reuse| reuse != 0)
2829+
}
2830+
}
2831+
2832+
/// Set value for the `UDP_GRO` option on this socket.
2833+
///
2834+
/// This indicates that the kernel can combine multiple datagrams into a
2835+
/// single buffer, this needs to be used in combination with [`Self::recvmsg`]
2836+
/// to get the number of segments in the buffer from the [`MsgHdr`].
2837+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
2838+
#[cfg_attr(
2839+
docsrs,
2840+
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
2841+
)]
2842+
pub fn set_udp_gro(&self, reuse: bool) -> io::Result<()> {
2843+
unsafe { setsockopt(self.as_raw(), libc::SOL_UDP, libc::UDP_GRO, reuse as c_int) }
2844+
}
28152845
}
28162846

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

tests/socket.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,12 @@ test!(reuse_address, set_reuse_address(true));
13721372
))
13731373
))]
13741374
test!(reuse_port, set_reuse_port(true));
1375+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
1376+
#[cfg_attr(
1377+
docsrs,
1378+
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
1379+
)]
1380+
test!(udp_gro, set_udp_gro(true));
13751381
#[cfg(all(feature = "all", target_os = "freebsd"))]
13761382
test!(reuse_port_lb, set_reuse_port_lb(true));
13771383
#[cfg(all(

0 commit comments

Comments
 (0)