feat: implement kernel receive timestamps on Linux/Android#2634
Open
syszery wants to merge 1 commit into
Open
Conversation
8acc55f to
aae01e9
Compare
Collaborator
thomaseizinger
left a comment
There was a problem hiding this comment.
Thanks! Looks clean.
Two comments.
thomaseizinger
approved these changes
May 13, 2026
Author
|
Hi @thomaseizinger, thank you for the feedback and the improvements! I reviewed the changes, and I noticed that we now convert with However, to make the intent clearer and the code safer, I suggest to make the following change to decode directly into a #[cfg(any(target_os = "linux", target_os = "android"))]
(libc::SOL_SOCKET, libc::SCM_TIMESTAMPNS) => {
let ts = unsafe { cmsg::decode::<libc::timespec, libc::cmsghdr>(cmsg) };
// Handle potential negative values on 32-bit/64-bit systems
let secs = u64::try_from(ts.tv_sec).unwrap_or(0);
let nsecs = u32::try_from(ts.tv_nsec).unwrap_or(0);
self.timestamp = Some(core::time::Duration::new(secs, nsecs));
} |
djc
approved these changes
May 14, 2026
Member
djc
left a comment
There was a problem hiding this comment.
Looks okay to me modulo a few nits. Thanks!
e2e6dd0 to
75fde81
Compare
Author
|
I've addressed all the feedback and squashed the history.
|
thomaseizinger
approved these changes
May 14, 2026
Collaborator
thomaseizinger
left a comment
There was a problem hiding this comment.
One more nit, otherwise LGTM
Enable SO_TIMESTAMPNS on Linux and Android, parse SCM_TIMESTAMPNS ancillary messages, and expose timestamps via RecvMeta::timestamp.
75fde81 to
db6b218
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2574.
Add Linux/Android support for kernel receive timestamps via
SO_TIMESTAMPNS.SO_TIMESTAMPNSon socket setupSCM_TIMESTAMPNSancillary messagesRecvMeta::timestamp(Option<u64>, nanoseconds since Unix epoch)CMSG_LENfrom 88 to 96 bytes on Linux/AndroidTested on Linux x86_64. All tests pass locally.