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

Added FreeBSD's SCM_REALTIME and SCM_MONOTONIC into sys::socket::ControlMessageOwned #2187

Merged
merged 15 commits into from Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
43 changes: 42 additions & 1 deletion src/sys/socket/mod.rs
@@ -1,7 +1,7 @@
//! Socket interface functions
//!
//! [Further reading](https://man7.org/linux/man-pages/man7/socket.7.html)
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
#[cfg(feature = "uio")]
use crate::sys::time::TimeSpec;
#[cfg(not(target_os = "redox"))]
Expand Down Expand Up @@ -410,6 +410,25 @@ libc_bitflags! {
}
}

#[cfg(target_os = "freebsd")]
libc_enum! {
/// A selector for which clock to use when generating packet timestamps.
/// Used when setting [`TsClock`](crate::sys::socket::sockopt::TsClock) on a socket.
/// (For more details, see [setsockopt(2)](https://man.freebsd.org/cgi/man.cgi?setsockopt)).
#[repr(i32)]
#[non_exhaustive]
pub enum SocketTimestamp {
/// Microsecond resolution, realtime. This is the default.
SO_TS_REALTIME_MICRO,
/// Sub-nanosecond resolution, realtime.
SO_TS_BINTIME,
/// Nanosecond resolution, realtime.
SO_TS_REALTIME,
/// Nanosecond resolution, monotonic.
SO_TS_MONOTONIC,
}
}

cfg_if! {
if #[cfg(any(target_os = "android", target_os = "linux"))] {
/// Unix credentials of the sending process.
Expand Down Expand Up @@ -779,6 +798,18 @@ pub enum ControlMessageOwned {
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
ScmTimestampns(TimeSpec),
/// Realtime clock timestamp
///
/// [Further reading](https://man.freebsd.org/cgi/man.cgi?setsockopt)
#[cfg(target_os = "freebsd")]
#[cfg_attr(docsrs, doc(cfg(all())))]
recatek marked this conversation as resolved.
Show resolved Hide resolved
ScmRealtime(TimeSpec),
/// Monotonic clock timestamp
///
/// [Further reading](https://man.freebsd.org/cgi/man.cgi?setsockopt)
#[cfg(target_os = "freebsd")]
#[cfg_attr(docsrs, doc(cfg(all())))]
ScmMonotonic(TimeSpec),
#[cfg(any(
target_os = "android",
apple_targets,
Expand Down Expand Up @@ -958,6 +989,16 @@ impl ControlMessageOwned {
let ts: libc::timespec = ptr::read_unaligned(p as *const _);
ControlMessageOwned::ScmTimestampns(TimeSpec::from(ts))
}
#[cfg(target_os = "freebsd")]
(libc::SOL_SOCKET, libc::SCM_REALTIME) => {
let ts: libc::timespec = ptr::read_unaligned(p as *const _);
ControlMessageOwned::ScmRealtime(TimeSpec::from(ts))
}
#[cfg(target_os = "freebsd")]
(libc::SOL_SOCKET, libc::SCM_MONOTONIC) => {
let ts: libc::timespec = ptr::read_unaligned(p as *const _);
ControlMessageOwned::ScmMonotonic(TimeSpec::from(ts))
}
#[cfg(any(target_os = "android", target_os = "linux"))]
(libc::SOL_SOCKET, libc::SCM_TIMESTAMPING) => {
let tp = p as *const libc::timespec;
Expand Down
2 changes: 1 addition & 1 deletion src/sys/socket/sockopt.rs
Expand Up @@ -721,7 +721,7 @@ sockopt_impl!(
Both,
libc::SOL_SOCKET,
libc::SO_TS_CLOCK,
i32
super::SocketTimestamp
);
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg(feature = "net")]
Expand Down