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

Add MSG_CONFIRM and MSG_DONTROUTE to RecvFlags #499

Merged
merged 1 commit into from
Mar 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,37 @@ impl RecvFlags {
pub const fn is_out_of_band(self) -> bool {
self.0 & libc::MSG_OOB != 0
}

/// Check if the confirm flag is set.
///
/// This is used by SocketCAN to indicate a frame was sent via the
/// socket it is received on. This flag can be interpreted as a
/// 'transmission confirmation'.
///
/// On Unix this corresponds to the `MSG_CONFIRM` flag.
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
)]
pub const fn is_confirm(self) -> bool {
self.0 & libc::MSG_CONFIRM != 0
}

/// Check if the don't route flag is set.
///
/// This is used by SocketCAN to indicate a frame was created
/// on the local host.
///
/// On Unix this corresponds to the `MSG_DONTROUTE` flag.
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
)]
pub const fn is_dontroute(self) -> bool {
self.0 & libc::MSG_DONTROUTE != 0
}
}

#[cfg(not(target_os = "redox"))]
Expand All @@ -584,6 +615,10 @@ impl std::fmt::Debug for RecvFlags {
s.field("is_out_of_band", &self.is_out_of_band());
#[cfg(not(target_os = "espidf"))]
s.field("is_truncated", &self.is_truncated());
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
s.field("is_confirm", &self.is_confirm());
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
s.field("is_dontroute", &self.is_dontroute());
s.finish()
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@ fn send_from_recv_to_vectored() {
#[cfg(all(unix, not(target_os = "redox")))]
assert_eq!(flags.is_out_of_band(), false);
assert_eq!(flags.is_truncated(), false);
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
assert_eq!(flags.is_confirm(), false);
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
assert_eq!(flags.is_dontroute(), false);
assert_eq!(
addr.as_socket_ipv6().unwrap(),
addr_a.as_socket_ipv6().unwrap()
Expand Down