Skip to content

Commit

Permalink
feat: Add UDP GRO option
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Oct 21, 2024
1 parent 3a93893 commit 7db2688
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,36 @@ impl Socket {
}
}

/// Get the value of the `UDP_GRO` option on this socket.
///
/// For more information about this option, see [`set_udp_gro`].
///
/// [`set_udp_gro`]: Socket::set_udp_gro
#[cfg(all(feature = "all", target_os = "linux"))]
pub fn udp_gro(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::SOL_UDP, sys::UDP_GRO)
.map(|reuse| reuse != 0)
}
}

/// Set value for the `UDP_GRO` option on this socket.
///
/// This indicates that the kernel can combine multiple datagrams into a
/// single buffer, this needs to be used in combination with [`Self::recvmsg`]
/// to get the number of segments in the buffer from the [`MsgHdr`].
#[cfg(all(feature = "all", target_os = "linux"))]
pub fn set_udp_gro(&self, reuse: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
sys::SOL_UDP,
sys::UDP_GRO,
reuse as c_int,
)
}
}

/// Get the value of the `SO_SNDBUF` option on this socket.
///
/// For more information about this option, see [`set_send_buffer_size`].
Expand Down
2 changes: 1 addition & 1 deletion src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub(crate) use libc::SO_LINGER;
))]
pub(crate) use libc::SO_LINGER_SEC as SO_LINGER;
#[cfg(target_os = "linux")]
pub(crate) use libc::SO_PASSCRED;
pub(crate) use libc::{SO_PASSCRED, SOL_UDP, UDP_GRO};
pub(crate) use libc::{
ip_mreq as IpMreq, linger, IPPROTO_IP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF,
IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,
Expand Down

0 comments on commit 7db2688

Please sign in to comment.